Skip to content

Instantly share code, notes, and snippets.

@michaelotto
Last active January 8, 2020 10:48
Show Gist options
  • Save michaelotto/e96025bcd0ad46ae5bd8d88e42a48eb4 to your computer and use it in GitHub Desktop.
Save michaelotto/e96025bcd0ad46ae5bd8d88e42a48eb4 to your computer and use it in GitHub Desktop.
// ==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