User:SD0001/hide-reverted-edits.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:SD0001/hide-reverted-edits. |
// TODO: handle reverts of reverts
$.when(mw.loader.using('mediawiki.util'), $.ready).then(function() {
if (mw.config.get('wgAction') !== 'history') return;
$('#pagehistory li.mw-tag-mw-undo').each(function() {
var editcomment = $(this).find('.comment').text();
// Plain mediawiki undo with untampered edit summary
if (editcomment.startsWith('Undid revision ')) {
var reverted_rev = parseInt(editcomment.slice('Undid revision '.length));
if (isNaN(reverted_rev)) return true;
$(this).hide();
$('[data-mw-revid=' + reverted_rev +']').hide();
// Twinkle reverts
} else if (editcomment.startsWith('Reverted ')) {
// rollback
if (/^Reverted (?:good faith|\d+) edits? by/.test(editcomment)) {
var reverted_user = /^Reverted (?:good faith|\d+) edits? by (.*?) \(talk\)/.exec(editcomment)[1];
// IPv6 addresses are in lowercase in history page, but in uppercase in rollback edit summary
if (mw.util.isIPv6Address(reverted_user)) {
reverted_user = reverted_user.toLowerCase();
}
$(this).hide();
var rev = $(this).next();
while ( rev.find('.mw-userlink bdi').text() === reverted_user ) {
rev.hide();
rev = rev.next();
if (rev.length === 0) {
break; // end of page history (in current view)
}
}
// Restore this version edits
} else if (/^Reverted to revision \d+ by /.test(editcomment)) {
var last_good_revision = /^Reverted to revision (\d+) by /.exec(editcomment)[1];
$(this).hide();
var rev = $(this).next();
while ( rev.attr('data-mw-revid') !== last_good_revision ) {
rev.hide();
rev = rev.next();
if (rev.length === 0) {
break; // end of page history (in current view)
}
}
// not a twinkle rollback?
} else {
return true;
}
}
});
// Mediawiki rollback
$('#pagehistory li.mw-tag-mw-rollback').each(function() {
var editcomment = $(this).find('.comment').text();
// sanity check
if (! editcomment.startsWith('Reverted edits by ')) return true;
var reverted_user = editcomment.slice('Reverted edits by '.length, editcomment.indexOf(' (talk)'));
// IPv6 addresses are in lowercase in history page, but in uppercase in rollback edit summary
if (mw.util.isIPv6Address(reverted_user)) {
reverted_user = reverted_user.toLowerCase();
}
$(this).hide();
var rev = $(this).next();
while ( rev.find('.mw-userlink bdi').text() === reverted_user ) {
rev.hide();
rev = rev.next();
if (rev.length === 0) {
break; // end of page history (in current view)
}
}
});
});