Skip to content

Instantly share code, notes, and snippets.

@arirahikkala
Created May 11, 2013 11:09
Show Gist options
  • Save arirahikkala/5559664 to your computer and use it in GitHub Desktop.
Save arirahikkala/5559664 to your computer and use it in GitHub Desktop.
Navigate on paste as is usual on Unix browsers, and that works on current Chrome versions (unlike the extension on the Chrome Web Store).
// ==UserScript==
// @name Navigate on Paste
// @namespace http://github.com/arirahikkala
// @version 0.1
// @description Navigate on paste as is usual on Unix browsers, and that works on current Chrome versions (unlike the extension on the Chrome Web Store).
// @match http://*/*
// @copyright 2013, Ari Rahikkala
// ==/UserScript==
document.body.onpaste=function(e){
var el = e.target;
if (el.tagName == "INPUT" || el.tagName == "TEXTFIELD")
return true;
var isLink = false;
var els = document.querySelectorAll(":hover");
for (var i = 0; i < els.length; i++) {
if (els[i].tagName == "A") {
isLink = true;
break;
}
}
if (!isLink) {
window.location.href = e.clipboardData.getData("text");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment