Last active
July 31, 2020 05:28
-
-
Save 5j9/43b53c1ee0f50c9039f00d1030d733d9 to your computer and use it in GitHub Desktop.
detecting 3rr on wikipedia using the selected revisions
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
var checked_revs = document.querySelectorAll('#pagehistory input[type=checkbox]:checked'); | |
var user_revs = {}; | |
var user, parent, date, revs; | |
checked_revs.forEach(function(check){ | |
parent = check.parentNode; | |
user = parent.querySelector('.mw-userlink').innerText; | |
date = new Date(parent.querySelector('.mw-changeslist-date').innerText); | |
rev = {"date": date, "parent": parent}; | |
revs = user_revs[user]; | |
if (!revs) { | |
user_revs[user] = [rev]; | |
} else if (revs.length < 4) { | |
revs = user_revs[user] = revs.filter(r => (r.date - date) < 24*3600*1000); | |
revs.push(rev); | |
} | |
}); | |
var colors = ["DodgerBlue", "OrangeRed", "Crimson", "DarkGoldenRod", "HotPink", "Yellow", "Red"]; | |
for ([user, revs] of Object.entries(user_revs)) { | |
if (revs.length == 4) { | |
var color = colors.pop(); | |
var msg = `[[user:${user}|${user}]] has violated 3RR in: \n`; | |
revs.forEach(function(rev){ | |
rev.parent.style.background = color; | |
href = rev.parent.querySelector('.mw-history-histlinks span:nth-last-child(1) a').href; | |
msg += `[${href}]`; | |
}); | |
console.log(msg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment