User:Vastmine1029/common.js

/************* Title       :   ContributionsTools Description :   Displays contribution tools from Special:Contributions on "User" name space pages Author      :   Vastmine1029 Version     :   1.0

mw.loader.using('mediawiki.api', function {	function main {		var config = mw.config.get([ 'wgUserName', 'wgUserGroups', 'wgVersion', 'wgCanonicalSpecialPageName' ]);		var user = mw.config.get('wgRelevantUserName');		var sitename, lang, langForSiteName = "", domain, rootdomain, subdomain;		var api = new mw.Api, data;			var userGroups = config.wgUserGroups.join; // e.g., str -> "*,user,autoconfirmed,emailconfirmed"		var checkUser = false;		var re = new RegExp('threadmoderator|content-moderator|sysop|staff|soap|helper|global-discussions-moderator|wiki-representative|wiki-representative');		var checkEligibleUser = re.test(userGroups);		//checkEligibleUser ? console.log("User has one or more user groups to use the tools.") : console.info("User does not a user group to use the tools.");		if (window.BlockReport)			return;		window.BlockReport = true;		console.log("Good");		var contributionsUserTools = document.createElement("div");		contributionsUserTools.classList.add("mw-contributions-user-tools");		contributionsUserTools.style.marginTop = "0.25em"; // setting top-margin for contributionsUserTools contributionsUserTools.style.marginBottom = "0.25em"; // setting bottom-margin for contributionsUserTools contributionsUserTools.style.paddingTop = "0.25em"; // setting padding-top for contributionsUserTools contributionsUserTools.style.paddingLeft = "0.25em"; // setting padding-left for contributionsUserTools contributionsUserTools.style.paddingRight = "0.25em"; // setting padding-right for contributionsUserTools contributionsUserTools.style.paddingBottom = "0.25em"; // setting padding-bottom for contributionsUserTools var forUserlink = document.createElement("span"); forUserlink.innerHTML = "For " + "" + user + " "; var changeslistLinks = document.createElement("span"); changeslistLinks.classList.add("mw-changeslist-links"); api.get({			action: 'query',			meta: 'siteinfo'		}).then(function(d) {			data = d.query.general;			// Ensuring that all necessary information from API has been loaded before proceeding.			var interval = setInterval(function { if ((data["server"] !== undefined) && (data["servername"] !== undefined) && (data["scriptpath"] !== undefined)&& (data["sitename"] !== undefined) && (data["lang"] !== undefined)) { clearInterval(interval); }			}, 1000);			sitename = data["sitename"]; // e.g., "Community Central"			lang = data["lang"];			domain = data["server"] + data["scriptpath"]; // e.g., https://community.fandom.com + /es			rootdomain = data["servername"]; // e.g., community			var rootDomainBreakdown = rootdomain.split(".");			subdomain = rootDomainBreakdown[0];			mw.hook('dev.enablewallext').add(function(wgMessageWallsExist) { wgMessageWallsExist.then(function {					// when Message Wall exists					if (checkEligibleUser === true) {						//"For " + "" + user + "  " +						changeslistLinks.innerHTML = " Message Wall " +						" block " +						" block log " +						" uploads " +						" logs " +						" deleted user contributions " +						" user rights management</a> ";					}					else {						changeslistLinks.innerHTML = "Message Wall</a> " + " block log</a> " + " uploads</a> " + " logs</a> "; }					//talk block log uploads logs },				function { if (checkEligibleUser === true) { // when Message Wall does not exists changeslistLinks.innerHTML = "talk page</a>" + "block</a>" + "block log</a>" + "uploads</a>" + "logs</a>" + "deleted user contributions</a>" + "user rights management</a>" + "user rights management</a>)";					}					else {						changeslistLinks.innerHTML = "talk page</a> " +						" block log</a> " +						" uploads</a> " +						" <a href=\"" + domain + "/wiki/Specialog/" + user + "\">logs</a> ";					}				}); });			contributionsUserTools.appendChild(forUserlink);			contributionsUserTools.appendChild(changeslistLinks);			console.log("profileUserId: " + mw.config.get('profileUserId'));			console.log("User Groups for " + config.wgUserName + ": " + config.wgUserGroups);		}); var interval = setInterval(function {			if ($('.ns-2 #userProfileApp').length) {				clearInterval(interval);				$(".ns-2 #userProfileApp").eq(0).after(contributionsUserTools); // prepending Box to ".ns-2 #content"			}		}, 1000); importArticles({			type: 'script',			articles: [				'u:dev:MediaWiki:WgMessageWallsExist.js'			]		}); }	main; });