Created
April 6, 2009 12:50
-
-
Save cherenkov/90746 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 middleMousePaste | |
| // @namespace http://d.hatena.ne.jp/Cherenkov/ | |
| // @description enable overwrite. | |
| // @include chrome://browser/content/browser.xul | |
| // ==/UserScript== | |
| (function(){ | |
| if (gPrefService.getBoolPref("middlemouse.paste")) return alert("Please set a value.\nabout:config -> middlemouse.paste -> false"); | |
| window.addEventListener("click", function(event) { | |
| if (event.button == 1) { | |
| var target = event.target; | |
| var tagName = target.tagName; | |
| if (tagName) tagName = tagName.toLowerCase(); | |
| var type = target.type; | |
| if (type) type = type.toLowerCase(); | |
| if ((tagName == "input" && (type == "" || type == "text" || type == "password")) || tagName == "textarea" || tagName == "textbox" || tagName == "searchbar") { | |
| var front = target.value.substr(0,target.selectionStart); | |
| var back = target.value.substr(target.selectionEnd); | |
| var select = target.value.substring(target.selectionStart, target.selectionEnd); | |
| var clipbrd = readFromClipboard(); | |
| if(!clipbrd) clipbrd = ""; | |
| target.value = front + clipbrd + back; | |
| //modify caret position. | |
| target.selectionStart = target.selectionEnd = (front.length + clipbrd.length); | |
| } | |
| } | |
| }, true); | |
| //stop a scroll event. | |
| window.addEventListener("mousedown", function(event) { | |
| if (event.button == 1) { | |
| var target = event.target; | |
| var tagName = target.tagName; | |
| if (tagName) tagName = tagName.toLowerCase(); | |
| var type = target.type; | |
| if (type) type = type.toLowerCase(); | |
| if ((tagName == "input" && (type == "" || type == "text" || type == "password")) || tagName == "textarea" || tagName == "textbox") { | |
| event.stopPropagation(); | |
| } | |
| } | |
| }, true); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment