User:Evad37/EditWarChecker.js
Appearance
From Wikipedia, the free encyclopedia
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 code will be executed when previewing this page.
This user script seems to have a documentation page at User:Evad37/EditWarChecker.
/* jshint esversion: 5, laxbreak: true, undef: true, eqnull: true, maxerr: 999 */ /* globals console, window, ,ドル mw */ $.when( mw.loader.using(["mediawiki.api"]), $.ready ).then(function(){ varconfig=mw.config.get(['wgPageName','wgArticleId','wgNamespaceNumber']); if(config.wgNamespaceNumber!==0||config.wgArticleId===0){ return; } varminMax=function(number,min,max){ if(number<min){ returnmin; }elseif(number>max){ returnmax; } returnnumber; }; config.hours=minMax(window.EWC_hours||24,2,72); varapi=newmw.Api({ ajax:{ headers:{ "Api-User-Agent":"EditWarChecker ( https://en.wikipedia.org/wiki/User:Evad37/EditWarChecker )" } } }); api.get({ "action":"query", "format":"json", "prop":"revisions", "titles":config.wgPageName, "rvprop":"ids|timestamp|flags|comment|user|tags|size", "rvslots":"*", "rvlimit":"max", "rvend":newDate(Date.now()-config.hours*60*60*1000).toISOString() }) .then(function(response){ varrevertUsers={}; varmaxUserReverts=0; functionaddRevert(user){ if(revertUsers[user]){ revertUsers[user]=revertUsers[user]++; }else{ revertUsers[user]=1; } if(revertUsers[user]>maxUserReverts){ maxUserReverts=revertUsers[user]; } } varreverts=(response.query.pages[config.wgArticleId].revisions||[]) .filter(function(revision,index,arr){ // Edits tagged by system if(revision.tags.includes("mw-undo")||revision.tags.includes("mw-rollback")){ addRevert(revision.user); returntrue; } // Edits with undo/revert comment if(/(?:undo|undid|revert)/i.test(revision.comment)){ addRevert(revision.user); returntrue; } // Edits with same kB change but opposite signs varthisEditDiffSize=revision.size-(arr[index+1]?arr[index+1].size:NaN); varprevEditDiffSize=(arr[index+1]?arr[index+1].size:NaN)-(arr[index+2]?arr[index+2].size:NaN); varminDiffSize=10;// prevent false positives from minor copyedits if(thisEditDiffSize&&prevEditDiffSize&&thisEditDiffSize>minDiffSize&&thisEditDiffSize===prevEditDiffSize*-1){ addRevert(revision.user); returntrue; } returnfalse; }); varrevertCount=reverts.length; varrevertUsersCount=Object.keys(revertUsers).length; varusersToList=$.map(revertUsers,function(reverts,user){ returnreverts>3?user+" ("+reverts+")":null; }).join(", "); varmessage="Approximately "+revertCount+ (revertCount===1 ?" revert" :" reversions" )+ (revertUsersCount>0 ?" by "+revertUsersCount+ (revertUsersCount===1 ?" user" :" users" ) :"" )+ " in the last "+config.hours+" hours."+ (usersToList ?"\nUsers with 4+ reverts: "+usersToList :"" ); var$symbol=$("<img width='20' height='20' style='float:right;cursor:pointer;' title='Edit war checker'>"); switch(true){ // Grey (non-alert): No reverts, or single revert caserevertCount<=1: $symbol.attr("src","https://upload.wikimedia.org/wikipedia/commons/e/e1/ButtonGray.svg"); break; // Green alert: Everyone well within 3RR; not too many total reverts casemaxUserReverts<=2&&revertCount<=5: $symbol.attr("src","https://upload.wikimedia.org/wikipedia/commons/3/3c/ButtonGreen.svg"); break; // Orange alert: One or more users at the 3RR limit; and/or quite a few reverts casemaxUserReverts<=3&&revertCount<=10: $symbol.attr("src","https://upload.wikimedia.org/wikipedia/commons/a/a6/ButtonOrange.svg"); break; // Red alert: One or more users are passed the 3RR limit; and/or there are a lot of reverts default: $symbol.attr("src","https://upload.wikimedia.org/wikipedia/commons/9/97/ButtonRed.svg"); break; } $symbol.click(function(){ mw.notify(message,{title:"Edit war checker",tag:"editWarCheck"}); }); $('h1').append($symbol); }) .catch(function(code,errorInfo){ console.error("EditWarChecker error",errorInfo||code||"Unknown error"); varmessage=errorInfo&&errorInfo.info||code.toString()||"Unknown error"; mw.notify(message,{title:"EditWarChecker failed to load"}); }); });