Note: After publishing, you may have to bypass your browser's cache to see the changes.
/*really quick block — adds configurable buttons to blockIP and temporary users from Recent Changes and Page History.Each button takes 4 seconds to 'load', to prevent accidental blocks,and is available for another 6 seconds to 'shoot'.Re-blocks are disabled, and a warning will be issued.Use responsibly!Documentation: [[:m:User:Ponor/really-quick-block]]*/$(document).ready(function(){if(!(mw.config.get("wgUserGroups").includes("sysop")&&(mw.config.get("wgCanonicalSpecialPageName")==="Recentchanges"||mw.config.get("wgCanonicalSpecialPageName")==="Watchlist"||mw.config.get("wgAction")==="history"))){return;}//you don't belong here//available block options: anononly, autoblock, nocreate, allowusertalk, noemail//see mediawiki.org/wiki/API:Blockif(!window.rqb_buttons){window.rqb_buttons={V4:{reason:"vandalism",expiry:"4 hours",options:["anononly"]},P6:{reason:"profanity",expiry:"6 hours",options:["anononly"]},A24:{reason:"attacks",expiry:"24 hours"},};}mw.util.addCSS(`.rqb-button {font-size:90%; border:2px dotted #f66; border-radius:6px; padding:0 2px; margin-right:4px;}.rqb-button-disabled {background-color:transparent; color:gray; border-color:gray;}`);//triggered by Recent Changes autoupdatemw.hook("wikipage.content").add(function(el){if(el.hasClass('mw-changeslist')){initialize();}});initialize();//------------------------------------------------------- hoisted functionsfunctioninitialize(){letelements=$('li[data-mw-revid] a.mw-tempuserlink');// temporary accountsif(elements.length==0){elements=$('li[data-mw-revid] a.mw-anonuserlink');// IPs}elements.each(function(){letsp=$("<span/>");for(constbinwindow.rqb_buttons){letbutton=$(`<a>${b}</a>`);button.addClass("rqb-button").attr("data-anon",$(this).text())//.data("expiry", window.rqb_buttons[b].expiry).attr("title",window.rqb_buttons[b].reason+': '+window.rqb_buttons[b].expiry).on('click',on_click);sp.append(button);}$(".mw-usertoollinks",$(this).parent()).append(sp);});}//on_load//first click: 4 seconds to "load",the button remains inactive; 4+2 seconds to "shoot" or go back to inactive againfunctionon_click(){if($(this).data("status")===undefined||$(this).data("status")==="WAITING"){$(this).data("status","LOADING");$(this).animate({"background-color":"#f66"},4000,()=>{$(this).data("status","CHARGED")}).delay(4000).animate({"background-color":"transparent"},2000,()=>{$(this).data("status","WAITING")});}elseif($(this).data("status")==="CHARGED"){//ready to block//console.log("BLOCKED")letanon=$(this).attr("data-anon");if(anon.match(/^~\d{4}(?:-\d{1,6})+$/)||(anon+'.').match(/^(?:\d{1,3}\.){4}$/)||anon.match(/^(?:[0-9a-f]{0,4}:){2}[:0-9a-f]*$/))(api_block(anon,window.rqb_buttons[$(this).text()].expiry,window.rqb_buttons[$(this).text()].reason,window.rqb_buttons[$(this).text()].options));}}functionapi_block(user,expiry='1 minute',reason='block test',options=["anononly","autoblock","nocreate","allowusertalk"]){if(!user){return;}//if not already blocked, blockletapi=newmw.Api();varblocksPromise=api.get({"action":"query","format":"json","list":"blocks","bkusers":user,"bkprop":"id|by"});blocksPromise.done(function(jsondata){if(jsondata.query.blocks.length===0){varparams={action:'block',format:'json',//anononly: "", //yes//nocreate: "", //yes//autoblock: "", //yes//allowusertalk: "", //yesuser:user,expiry:expiry,reason:reason,};for(constiofoptions.keys()){params[options[i]]="";//means yes}api.postWithToken('csrf',params).done(function(){$("a.rqb-button[data-anon='"+user+"']").addClass("rqb-button-disabled").data("status","BLOCKED").off();mw.notify("⛔ "+user,{'type':'success'});}).fail(function(){mw.notify("⚡⚡⚡ "+user,{'type':'error'});});}else{mw.notify("2× ⛔ "+user,{'type':'warn'});$("a.rqb-button[data-anon='"+user+"']").addClass("rqb-button-disabled").data("status","DISABLED").off();}});//blocksPromise.done}//api_block});