Jump to content

User:Terasail/HeaderIcons.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Terasail (talk | contribs) at 18:56, 10 March 2023 (FINALLY FIX ERROR???). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*	//<nowiki>
	HeaderIcons.js
	Created by: Terasail
*/
//jshint esversion: 6
if (mw.config.get("skin") === "vector-2022") {
	//Static header
	let headerIconList = $("#p-vector-user-menu-overflow .vector-menu-content-list")[0];
	let headerIcons = headerIconList.children;
	for (let i = 0; i < headerIcons.length; i++) {//Remove icons after notification buttons
		if (headerIcons[i].id !== "pt-userpage-2" && headerIcons[i].id.slice(3,16) !== "notifications") {
			headerIcons[i].remove();
		}
	}
	let userLinks = $("#p-personal .mw-list-item");
	for (let i = 1; i < userLinks.length; i++) {
		
		if(getComputedStyle(userLinks[i].children[0].children[0], '::before')['backgroundImage'] !== 'none') {
			let tempElem = userLinks[i].cloneNode(true);
			let elemIcon = tempElem.children[0].children[0];
			tempElem.id = userLinks[i].id + '-2';
			tempElem.className = 'user-links-collapsible-item mw-list-item';
			tempElem.children[0].className = 'mw-ui-button mw-ui-quiet mw-ui-icon-element ' + elemIcon.className;
			elemIcon.remove();
			$(headerIconList).append(tempElem);
		}
	}

	//Sticky header
	if ($('#vector-sticky-header').length !== 0) {//Check for sticky header
		$('<div id="sticky-user-menu-overflow" class="vector-sticky-header-icons"></div>').insertBefore(".vector-sticky-header-icon-end");
		let stickyIconList = $("#sticky-user-menu-overflow");
		let userLinks = $("#p-personal-sticky-header .mw-list-item");
		for (let i = 0; i < userLinks.length; i++) {
			let linkChildren = userLinks[i].children[0].children;
			if(linkChildren.length > 0 && getComputedStyle(linkChildren[0], '::before')['backgroundImage'] !== 'none') {
				let tempElem = userLinks[i].children[0].cloneNode(true);
				let elemIcon = tempElem.children[0];
				tempElem.id = userLinks[i].id + '-2';
				tempElem.className = 'mw-ui-button mw-ui-quiet mw-ui-icon-element ' + elemIcon.className;
				elemIcon.remove();
				$(stickyIconList).append(tempElem);
			}
		}
	}
}
//</nowiki>[[Category:Wikipedia scripts]]