Skip to content

Instantly share code, notes, and snippets.

@vyznev
Last active August 26, 2021 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vyznev/29e814707baf8e1fa6e6 to your computer and use it in GitHub Desktop.
Save vyznev/29e814707baf8e1fa6e6 to your computer and use it in GitHub Desktop.
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