Skip to content

Instantly share code, notes, and snippets.

@nschubach
Last active April 2, 2016 00:10
Show Gist options
  • Save nschubach/27fcf78f1ecbf914310450a98937ba02 to your computer and use it in GitHub Desktop.
Save nschubach/27fcf78f1ecbf914310450a98937ba02 to your computer and use it in GitHub Desktop.
spam remover reddit april fools
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();
}
}
});
}
});
@travelton
Copy link

Or just remove them completely.

$(document).on('DOMNodeInserted', function(e) {
    $('.robin-message--message', e.currentTarget).each(function() {
        if (/[\u0080-\uFFFF]/.test($(this).text())) {
            $(this).parent().remove();
        }
    });
});

@nschubach
Copy link
Author

yeah, I was testing and had the color in there... it auto removes now along with the [Robin Autovoter posts

@NorbiPeti
Copy link

See my fork. :P Changed a bunch of things there.

@nschubach
Copy link
Author

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

@vishnumad
Copy link

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

@nschubach
Copy link
Author

It's removing any unicode (special characters) that people like to post (swastikas, hearts, triangles, faces ...)

@vishnumad
Copy link

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())) {...} ?

@nschubach
Copy link
Author

yes... but the current version of the script will remove the redundant "voted for" posts as well.

@strigona-worksight
Copy link

You should hash the string instead of using it as the key.

@nschubach
Copy link
Author

Done!

@nschubach
Copy link
Author

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