Skip to content

Instantly share code, notes, and snippets.

@uu59
Created March 16, 2011 02:51
Show Gist options
  • Save uu59/871922 to your computer and use it in GitHub Desktop.
Save uu59/871922 to your computer and use it in GitHub Desktop.
inject rel="noreferer" to all <a> (include dynamically generated)
// ==UserScript==
// @name Always noreferrer links
// @namespace http://twitter.com/uu59
// @include *
// ==/UserScript==
(function(){
var process = function(docroot){
Array.prototype.forEach.call(
docroot.querySelectorAll('a'),
function(a){
var attr = a.getAttribute('rel') || '';
if(attr.indexOf('noreferrer') == -1) {
a.setAttribute('rel', 'noreferrer ' + attr);
}
}
)
}
process(document);
window.addEventListener('DOMNodeInserted', function(e){
process(e.target.ownerDocument);
},false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment