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 callWhenMw = function{ if (mw.Api === undefined) {setTimeout(callWhenMw, 60);return} else if ($(".main-container")[0] === undefined) {setTimeout(callWhenMw, 60);return} const doc = document; const upperNav = doc.createElement("div"); const ul = doc.createElement("ul"); upperNav.className = "upper-container"; $(".main-container")[0].appendChild(upperNav); upperNav.appendChild(ul); function addElement (node, id) { const li = doc.createElement("li"); li.id = id; li.appendChild(node); ul.appendChild(li); }	addElement($(".fandom-community-header__top-container")[0].children[2]); addElement($(".global-navigation__bottom")[0].children[1], "user-profile"); addElement($(".notifications")[0], "notifications"); new mw.Api.get({		action: "notifications",		do: "getNotificationsForUser",		page: 0,		itemsPerPage: 50,		unread: 1,	}).done(function(e) {		if (e.meta.unread === 0) {			$($(".notifications__counter")[0]).hide;		} else {			$(".notifications__counter")[0].textContent = e.meta.unread;		}	}); $(".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); });

callWhenMw; callWhenNode;