Created
September 6, 2015 01:00
-
-
Save hateradio/43f710f288a2106cef03 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 I'm An Idiot: The Anti-LOL Script | |
// @namespace hateradio))) | |
// @description Remove those senseless letters from your view. | |
// @include http://*neogaf.*/forum/* | |
// @grant All | |
// @priority 100000 | |
// ==/UserScript== | |
/*jslint indent: 4, maxerr: 50, browser: true */ | |
// //*[text()[contains(.,'ABC')]] | |
(function () { | |
'use strict'; | |
var anti = { | |
// searches: [ | |
// "//div[contains(@class, 'post')]//text()[contains(translate(., 'LOL', 'lol'), 'lol')]", | |
// "//div[contains(@class, 'post')]//text()[contains(translate(., 'Having said that', 'having said that'), 'having said that')]", | |
// "//div[contains(@class, 'post')]//text()[contains(translate(., 'That said', 'that said'), 'that said')]", | |
// "//div[contains(@class, 'post')]//text()[contains(translate(., 'That being said', 'that being said'), 'that being said')]" | |
// ], //div[contains(@class, "post")]//text()[contains(translate(., Having said that, having said that), having said that)] | |
replaceText: [ | |
'LOL', | |
'Having said that', | |
'That said', | |
'That being said' | |
], | |
replacementsCustom: { | |
'LOL': function (data) { | |
data = data.replace(/(lol)\b/ig, '[I\'m an idiot.]').replace(/((lo)\1{1,}lo?[sz]?)\b/ig, '[I\'m an idiot.]'); | |
data = data.replace(/(lol[sz]?)\b/ig, '[I\'m an idiot.]'); | |
return data; | |
} | |
}, | |
replaceSearch: function (text) { | |
var lower = text.toLowerCase(); | |
return '//div[contains(@class, "post")]//text()[contains(translate(., "' + text + '", "' + lower + '"), "' + lower + '")]'; | |
}, | |
replaceFn: function (text) { | |
return anti.replacementsCustom[text] || function (data) { | |
data = data.replace(new RegExp('(?:' + text + '),?', 'ig'), ''); | |
return data; | |
}; | |
}, | |
// replacements: [ | |
// function (data) { | |
// data = data.replace(/(lol)\b/ig, '[I\'m an idiot.]').replace(/((lo)\1{1,}lo?[sz]?)\b/ig, '[I\'m an idiot.]'); | |
// data = data.replace(/(lol[sz]?)\b/ig, '[I\'m an idiot.]'); | |
// return data; | |
// }, | |
// function (data) { | |
// data = data.replace(/(?:Having said that),?\s+?/ig, ''); | |
// return data; | |
// }, | |
// function (data) { | |
// data = data.replace(/(?:that said),?\s+?/ig, ''); | |
// return data; | |
// }, | |
// function (data) { | |
// data = data.replace(/(?:that being said),?\s+?/ig, ''); | |
// return data; | |
// } | |
// ], | |
replacer: function (nodes, replace) { // replace: String => String | |
var i = nodes.snapshotLength, n; | |
while (i--) { | |
n = nodes.snapshotItem(i); | |
n.data = replace(n.data); | |
} | |
}, | |
main: function () { | |
anti.searches = anti.replaceText.map(anti.replaceSearch); | |
anti.replacements = anti.replaceText.map(anti.replaceFn); | |
// console.log(anti); | |
anti.searches.forEach(function (text, idx) { | |
var nodes = document.evaluate(text, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |
anti.replacer(nodes, anti.replacements[idx]); | |
}); | |
} | |
}; | |
window.setTimeout(anti.main, 400); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment