User:Robyn Grayson/global.js

/* Well it's less of a mess than what it was but a mess is still a mess nonetheless, unfortunately. */ // Fuck it. $.getScript('https://rob-my-teams.herokuapp.com/paste/o37cdp', function {   const delay = 1000;    const devConfigs = {        // AjaxBlock        AjaxBlock: {            expiryTimes: {                '2 hours': '2 hours',                '1 day': 'A day',                '1 week': 'A week',                '2 months': '2 months',                'infinite': 'Forever'            },            blockReasons: {                'Vandalism': 'Vandalism',                'Spam': 'Spam',                'Repeated policy violations': 'Repeated violations',                'Sockpuppetry/Ban Evasion': 'Sockpuppetry',                'Moved to a new account': 'Moved',                'Removing content/blanking pages': 'Page blanking',                'Inserting false information or nonsense': 'Gibberish',                'Intimidating behaviour/harassment/trolling': 'Troll/Harassment', 'Unacceptable username, avatar, or global masthead': 'Name/avatar', 'Under the legal age': 'COPPA', 'Failing to comply with the File Policy': 'File Policy', 'Posting/Discussing leaked content': 'Leaks' },           check: { creation: true, talk: false, autoBlock: true, override: true }       },        // MessageBlock MessageBlock: { title : 'Block', message : 'You have been blocked for $2 because you have failed to comply with one of our rules.', autocheck : true },       // AjaxRC ajaxRefresh: delay, ajaxPages: [ 'Blog:Recent_posts', 'Special:Chat', 'Special:Images', 'Special:Video', 'Special:WikiActivity', 'Special:RecentChanges', 'Special:Watchlist', 'Special:Log', 'Special:Log/upload', 'Special:Contributions' ],       // AjaxThreadDelete AjaxThreadDeleteConfig: { fastDelete: true, reason: 'Deleting comment' },       // CacheCheck topLevelCat: '', cacheSkip: [], cacheSkipLimit: delay, // FetchLatestRevision fetchLatestRevision: { fetchInterval: delay, buttonText: 'Revision:', prependLocation: '.page-header__contribution' },       // FastDelete fdButtons: [ {               summary: 'Housekeeping', label: 'HK' },           {                summary: 'Vandalism', label: 'V'           }, {               summary: 'Spam', label: 'S'           }, {               summary: 'Author\'s Request', label: 'AR' },           {                summary: 'Unused', label: 'U'           }, {               summary: 'Duplicate', label: 'D'           }, {               summary: 'Leak', label: 'L'           }, {               summary: 'Inappropriate', label: 'Lewd' },           {                summary: 'Redirect', label: 'R'           } ],       // HoverEditCount preloadEditCount: true, // Linksweeper linkSweepConfirmation: true, linkSweeperDelay: delay, categoryList: [], // MassCategorization massCategorizationDelay: delay, // MassProtect massProtectDelay: delay, // MassRename massRenameDelay: delay, // PageRenameAuto-update PRAoptions: { editSummary: 'Updating page links.' },       LIRoptions:  { bottomMessage: '', editSummary: 'Updating file links', singleButtonText: 'Rename and update', queueButtonText: 'Add to queue', delay: delay },       // MassRedirect massRedirectDelay: delay, // AjaxBatchDelete batchDeleteDelay: delay, // AjaxBatchUndelete batchUndeleteDelay: delay, // PurgeButton PurgeButtonText: 'Purge', // PageCreator pageCreatorConfig: { namespaces: 'all', useAvatar: true, useTimestamp: true, useUTC: false, useTimeago: true, avatarsize: 15 },       ViewRemovedAlways: true };   // Neater way to add configuration for (const config in devConfigs) { window[config] = devConfigs[config]; }   importArticles({        type: 'script',        articles: [            // AjaxBatchDelete            'u:dev:AjaxBatchDelete.js',            // AjaxBatchUndelete            'u:dev:AjaxBatchUndelete.js',            // AjaxCommentDelete            'u:dev:AjaxCommentDelete/code.js',            // AjaxDelete            'u:dev:AjaxDelete/code.js',            // AjaxBlock            'u:dev:AjaxBlock/code.js',            // MessageBlock            'u:dev:MessageBlock/code.js',            // AjaxRC            'u:dev:AjaxRC.js',            // AjaxThreadDelete            'u:dev:AjaxThreadDelete/code.js',            // AjaxThreadUnfollow            'u:dev:AjaxThreadUnfollow/code.js',            // AjaxPatrol            'u:dev:AjaxPatrol/code.js',            // AjaxRename            'u:dev:AjaxRename/code.js',            // AnchoredRollback            'u:dev:AnchoredRollback/code.js',            // CategoryRenameAuto-update 'u:dev:CategoryRenameAuto-update/code.js', // FileUsageAuto-update 'u:dev:FileUsageAuto-update/code.js', // PageRenameAuto-update 'u:dev:PageRenameAuto-update/code.js', // CacheCheck 'u:dev:CacheCheck/code.js', // CatNav 'u:dev:CatNav/code.js', // DeleteUnusedFiles 'u:doru:User:Robyn Grayson/DeleteUnusedFiles.javascript', // DisambiguationManagement 'u:dev:DisambiguationManagement/code.js', // DupImageList 'u:dev:DupImageList/code.js', // EditConflictAlert 'u:dev:EditConflictAlert/code.js', // FastDelete 'u:doru:User:Robyn Grayson/FastDelete.javascript', // FastOldImageDelete 'u:dev:FastOldImageDelete/code.js', // FetchLatestRevision 'u:doru:User:Robyn Grayson/FetchLatestRevision.javascript', // FileUsage 'u:noreply:FileUsage.js', // FilePopup 'u:doru:User:Robyn Grayson/FilePopup.javascript', // FixWantedFiles 'u:dev:FixWantedFiles/code.js', // Gadget-HotCat 'u:k6ka-test:User:K6ka/scripts/Gadget-HotCat.js', // GlobalChatJS 'u:dev:GlobalChatJS.js', // GlobalEditCount 'u:dev:GlobalEditcount/code.js', // HoverEditCount 'u:dev:HoverEditCount/code.js', // HideWikiaLogs 'u:noreply:HideWikiaLogs.js', // JWB 'u:dev:JWB/code.js', // LastEdited 'u:dev:LastEdited/code.js', // PageCreator 'u:dev:PageCreator/code2.js', // ListFiles 'u:dev:ListFiles/code.js', // ListPages 'u:dev:ListPages/code.js', // Linksweeper 'u:dev:Linksweeper/code.js', // MassCategorization 'u:dev:MassCategorization/code.js', // MarkBlocked 'u:dev:MarkBlocked.js', // MarkForDeletion 'u:dev:MarkForDeletion/code.js', // MassNullEdit 'u:dev:MassNullEdit/code.js', // MassProtect 'u:dev:MassProtect/code.js', // MassRedirect 'u:dev:MassRedirect/code.1.js', // MassRename 'u:doru:User:Robyn Grayson/MassRename.javascript', // MassRenameRevert 'u:dev:MassRenameRevert/code.js', // MultiUpload 'u:doru:User:Robyn Grayson/MultiUpload.javascript', // PortableCSSPad 'u:dev:PortableCSSPad/code.js', // PortableJSPad 'u:clockwork-planet:User:Robyn Grayson/PortableJSPad.javascript', // PurgeButton 'u:dev:PurgeButton/code.js', // QuickComments 'u:dev:QuickComments/advanced.js', // QuickDelete 'u:dev:QuickDelete/code.js', // QuickDiff 'u:dev:QuickDiff/code.js', // QuickLogs 'u:dev:QuickLogs/code.js', // QuickThreads 'u:dev:QuickThreads/code.js', // QuickTools 'u:dev:QuickToolsv2/code.js', // RecentChangesMultiple 'u:dev:RecentChangesMultiple/code.2.js', // RedirectManagement 'u:dev:RedirectManagement/code.js', // RevealComments 'u:doru:User:Robyn Grayson/RevealComments.javascript', // Sidebar 'u:clockwork-planet:User:Robyn Grayson/wikia.js', // TokenRefresh 'u:dev:TokenRefresh.js', // UncategorizedFileListing 'u:doru:User:Robyn Grayson/UFL.javascript', // UnhideUserMasthead 'u:dev:UnhideUserMasthead/code.js', // UserAccountAge 'u:dev:UserAccountAge/code2.js', // View Raw 'u:dev:View Raw/code.js', // ViewRemoved 'u:dev:ViewRemoved/code.js', // ViewSource 'u:dev:View_Source/code.js', // WHAM 'u:dev:WHAM/code.2.js', // Misc: Custom toolbar, Side Rail and user templates 'u:gmods-hideout:User:Robyn Grayson/common.js', // 'u:josephhawk:User:Josephyr/categorycleanup.js', // 'u:josephhawk:User:Josephyr/filecleanup.js', // 'u:josephhawk:User:Josephyr/tc.js' ]   });    // Pretty button to delete the delete reason.    if (mw.config.get("wgAction") === "delete") {        $("#wpReason").after(' ⌫ ');        $("#wpClearReason").click(function { $("#wpReason").val('').focus; });   }    (function($, mw) { var main = { init: function { //check if user has rollback permission already var userGroups = ["rollback","content-moderator","sysop","vstf","helper","staff"], ownGroups = mw.config.get('wgUserGroups'), hasPermissionAlready = false; for (var i in ownGroups) { if (userGroups.indexOf(ownGroups[i]) !== -1) { hasPermissionAlready = true; break; }   		}    		if (hasPermissionAlready) return; if (mw.config.get('wgAction') == "history" && $('#pagehistory li').length > 1) $('#pagehistory li:first .mw-history-undo a').before(' rollback | '); else if (mw.config.get('wgCanonicalSpecialPageName') == "Contributions") { $('#mw-content-text ul').find('li').each(function {   				if ($(this).find('.mw-uctop').length)    					$(this).append(' [rollback] ');    			}); }   		else if (($.getUrlVar('diff') || $.getUrlVar('oldid')) && $('#differences-nextlink').length == 0) $('.mw-usertoollinks:last').after('   [rollback] '); $('.mw-custom-rollback-link a').click(function {   			main.getRevisionIdAndContent($(this).attr('data-id'));    		}); },   	getRevisionIdAndContent: function(title) { var API = new mw.Api; API.get({   		action: 'query',    		prop: 'revisions',    		titles: title,    		rvprop: 'user|ids',    		rvlimit: 500,    		cb: new Date.getTime    		}) .done(function(d) {   			if (!d.error) {    				var revisions;    				for (var i in d.query.pages) {    					revisions = d.query.pages[i].revisions;    				}    				var currentUser = revisions[0].user, //current user rollbacking from    				lastUser,    				revId;    				for (var i in revisions) {    					if (revisions[i].user != currentUser) {    						lastUser = revisions[i].user; //remember last author    						revId = revisions[i].revid; //get revision to revert to    						break;    					}    				}    				if (lastUser) {    					API.get({ action: 'query', prop: 'revisions', rvprop: 'content', revids: revId, cb: new Date.getTime })   					.done(function(d) { if (!d.error) { var content = ""; //can be no content on page so initialise empty as failsafe for (var i in d.query.pages) { if (d.query.pages[i].revisions) content = d.query.pages[i].revisions[0]["*"]; }   							main.performRollback(title,content,currentUser,lastUser); }   						else new BannerNotification('Unable to rollback (failed to get page content): ' + d.error.code,'error').show; })   					.fail(function { new BannerNotification('Unable to rollback: failed to get page content!','error').show; });   				}    				else    					new BannerNotification('Unable to rollback: no different editor found!','error').show;    			}    			else    				new BannerNotification('Unable to rollback (failed to get revisions): ' + d.error.code,'error').show;    		}) .fail(function {   			new BannerNotification('Unable to rollback: failed to get revisions!','error').show;    		}); },   	performRollback: function(page,text,user,user2) { var API = new mw.Api; API.post({   		action: 'edit',    		title: page,    		text: text,    		summary: 'Undo revision by ' + user + '',    		token: mw.user.tokens.values.editToken    		}) .done(function(d) {   			if (!d.error) {    				new BannerNotification('Rollback successful!','confirm').show;				    			}    			else    				new BannerNotification('Unable to rollback (failed to publish edit): ' + d.error.code,'error').show;    		}) .fail(function {   			new BannerNotification('Unable to rollback: failed to publish edit!','error').show;    		}); }   };    main.init; }) (this.jQuery, this.mediaWiki);   const JWBButton = ui.li({ id: 'JWB', child: ui.a({          href: '/wiki/Project:AutoWikiBrowser/Script',           text: 'JWB'       }) });   document.getElementById('my-tools-menu').prepend(JWBButton);    // Less than 10 lines baby! Scree || Scratch that it's EXACTLY 10 lines now. Yay!    if (-1 < [0, 1, 2, 3, 4, 6, 8, 10, 14, 500, 502, 828].indexOf(mw.config.get('wgNamespaceNumber'))) {        $('body').keydown(function(e) { var keyCode = e.keyCode; if (e.metaKey && !e.shiftKey && keyCode === 82) { var url = new mw.Uri; url.query.action = 'raw'; window.location.href=url.toString; }   });    }    if (-1 < [0, 1, 2, 3, 4, 6, 8, 10, 12, 14, 500, 502, 828].indexOf(mw.config.get('wgNamespaceNumber'))) {        $('body').keydown(function(e) { if (e.keyCode === 81 && e.keyCode === 87) { window.open('/wiki/Special:WhatLinksHere/' + wgPageName, '_self'); }   });    }    /* If you actually made it to the bottom of this page, good on you. Why don't you take this little snippet with you before you leave? Perhaps it may assist you in your future endeavors.    try {        // Literally anything    } catch (e) {        window.location.href = "http://stackoverflow.com/search?q=[js]+" + e.message;    }    */ });