Created
December 30, 2009 22:45
-
-
Save os0x/266475 to your computer and use it in GitHub Desktop.
ドメインの異なるリンクにnoreferrerをセット via awef
This file contains 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 noreferrer | |
// @namespace http://ss-o.net/ | |
// @include http://* | |
// ==/UserScript== | |
document.body.addEventListener('DOMNodeInserted',noref,false); | |
noref({target:document.body}); | |
function noref(e){ | |
if (e.target.getElementsByTagName) { | |
var as = document.evaluate('descendant-or-self::a', e.target, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
for (var i = 0, l = as.snapshotLength;i < l;++i){ | |
var a = as.snapshotItem(i); | |
if ( | |
a.href.indexOf('http') === 0 && | |
a.host !== location.host && | |
!/noreferrer/i.test(a.rel) | |
) { | |
a.rel = (a.rel ? a.rel + ' ' : '') + 'noreferrer'; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment