Skip to content

Instantly share code, notes, and snippets.

@vyznev
Last active Aug 26, 2021
Embed
What would you like to do?
Reveal nofollow links on Stack Exchange
// ==UserScript==
// @name Reveal nofollow links on Stack Exchange
// @version 1.3
// @namespace http://vyznev.net/
// @description Colors all links with rel=nofollow red on the Stack Exchange network. (Works on other sites too, if you edit the includes.)
// @author Ilmari Karonen
// @license ISC (http://opensource.org/licenses/ISC)
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// @match *://*.serverfault.com/*
// @match *://*.stackapps.com/*
// @match *://*.mathoverflow.net/*
// @match *://*.askubuntu.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
// Yes, that's all there really is to it:
var css = 'a[rel*=nofollow] { color: red !important; }';
// Inject style into page:
var style = document.createElement('style');
style.textContent = css;
var parent = (document.head || document.documentElement);
if (parent) parent.appendChild(style);
else {
// work-around for https://github.com/greasemonkey/greasemonkey/issues/2996
var obs = new MutationObserver(function () {
var parent = (document.head || document.documentElement);
if (parent) { obs.disconnect(); parent.appendChild(style); }
});
obs.observe(document, {childList: true});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment