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.
// <nowiki>/* ConfirmRollback * * This script allows you to customise your rollback links. You can either * allow them, hide them, or ask for confirmation when you click them. * Furthermore, you can have different rollback settings for different pages, * and different settings for mobile and desktop devices. * * To install, add the following to your [[Special:MyPage/skin.js]]:importScript('User:Mr. Stradivarius/gadgets/ConfirmRollback.js') // Linkback: [[User:Mr. Stradivarius/gadgets/ConfirmRollback.js]] * See [[User:Mr. Stradivarius/gadgets/ConfirmRollback]] for documentation. */mw.loader.using(['oojs-ui'],function(){"use strict";// Get a rollback status of either "hide", "confirm" or "allow" for a given// page type and device type.functiongetRollbackStatus(pageType,deviceType){vardefaultConfig={desktop:{watchlist:'confirm',contributions:'allow',recentchanges:'allow',relatedchanges:'allow',history:'allow',diff:'allow'},mobile:{watchlist:'confirm',contributions:'confirm',recentchanges:'confirm',relatedchanges:'confirm',history:'confirm',diff:'confirm'}};varscriptConfig=window.ConfirmRollback||{};vardeviceDefaults=defaultConfig[deviceType];functionresolveRollbackStatus(cfg){// resolve the config object recursively. We need to be recursive// because the config syntax is very flexible.varret;if(typeof(cfg)==='object'){if(cfg.mobile||cfg.desktop){returnresolveRollbackStatus(cfg[deviceType]);}else{ret=cfg[pageType];}}elseif(cfg==='hide'||cfg==='allow'||cfg==='confirm'){ret=cfg;}returnret||deviceDefaults[pageType]||'confirm';}returnresolveRollbackStatus(scriptConfig);}// Makes the message that says something like// "Revert 5 edits by Mr. Stradivarius?"functionmakeRollbackMessage(event){vartargetText=$(event.target).text();varcount=targetText.match(/\d/)?targetText.match(/\d+/)[0]:null;varedits=count?count+' edits':'edit';varuser=mw.util.getParamValue('from',event.target.href);return'Roll back '+edits+' by '+user+'?';}// Handles rollback clicks on mobile devices. This uses the default browser// window.confirm dialog, as OO-js UI windows on mobile are tiny and// unreadable.functionhandleMobileClicks($rollbackLinks){$rollbackLinks.click(function(event){varmessage=makeRollbackMessage(event);if(!confirm(message)){returnevent.preventDefault();}});}// Handle rollback clicks on desktop. This uses OO-js UI, which looks// pretty on desktops.functionhandleDesktopClicks($rollbackLinks){// Initialize the dialog object.varconfirmationDialog=newOO.ui.MessageDialog();varwindowManager=newOO.ui.WindowManager();$('body').append(windowManager.$element);windowManager.addWindows([confirmationDialog]);$rollbackLinks.click(function(event){event.preventDefault();varmessage=makeRollbackMessage(event);windowManager.openWindow(confirmationDialog,{title:'Confirm rollback',message:message,actions:[{action:'rollback',label:'OK',flags:['primary','destructive']},{label:'Cancel'}]}).then(function(opening){opening.then(function(opened){opening.then(function(closing,data){// The dialog is open. Check for the rollback action// and if detected, follow the original rollback link// URL.if(data&&data.action==='rollback'){window.open($(event.target).attr('href'),'_top');}});});});});}varpageType,deviceType,rollbackStatus,$rollbackLinks;varmwConfig=mw.config.get(['wgCanonicalSpecialPageName','wgAction']);// Find the page type, and exit if we are not viewing a page on which// rollback links can appear.if(mwConfig.wgCanonicalSpecialPageName==='Watchlist'){pageType='watchlist';}elseif(mwConfig.wgCanonicalSpecialPageName==='Contributions'){pageType='contributions';}elseif(mwConfig.wgCanonicalSpecialPageName==='Recentchanges'){pageType='recentchanges';}elseif(mwConfig.wgCanonicalSpecialPageName==='Recentchangeslinked'){pageType='relatedchanges';}elseif(mwConfig.wgAction==='history'){pageType='history';}elseif($(___location).attr('href').indexOf('&diff')!==-1){pageType='diff';}else{return;}deviceType=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?'mobile':'desktop';rollbackStatus=getRollbackStatus(pageType,deviceType);$rollbackLinks=$('.mw-rollback-link');if(rollbackStatus==='hide'){$rollbackLinks.css('display','none');}elseif(rollbackStatus==='allow'){$rollbackLinks.css('display','inline');}elseif(rollbackStatus==='confirm'){// Display rollback links if they are hidden.$rollbackLinks.css('display','inline');// Handle rollback clicks.if(deviceType==='mobile'){handleMobileClicks($rollbackLinks);}else{handleDesktopClicks($rollbackLinks);}}});// </nowiki>