User:Williek11/global.js

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:Rollback/code.js',        'u:dev:MediaWiki:AnchoredRollback/code.js',        'u:dev:MediaWiki:UsefulDropdown/code.js',		'u:dev:MediaWiki:RemoveTracking.js',		'u:dev:MediaWiki:MassProtect/code.js',		'u:dev:MediaWiki:AjaxBatchDelete.js',		'u:dev:MediaWiki:MassRollback.js',        'u:dev:MediaWiki:DisplayTimer/code.js',    ] });

if (location.search.includes("action=edit")) { window.onbeforeunload = function{ return '' }; }

// navbar adjustments

const callWhenNodes = function{ const mainContainer = $(".main-container")[0]; const resizableContainer = $(".resizable-container")[0]; const tabs = $(".fandom-community-header>.fandom-community-header__local-navigation>.wds-tabs")[0]; if (mainContainer === undefined || resizableContainer === undefined || tabs === undefined) {setTimeout(callWhenNodes, 60); return;} const sideContainer = document.createElement("div"); const dualContainer = document.createElement("div"); const profileContainer = document.createElement("div"); const profilePicture = document.createElement("img"); const profileOverlay = document.createElement("div"); const pageName = mw.config.get("wgPageName"); sideContainer.className = "side-container"; dualContainer.className = "dual-container"; profileContainer.id = "profile-container"; profileOverlay.id = "profile-overlay"; dualContainer.appendChild(sideContainer); dualContainer.appendChild(resizableContainer); mainContainer.insertBefore(dualContainer, $(".global-footer")[0]); profilePicture.src = "https://static.wikia.nocookie.net/ec060e43-6e31-4456-9fae-0ded849d23b9/thumbnail/width/150/height/150"; profileContainer.appendChild(profilePicture); profileContainer.appendChild(profileOverlay); sideContainer.appendChild(profileContainer); profileContainer.addEventListener("mouseenter", function { profileOverlay.style.opacity = "1"; }); profileContainer.addEventListener("mouseleave", function { profileOverlay.style.opacity = "0"; }); function addCollapse (container, toCollapse) { const collapseNode = document.createElement("span"); const title = container.getElementsByClassName("side_items-title")[0]; const ul = container.getElementsByClassName("side_items-list")[0]; collapseNode.classList.add("side_items-title_collapse"); Object.freeze(ul); Object.freeze(container); var isCollapsed = false; function setHeight (h) {ul.style.height = h;} if (toCollapse === true) { collapseNode.textContent = "▼"; setHeight(0); isCollapsed = true; } else { collapseNode.textContent = "▲"; }		title.appendChild(collapseNode); collapseNode.addEventListener("click", function {			if (isCollapsed === false) {				collapseNode.textContent = "▼";				setHeight(0);				isCollapsed = true;			} else {				collapseNode.textContent = "▲";				setHeight("");				isCollapsed = false;			}		}); }	function addNodeToSide (obj, startCollapsed) { const node = document.createElement("div"); const titleNode = document.createElement("div"); const ulNode = document.createElement("ul"); node.className = "side_item"; ulNode.className = "side_items-list"; titleNode.className = "side_items-title"; titleNode.innerHTML = obj.title; node.appendChild(titleNode); node.appendChild(ulNode); if (startCollapsed === true) { addCollapse(node, true); } else { addCollapse(node); }		for (var i = 0, l = obj.items.length; i < l; i++) { const currentItem = obj.items[i]; const itemLink = currentItem.link; const itemHTML = currentItem.html; const itemNode = document.createElement("li"); const linkNode = document.createElement("a"); if (currentItem.children !== undefined) { console.log(currentItem); }			linkNode.href = itemLink; linkNode.innerHTML = itemHTML; itemNode.appendChild(linkNode); ulNode.appendChild(itemNode); }		sideContainer.appendChild(node); }	function objectifyNestedTabs (ul) { const arrayOfTabs = []; for (var i = 0, children = ul.children, l = children.length; i < l; i++) { const currentLi = children[i]; const tabObject = {}; // !currentLi.classList.contains("wds-dropdown-level-nested") || if (currentLi.classList.contains("wds-dropdown")) { tabObject.html = currentLi.firstElementChild.firstElementChild.lastElementChild.textContent; tabObject.link = currentLi.firstElementChild.firstElementChild.href; } else { tabObject.html = currentLi.firstElementChild.textContent.trim; tabObject.link = currentLi.firstElementChild.href; }			if (currentLi.lastElementChild.firstElementChild.classList.contains("wds-list")) { tabObject.children = objectifyNestedTabs(currentLi.lastElementChild.firstElementChild); }			arrayOfTabs.push(tabObject); }		return arrayOfTabs; }	for (var i = 0, tabItemsObj = objectifyNestedTabs(tabs), keys = Object.keys(tabItemsObj), l = keys.length; i < l; i++) { const obj = {}; obj.title = tabItemsObj[keys[i]].html; obj.items = tabItemsObj[keys[i]].children; addNodeToSide(obj, true); }	addNodeToSide({title: "Site tools", items: [		{link: "/wiki/Special:RecentChanges", html: "Recent changes"},		{link: "/wiki/Special:NewFiles", html: "New files"},		{link: "/wiki/Category:Maintenance", html: "Maintenance"},		{link: "/wiki/Category:Templates", html: "Templates"},		{link: "/wiki/Special:SpecialPages", html: "Special pages"},		{link: "/wiki/Special:Preferences", html: "Change preferences"},	]}); addNodeToSide({title: "Page tools", items: [		{link: "/wiki/Special:WhatLinksHere/"+pageName, html: "What links here"},		{link: "/wiki/"+pageName+"?action=info", html: "Information"},	]}); };

const callWhenApi = function{ if (mw.Api === undefined || $(".main-container")[0] === undefined) {setTimeout(callWhenApi, 60); return} new mw.Api.get({		action: 'query',		format: 'json',		list: 'backlinks',		bltitle: mw.config.get("wgPageName"),	}).done(function(data) {		var arr = [];		var backlinks = data.query.backlinks;		window.whatlinkshere = [];		for (var i = 0, l = backlinks.length; i < l; i++) {			window.whatlinkshere.push(backlinks[i].title);		}		$(".tools")[0].appendChild((function{			var li = document.createElement("li");			li.textContent = "What links here: "+whatlinkshere.length;			li.title = whatlinkshere.join(", ");			return li;		}));	}); /* THEME SWITCH $(".wiki-tools__theme-switch")[1].addEventListener("click", function {		new mw.Api.get({action:"query", meta:"tokens"}).done(function(e){ var change; if ($("body")[0].classList.contains("theme-fandomdesktop-dark")) { change = 'theme=light'; } else { change = 'theme=dark'; }			new mw.Api.post({		       action: 'options',		        format: 'json',		        change: change,		        token: e.query.tokens.csrftoken		    }).done(function(e){		    	if (e.options === "success") {		    		location.reload;		    	} else {		    		console.error(e);		    	}		    }); });	}); */

};

const callWhenNode = (function{	const node = $("#my-tools-menu")[0];	if (node === undefined) {setTimeout(callWhenNode, 60);return;}	const li = document.createElement("li");	const a = document.createElement("a");	a.href = location.search === "" ? location + "?useuserjs=0&useusercss=0" : location + "&useuserjs=0&useusercss=0";	a.textContent = "Remove Customization";	li.appendChild(a);	node.appendChild(li); });

callWhenNodes; callWhenApi; callWhenNode;