Skip to content

Instantly share code, notes, and snippets.

@zuzu
Forked from awef/noref.user.js
Created April 19, 2011 13:58
Show Gist options
  • Save zuzu/927904 to your computer and use it in GitHub Desktop.
Save zuzu/927904 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name noref
// @description Aタグにrel="noreferrer"を付ける
// @match http://*/*
// @match https://*/*
// ==/UserScript==
var fn = function(node) {
if (node.nodeName === 'A') {
if (!/(?:^|\s)noreferrer(?:$|\s)/.test(node.rel)) {
node.rel = (node.rel + ' noreferrer').trim();
}
}
else if (node.parentNode) {
fn(node.parentNode);
}
};
document.documentElement.addEventListener('click', function(e) {
fn(e.target);
}, false);
document.documentElement.addEventListener('mouseup', function(e) {
fn(e.target);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment