Last active
January 8, 2020 10:48
-
-
Save michaelotto/e96025bcd0ad46ae5bd8d88e42a48eb4 to your computer and use it in GitHub Desktop.
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 Remove bento.de stories from spiegel.de | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Remove bento.de stories from spiegel.de | |
// @author Michael Otto | |
// @match https://www.spiegel.de/* | |
// @match http://www.spiegel.de/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var search_string = [ | |
"//section[@data-area='block>Bento-Box']", // potential elements with articles | |
"//article" | |
]; | |
function parse_and_remove(xpath) { | |
for (var i = 0; i < xpath.snapshotLength; i++) { | |
var el = xpath.snapshotItem(i); | |
var links = el.getElementsByTagName('a'); // if element contains a link to bento, remove it altogether | |
for (var j=0; j < links.length; j++) { | |
if (links[j].href.match(/^https?:\/\/(\w+\.)?bento\.de\//i)) { | |
console.log("Removing element with link to "+links[j].href); | |
el.parentNode.removeChild(el); | |
break; | |
} | |
} | |
} | |
} | |
for (var j = 0; j < search_string.length; j++) { | |
parse_and_remove(document.evaluate(search_string[j], document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null)); | |
} | |
;})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment