Skip to content

Instantly share code, notes, and snippets.

@Infocatcher
Last active December 16, 2015 05:09
Show Gist options
  • Save Infocatcher/5382604 to your computer and use it in GitHub Desktop.
Save Infocatcher/5382604 to your computer and use it in GitHub Desktop.
Right-click on New Tab button to open URI from clipboard in new tab. You can use Custom Buttons extension (paste code into "initialization" section) or something like http://userchromejs.mozdev.org/ or https://addons.mozilla.org/addon/uc/ to run this code
addEventListener("contextmenu", handleClick, true);
addEventListener("click", handleClick, true);
addEventListener("unload", function destroy(e) {
removeEventListener(e.type, destroy, false);
removeEventListener("contextmenu", handleClick, true);
removeEventListener("click", handleClick, true);
}, false);
function isNewTabButton(e) {
var trg = e.originalTarget || e.target;
var cl = trg.classList;
if(!cl)
return false;
return cl.contains("tabs-newtab-button")
|| cl.contains("tabs-newbutton") // SeaMonkey
|| trg.id == "new-tab-button";
}
function handleClick(e) {
if(!isNewTabButton(e) || e.ctrlKey || e.shiftKey || e.altKey || e.metaKey)
return;
if(e.type == "click" && e.button != 2)
return;
e.preventDefault();
e.stopPropagation();
if(e.type == "contextmenu")
return;
var clipURI = readFromClipboard() || "";
if(!/^\w+:\S+$/.test(clipURI))
return;
gBrowser.selectedTab = gBrowser.addTab(clipURI);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment