Skip to content

Instantly share code, notes, and snippets.

@yattom
Last active December 24, 2015 08:59
Show Gist options
  • Save yattom/6774549 to your computer and use it in GitHub Desktop.
Save yattom/6774549 to your computer and use it in GitHub Desktop.
Grease Monkey script to remove (=make less visible) texts which contains unwanted keywords. This specific version removes Olympic related words on nikkei.com.
// ==UserScript==
// @name OlympicRemover
// @namespace http://yattom.jp/experimental
// @include http://www.nikkei.com/
// @version 1
// ==/UserScript==
var org_func = window.onload();
window.onload = function() {
var remove = function() {
var keywords = [
'五輪',
'オリンピック',
];
var handle = function(tag) {
for(var i in tag.childNodes) {
var e = tag.childNodes[i];
if(e.nodeType == document.TEXT_NODE) {
found = false;
for(j in keywords) {
if(e.textContent.indexOf(keywords[j]) != -1) {
found = true;
break;
}
}
if(!found) {
return false;
}
tag.style['opacity'] = 0.1;
//tag.style['background'] = 'red';
return true;
}
}
return false;
};
var traverse = function(element, fn) {
var skipChildren = fn(element);
if(skipChildren) { return; }
for(var i in element.children) {
traverse(element.children[i], fn);
}
};
traverse(document.body, handle);
};
window.setTimeout(remove, 3 * 1000);
window.setInterval(remove, 3 * 60 * 1000);
org_func();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment