User:Williek11/global.js

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

mw.hook("dev.modal").add(function(modal){	/* new modal.Modal({ id: "comments", title: "Comments", size: "large", }); */	new modal.Modal({ id: "talk", title: "Talk Page", size: "large", content: "Loading...", }).create; });

// navbar adjustments

mw.hook("wikipage.content").add(function{	const mainContainer = $(".main-container")[0];	const resizableContainer = $(".resizable-container")[0];	const communityHeader = $(".community-header-wrapper")[0];	const navigationHeader = document.createElement("div");	const sideContainer = document.createElement("div");	const dualContainer = document.createElement("div");	const pageName = mw.config.get("wgPageName");	const lang = mw.config.get("wgContentLanguage");	navigationHeader.className = "navigation-header";	sideContainer.className = "side-container";	dualContainer.className = "dual-container";	navigationHeader.innerHTML = ' ';	dualContainer.appendChild(sideContainer);	dualContainer.appendChild(resizableContainer);	mainContainer.insertBefore(navigationHeader, $(".global-footer")[0]);	mainContainer.insertBefore(dualContainer, $(".global-footer")[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 createTab (obj) { const aNode = document.createElement("a"); const node = document.createElement("div"); node.className = "community-header-tab"; node.innerText = obj.text; if (obj.event) { node.addEventListener("click", obj.event); } if (obj.link) { aNode.href = obj.link; aNode.appendChild(node); return aNode; } return node; }	function linkify (text) { return lang === "en" ? "/wiki/"+text : "/"+lang+"/wiki/"+text; }	addNodeToSide({title: "Profile", items: [		{link: linkify("User:Williek11"), html: "Own Profile"},		{link: linkify("Message Wall:Williek11"), html: "Message Wall"},		{link: linkify("User blog:Williek11"), html: "User Blog"},		{link: linkify("Special:Contributions/Williek11"), html: "Contributions"},		{link: linkify("Special:UserProfileActivity/Williek11"), html: "User Activity"},		{link: linkify("User:Williek11/Sandbox"), html: "Sandbox"},	]}); addNodeToSide({title: "Site tools", items: [		{link: linkify("Main Page"), html: "Main Page"},		{link: linkify("Special:RecentChanges"), html: "Recent changes"},		{link: linkify("Special:SocialActivity"), html: "Social Activity"},		{link: linkify("Special:NewFiles"), html: "New files"},		{link: linkify("Category:Maintenance"), html: "Maintenance"},		{link: linkify("Category:Templates"), html: "Templates"},		{link: linkify("Special:SpecialPages"), html: "Special pages"},		{link: linkify("Special:Preferences"), html: "Change preferences"},	]}); addNodeToSide({title: "Page tools", items: [		{link: linkify("Special:WhatLinksHere/"+pageName), html: "What links here"},		{link: linkify(pageName+"?action=info"), html: "Information"},	]}); $.ajax({		url: "/MediaWiki:Mainpage?action=raw",		type: "GET",		success: function (data) {			$("[href='"+linkify("Main Page")+"']")[0].href = linkify(data);		}	}); const arrayOfTabs = [ createTab({			text: "Talk Page",			event: function {				const talkModal = window.dev.modal.modals.talk;				const titleObject = new mw.Title(pageName);				if (titleObject === null) {					talkModal.setContent("Title Object is null.");					talkModal.show;					return;				}				const talkPage = titleObject.getTalkPage.getPrefixedText;				if (window.dev.talkPageLoaded) {talkModal.show; return}				if (talkPage === undefined) {					talkModal.setContent("There is no associated talk page for this one.");				} else {					$.ajax({ url: "/"+talkPage+"?action=raw", type: 'GET', success: function(data) { new mw.Api.get({				           	action: "parse",				            	preview: true,				            	text: data,				            	contentmodel: "wikitext",				            }).then(function(parsedData){				            	talkModal.setContent(parsedData.parse.text["*"]);				            	talkModal.setSize("large");				            }, function(error){				            	talkModal.setContent("414: URI too long");				            }); },				       error: function{ talkModal.setContent("The talk page does not exist."); },				   });				}				talkModal.show;				window.dev.talkPageLoaded = true;				// const title = new mw.Title(mw.config.get( 'wgPageName' ));			},		}), createTab({			text: "Edit",			link: linkify(pageName+"?action=edit"),		}), createTab({			text: "History",			link: linkify(pageName+"?action=history"),		}), ];	console.log(communityHeader); communityHeader.replaceChildren; arrayOfTabs.forEach(function(node){communityHeader.appendChild(node)}); }, 500);

mw.loader.using('mediawiki.api').then(function{	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); }			});		});	}); */

});