Created
July 27, 2009 07:40
-
-
Save cherenkov/156094 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name hatena form support | |
| // @namespace http://d.hatena.ne.jp/Cherenkov/ | |
| // @include chrome://browser/content/browser.xul | |
| // ==/UserScript== | |
| //thanks alice0775 | |
| //http://space.geocities.yahoo.co.jp/gl/alice0775/view/20070820/1187614472 | |
| //http://space.geocities.jp/alice0775/STORE/popupTranslate.uc.xul.txt | |
| (function(){ | |
| //選択文字列を得る | |
| function getSelection() { | |
| var targetWindow = getFocusedWindow(); | |
| var sel = targetWindow.getSelection(); | |
| if (sel && !sel.toString()) { | |
| var node = document.commandDispatcher.focusedElement; | |
| if (node && | |
| node.ownerDocument.defaultView == targetWindow && | |
| (node.type == "text" || node.type == "textarea") && | |
| 'selectionStart' in node && | |
| node.selectionStart != node.selectionEnd) { | |
| var offsetStart = Math.min(node.selectionStart, node.selectionEnd); | |
| var offsetEnd = Math.max(node.selectionStart, node.selectionEnd); | |
| return node.value.substr(offsetStart, offsetEnd-offsetStart); | |
| } | |
| } | |
| return sel ? | |
| sel.toString() : ""; | |
| } | |
| //現在のウインドウを得る | |
| function getFocusedWindow(){ | |
| var focusedWindow = document.commandDispatcher.focusedWindow; | |
| if (!focusedWindow || focusedWindow == window) | |
| return window.content; | |
| else | |
| return focusedWindow; | |
| } | |
| function run() { | |
| var selectText = getSelection(); | |
| if(selectText) { | |
| //var link = "<a href='" + content.document.location.href + "'>" + content.document.title + "</a>"; | |
| var link = "[" + content.document.location.href + ":title=" + content.document.title + "]"; | |
| selectText = ">>\n" + selectText + "\n" + link + "\n<<"; | |
| putClipboard(selectText); | |
| } | |
| function putClipboard(string){ | |
| Cc["@mozilla.org/widget/clipboardhelper;1"] | |
| .getService(Ci.nsIClipboardHelper) | |
| .copyString(string); | |
| } | |
| } | |
| var btn = document.createElement("toolbarbutton"); | |
| btn.setAttribute("class", "bookmark-item"); | |
| btn.setAttribute("image", "moz-anno:favicon:http://d.hatena.ne.jp/favicon.ico"); | |
| btn.addEventListener("command", run, false); | |
| var toolbar = document.getElementById("PersonalToolbar"); | |
| toolbar.appendChild(btn); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment