Skip to content

Instantly share code, notes, and snippets.

@cherenkov
Created April 6, 2009 12:50
Show Gist options
  • Select an option

  • Save cherenkov/90746 to your computer and use it in GitHub Desktop.

Select an option

Save cherenkov/90746 to your computer and use it in GitHub Desktop.
// ==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