Last active
June 17, 2018 02:41
-
-
Save luther9/4f3e7b127628d7039bf7c2017bd1b470 to your computer and use it in GitHub Desktop.
A Greasemonkey script to block certain links on all websites
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
'use strict' | |
const blacklist = [ | |
'codegolf.stackexchange.com', | |
'puzzling.stackexchange.com', | |
] | |
/* | |
Move all children of node to right before node. | |
*/ | |
function unpackTag(parent, node) { | |
while (node.hasChildNodes()) { | |
parent.insertBefore(node.firstChild, node) | |
} | |
} | |
{ | |
const links = document.body.getElementsByTagName('a') | |
let i = 0 | |
while (i < links.length) { | |
const link = links[i] | |
const href = link.getAttribute('href') | |
if (href && blacklist.some(url => href.includes(url))) { | |
const parent = link.parentNode | |
unpackTag(parent, link) | |
parent.removeChild(link) | |
} else { | |
++i | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment