-
-
Save nschubach/27fcf78f1ecbf914310450a98937ba02 to your computer and use it in GitHub Desktop.
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(); | |
} | |
} | |
}); | |
} | |
}); |
See my fork. :P Changed a bunch of things there.
I'm not seeing any difference. But I did change it to use e.target
instead of e.currentTarget
because long running chat will get laggy
Can you explain what the code inside the if statement is doing? I understand that it's searching for text with "[Robin Autovoter", but what exactly is /[\u0080-\uFFFF]|(?:\
doing
It's removing any unicode (special characters) that people like to post (swastikas, hearts, triangles, faces ...)
Ah I see. So let's say I wanted it to remove everything listed in addition to the phrase "voted for GROW", I'd change the if statement to if (/[\u0080-\uFFFF]|(?:\[Robin Autovoter)|(?:\voted for GROW)/.test($(this).text())) {...}
?
yes... but the current version of the script will remove the redundant "voted for" posts as well.
You should hash the string instead of using it as the key.
Done!
It's getting way too complex for a simple one day script ... but it tracks spamminess of each user now.
yeah, I was testing and had the color in there... it auto removes now along with the
[Robin Autovoter
posts