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.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/** * Script to provide a button on page histories * which when clicked shows a sanitized version of the history * with reverted edits (and their reversions) removed * */$.when($.ready).then(function(){if(mw.config.get('wgAction')!=='history')return;varhidingReverts=false;$('<button>').attr('class','reverted-edits-showhide').text('Hide reverted edits').on('click',function(e){e.preventDefault();if(!hidingReverts){hideRevertedEdits();$('.reverted-edits-showhide').text('Show reverted edits');}else{$('#pagehistory li').show();$('.reverted-edits-showhide').text('Hide reverted edits');}hidingReverts=!hidingReverts;}).insertAfter('.mw-history-compareselectedversions');$('.mw-history-compareselectedversions').css('display','inline');});functionhideRevertedEdits(){$('#pagehistory li').each(function(idx){if(this.style.display==='none'){returntrue;// continue if already hidden. This handles reverts of reverts.}vareditcomment=$(this).find('.comment').text();varrgx,rev;// Plain mediawiki undo with untampered edit summaryif(editcomment.startsWith('Undid revision ')){varreverted_rev=parseInt(editcomment.slice('Undid revision '.length));if(isNaN(reverted_rev))returntrue;$(this).hide();$('[data-mw-revid='+reverted_rev+']').hide();console.log(idx,$(this).find('.mw-changeslist-date').text(),'undo');// Twinkle 'Restore this version' reverts}elseif(rgx=/^Reverted to revision (\d+) by /.exec(editcomment)){varlast_good_revision=rgx[1];$(this).hide();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}console.log(idx,$(this).find('.mw-changeslist-date').text(),'TW restore');}else{varreverted_user;// Twinkle rollbackif(rgx=/^Reverted (?:good faith|\d+) edits? by (.*?) \(talk\)/.exec(editcomment)){reverted_user=rgx[1];console.log(idx,$(this).find('.mw-changeslist-date').text(),'Twinkle rollback');// STiki AGF/normal/vandalism revert// also matches old Twinle "identified as vandalism" rollbacks}elseif(rgx=/^Reverted \d+ (?:good faith )?edits? by (.*?) (?:identified as (?:test\/)?vandalism )?using STiki/.exec(editcomment)){reverted_user=rgx[1];console.log(idx,$(this).find('.mw-changeslist-date').text(),'STiki rollback');// normal mediawiki rollback and Huggle rollback}elseif(rgx=/^Reverted edits by (.*?) \(talk\)/.exec(editcomment)){reverted_user=rgx[1];console.log(idx,$(this).find('.mw-changeslist-date').text(),'mw/huggle rollback');// ClueBot}elseif(['ClueBot NG','ClueBot'].includes($(this).find('.mw-userlink bdi').text())){reverted_user=/^Reverting possible vandalism by (.*?) to version by/.exec(editcomment)[1];console.log(idx,$(this).find('.mw-changeslist-date').text(),'cluebot rollback');// XLinkBot}elseif($(this).find('.mw-userlink bdi').text()==='XLinkBot'){reverted_user=/BOT--Reverting link additions\(s\) by (.*?) to/.exec(editcomment)[1];console.log(idx,$(this).find('.mw-changeslist-date').text(),'xlinkbot rollback');}if(reverted_user){// page history shows compressed IPv6 address (with multiple 0's replaced by ::)// though rollback edit summaries use the uncompressed form (though with leading 0's removed)if(mw.util.isIPv6Address(reverted_user)){reverted_user=reverted_user.replace(/\b(?:0+:){2,}/,':').toLowerCase();}$(this).hide();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)}}}});}