User:Caburum/global.js

// Hello and welcome to my global JS page window.dev = window.dev || {}; window.caburum = { shouldRunGlobal: window.location.search.indexOf('useglobaljs') === -1 && window.location.search.indexOf('usecabjs') === -1, // return true if the global script should run, shouldRunLocal: window.location.search.indexOf('uselocaljs') === -1 && window.location.search.indexOf('usecabjs') === -1, // return true if the local script should run ran: false, init: function { if (![			'Caburum',			'CaburumBot',			'Among Us Wiki Bot'		].includes(mw.config.get('wgUserName'))) return console.error('You\'re not Cab!'); // Prevent users other than me from loading this mw.config.get('wgUserGroups').forEach(function(group) { // Sets the current user's groups to true in groups object			window.caburum.groups[group] = true;		}); if (!this.shouldRunGlobal) { this.log('Did not execute global.js from Community Central, disabled'); } else if (!this.ran) { this.log('Executed global.js from Community Central'); $(this.exec.bind(this)); this.ran = true; }	},	exec: function { $.extend(window, { // Script config			AjaxRename: { // w:c:dev:AjaxRename				check: {					leaveredirect: false,					watch: false,					movetalk: true				},				renameReasons: {					'Normal': {						'Misnamed': 'Misnamed',						'Better name': 'Better name',						'Fixing capitalization': 'Fixing capitalization'					},					'Other': {						'Page does not belong in namespace': 'Page does not belong in namespace',					}				}			},			andrewds1021: {				view_notifications_users: { // w:c:dev:ViewNotificationsUsers					all_types: true,					content: 'name'				},				ignore_notifications: { // w:c:dev:IgnoreNotifications					ignore_errors: true,					filters: [						{							types: 'discussion-upvote'						},						{							wiki_ids: [								2078067,								2411433,								2417668,								2386902,								2424513							],							types: 'announcement-target'						}					]				}			},			AutoCreateUserPagesConfig: { // w:c:dev:MediaWiki:AutoCreateUserPages.js content: { 2: '',					3: false, 1202: false },				summary:'Automated user page creation' },			dev: { i18n: {overrides: { // i18n overrides Rollback: { summary: 'Reverted edits by $1 (talk) to last version by $2' }				}}			},			FCButtons: [ // w:c:dev:FastCreate {					label: 'Create bot userpage', target: 'User:CaburumBot', summary: 'Creating my bot\'s userpage', content: '', prepend: true, placement: mw.config.get('skin') === 'fandomdesktop' ? '.global-navigation__bottom > .wds-dropdown > .wds-dropdown__content > .wds-list' : '.wds-global-navigation__user-menu .wds-list' }			],			fdButtons: [ // w:c:dev:FastDelete {					summary: 'Housekeeping', label: 'HK' },				{					summary: 'Vandalism', label: 'V'				}, {					summary: 'Spam', label: 'S'				}, {					summary: 'Duplicate', label: 'Dp' }			],			globalNavButtons: [ // w:c:dev:GlobalNavButtons /* Patrolling */ window.caburum.globalNavPage('Recent Changes', 'Special:RecentChanges', {m: 'RC', i: ' '}), window.caburum.globalNavPage('New files', 'Special:NewFiles', {p: 'RC'}), window.caburum.globalNavPage('New pages', 'Special:NewPages', {p: 'RC'}), window.caburum.globalNavPage('New messages', 'Special:SocialActivity', {p: 'RC', r: 'containerTypes=WALL'}), window.caburum.globalNavPage('New comments', 'Special:SocialActivity', {p: 'RC', r: 'containerTypes=ARTICLE_COMMENT'}), /* Social */ window.caburum.globalNavLink('Forum', mw.config.get('wgScriptPath') + '/f', {m: false, p: false, i: ' '}), /* MediaWiki */ window.caburum.globalNavPage('MediaWiki', 'Special:AllPages/MediaWiki:', {m: 'MW', i: ' '}), window.caburum.globalNavPage('Common CSS', 'MediaWiki:Common.css', {p: 'MW'}), window.caburum.globalNavPage('Oasis CSS', 'MediaWiki:Wikia.css', {p: 'MW'}), window.caburum.globalNavPage('FandomDesktop CSS', 'MediaWiki:Fandomdesktop.css', {p: 'MW'}), window.caburum.globalNavPage('Common JavaScript', 'MediaWiki:Common.js', {p: 'MW'}), window.caburum.globalNavPage('FandomDesktop JavaScript', 'MediaWiki:Fandomdesktop.js', {p: 'MW'}), window.caburum.globalNavPage('ImportJS', 'MediaWiki:ImportJS', {p: 'MW'}), window.caburum.globalNavPage('Wiki navigation', 'MediaWiki:Wiki-navigation', {p: 'MW'}), /* Personal */ window.caburum.globalNavPage('Me', 'Special:MyPage', {m: 'ME', i: ' '}), window.caburum.globalNavPage('Sandbox', 'Special:MyPage/Sandbox', {p: 'ME'}), window.caburum.globalNavPage('Local JavaScript', 'Special:MyPage/common.js', {p: 'ME'}), window.caburum.globalNavPage('Local CSS', 'Special:MyPage/common.css', {p: 'ME'}), window.caburum.globalNavLink('Global JavaScript', 'https://community.fandom.com/wiki/Special:MyPage/global.js', {p: 'ME'}), window.caburum.globalNavLink('Global CSS', 'https://community.fandom.com/wiki/Special:MyPage/global.css', {p: 'ME'}), /* Wikis */ window.caburum.globalNavLink('Wikis', 'https://caburum.fandom.com/wiki/User:Caburum/RecentChanges', {m: 'W', i: '<path id="map-small" d="M16 13.325l-3 1.2V4.688l3-1.2v9.837zm-5 1.2l-3-1.2V3.488l3 1.2v9.837zm-5-1.2l-3 1.2V4.688l3-1.2v9.837zM17.561 1.186a1.003 1.003 0 0 0-.933-.1L12 2.935 7.376 1.088a.929.929 0 0 0-.101-.035h-.001l-.002-.002h-.001a.971.971 0 0 0-.266-.037h-.009c-.067-.04-.187.013-.278.041h-.002l-.003.001-.089.031-4.996 1.997A1 1 0 0 0 1 4.012V16a1 1 0 0 0 1.372.927L7 15.078l4.624 1.848c.033.013.067.025.101.035h.001l.002.002h.001c.088.024.204.005.267.037h.009a.974.974 0 0 0 .277-.041h.002l.003-.001c.029-.009.06-.02.089-.032l4.996-1.996a1 1 0 0 0 .628-.927V2.013a.999.999 0 0 0-.439-.827z"> '}), window.caburum.globalNavLink('Among Us Wiki', 'https://among-us.fandom.com/wiki/', {p: 'W'}), window.caburum.globalNavLink('Community Central', 'https://community.fandom.com/wiki/', {p: 'W'}), window.caburum.globalNavLink('Dev Wiki', 'https://dev.fandom.com/wiki/', {p: 'W'}), window.caburum.globalNavLink('Discord Wiki', 'https://discord.fandom.com/wiki/', {p: 'W'}), window.caburum.globalNavLink('Test Wiki', 'https://caburum.fandom.com/wiki/', {p: 'W'}), window.caburum.globalNavLink('Customize Your Wiki', 'https://custom.fandom.com/wiki/', {p: 'W'}) ],			MessageBlock: { // w:c:dev:MessageBlock title : 'Blocked', message : 'You have received a $2 block for the reason: \'$1\'. Unless otherwise stated, you may appeal your block on my message wall at Community Central.', autocheck : true }		});

if (window.caburum.groups['sysop'] || window.caburum.groups['content-moderator'] || window.caburum.groups['threadmoderator']) { window.globalNavButtons.push(				window.caburum.globalNavPage('Message deletion', 'Special:SocialActivity', {p: 'RC', r: 'deleted=true&containerTypes=WALL'}),				window.caburum.globalNavLink('Reported posts', mw.config.get('wgScriptPath') + '/f/reported', {p: 'RC'})			); }

if (mw.config.get('wgNamespaceIds').gadget) { window.globalNavButtons.push(				window.caburum.globalNavPage('Gadgets', 'Special:Gadgets', {p: 'MW'})			); }

// Move "Explore" menu back to the end $('.fandom-community-header__local-navigation .wds-tabs .wds-dropdown:first-child').each(function {			$(this).appendTo($(this).parent);		});

// Execute common.js		if (!window.caburum.shouldRunLocal) { window.caburum.log('Did not execute common.js, disabled'); } else { mw.hook('caburum.runLocalJS').fire; }

// Load scripts based on criteria var articles = []; window.caburum.scripts.forEach(function(source) {			$.each(source.scripts, function(script, data) { var groups = []; if (Array.isArray(data)) { // Array of group rights groups = data; } else if (typeof data === 'string') { // Single group groups = [data]; } else if (typeof data === 'object') { // Advanced config groups = groups.concat(data.groups || data.group); if ((data.skins || data.skin) && ![].concat(data.skins || data.skin).includes(mw.config.get('skin'))) return; if ((data.wikis || data.wiki) && ![].concat(data.wikis || data.wiki).includes(mw.config.get('wgCityId'))) return; }

// If all other checks pass, then check groups if (groups.filter(function(group) { return window.caburum.groups[group]; // True if user has group }).length > 0) { articles.push(source.prefix + script + '.js'); }			});		});		importArticles({			type: 'script',			articles: articles		}); },	scripts: [ // Scripts to import per source, dependent on user groups { // Dev Wiki prefix: 'u:dev:MediaWiki:', scripts: { // Maintenance 'AjaxBatchDelete': ['sysop', 'content-moderator'], 'AjaxRename/ucp': '*', 'FastDelete/code': ['sysop', 'content-moderator'], 'Rollback/code': '*', 'AnchoredRollback/code': '*', 'ListFiles/code': '*', 'MassNullEdit/code': '*',

// Admin //'AjaxBlock/code': ['sysop'], // Conflicts with MessageBlock 'MessageBlock/code': ['sysop'], 'SOAPReport': '*', 'WHAM/code.2': ['sysop', 'content-moderator', 'threadmoderator', 'rollback'],

// Tools 'QuickDiff/code': '*', // 'MultiUpload', 'UploadMultipleFiles': '*', 'LastEdited/code': '*', 'FastCreate': '*', 'QuickPurge': '*', 'CopyTitle': '*',

// Personal 'DisplayTimer/code': '*', 'AutoCreateUserPages': '*', 'GlobalNavButtons': '*',

// Social 'ViewNotificationsUsers': '*', 'IgnoreNotifications': '*', 'UserAndIPTools': '*', 'UserAccountAge/code2': '*',

// Editing // 'DecodeURI/code': '*', 'ImageMapEdit': '*', }		},		{ // Caburum Testing Wiki prefix: 'u:caburum:MediaWiki:', scripts: { 'BadgeStatusUpdater': '*', 'ThemeSwitcher': {group: '*', skin: 'fandomdesktop'} }		},		{ // Personal prefix: 'u:caburum:User:Caburum/', scripts: { 'MassEdit': '*' }		}	],	groups: {}, // Stored user group object, value is true if user has group, populated in init log: function { // Formatted console.log console.log.apply(null, Array.prototype.concat('%c[CABURUM]', 'color: #00D6D6; background-color: #202124;', Array.prototype.slice.call(arguments))); },	globalNavPage: function(title, page, args) { // Creates a GlobalNavButtons object for an internal page args = { p: args.p || undefined, r: args.r || undefined, m: args.m || false, i: args.i || undefined };		return { text: title, url: mw.util.getUrl(page) + (args.r ? '?' + args.r : ''), isMain: args.m ? true : false, whoIsMain: args.m ? false : args.p, shortName: args.m ? args.m : title, icon: args.i		}; },	globalNavLink: function(title, url, args) { // Creates a GlobalNavButtons object for an external link args = { p: args.p || undefined, m: args.m || false, i: args.i || undefined };		return { text: title, url: url, isMain: args.m ? true : false, whoIsMain: args.m ? false : args.p, shortName: args.m ? args.m : title, icon: args.i		}; }, };

$(window.caburum.init.bind(window.caburum));