Last active
April 2, 2016 00:10
-
-
Save nschubach/27fcf78f1ecbf914310450a98937ba02 to your computer and use it in GitHub Desktop.
spam remover reddit april fools
This file contains hidden or 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
function hash(str) { | |
var hash = 0, i, chr, len; | |
if (str.length === 0) return hash; | |
for (i = 0, len = str.length; i < len; i++) { | |
chr = str.charCodeAt(i); | |
hash = ((hash << 5) - hash) + chr; | |
hash |= 0; | |
} | |
return hash; | |
}; | |
var spamObject = {}; | |
var spamByUser = {}; | |
$(document).on('DOMNodeInserted', function(e) { | |
if (e.target.id != 'robinChatMessageList') { | |
$('.robin-message--message', e.target).each(function() { | |
var user = $(this).parent().find('.robin-message--from').text(); | |
var time = new Date().valueOf(); | |
if (!spamByUser[user]) { | |
spamByUser[user] = { count: 0, time: time }; | |
} | |
if (time - spamByUser[user].time > 10000) { | |
spamByUser[user].count /= 1.25; | |
} | |
if (spamByUser[user].count > 5 && time - spamByUser[user].time < 10000) { | |
spamByUser[user].time = time; | |
spamByUser[user].count += 1; | |
$(this).parent().remove(); | |
} else if (/[\u0080-\uFFFF]|(?:\[Robin Autovoter)/.test($(this).text())) { | |
spamByUser[user].count += 1; | |
$(this).parent().remove(); | |
} else { | |
var textHash = hash($(this).text()); | |
if (!spamObject[textHash]) { | |
spamObject[textHash] = 0; | |
} | |
var count = spamObject[textHash] += 1; | |
if (count > 3) { | |
spamByUser[user].count += 1;; | |
$(this).parent().remove(); | |
} | |
} | |
}); | |
} | |
}); |
It's getting way too complex for a simple one day script ... but it tracks spamminess of each user now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Done!