Jump to content

User:Terasail/HeaderIcons.js

From Wikipedia, the free encyclopedia
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
*/

if (mw.config.get("skin") === "vector-2022") {
	let userLinks = $("#p-personal .mw-list-item");
	//Static header
	$($('#p-vector-user-menu-notifications')).after('<div id="p-vector-header-icons-js" class="vector-menu mw-portlet"><div class="vector-menu-content"><ul class="vector-menu-content-list"></ul></div></div>');
	let headerIcons = $("#p-vector-user-menu-overflow .vector-menu-content-list")[0].children;
	for (let i = 0; i < headerIcons.length; i++) {//Remove icons after notification buttons
		if (headerIcons[i].id !== "pt-userpage-2" && headerIcons[i].id.indexOf("-2") >= 0) {
			headerIcons[i].remove();
		}
	}
	for (let i = 1; i < userLinks.length; i++) {
		let tempElem = userLinks[i].cloneNode(true);
		tempElem.id = userLinks[i].id + '-2';
		tempElem.children[0].className = 'cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only';
		$($('#p-vector-header-icons-js ul')[0]).append(tempElem);
		let iconSpan = $('#' + tempElem.id + ' span')[0];
		if (window.getComputedStyle(iconSpan).mask.indexOf("data:image") != -1) {//Reapply image mask to icon as it doesn't clone correctly for non-base icons
			iconSpan.style.mask = window.getComputedStyle($('#' + userLinks[i].id + ' span')[0]).mask;
		}
	}

	//Sticky header
	if ($('#vector-sticky-header').length !== 0) {//Check for sticky header
		$($('#vector-sticky-header .vector-sticky-header-icons')).after('<div id="vector-sticky-header-icons-js"><div class="vector-sticky-header-icons" style="margin-left:5px;"></div></div>');
		for (let i = 1; i < userLinks.length; i++) {
			let tempElem = userLinks[i].children[0].cloneNode(true);
			tempElem.id = userLinks[i].id + '-sticky-header-2';
			tempElem.className = 'cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only';
			$($('#vector-sticky-header-icons-js div')[0]).append(tempElem);
			let iconSpan = tempElem.children[0];
			if (window.getComputedStyle(iconSpan).mask.indexOf("data:image") != -1) {//Reapply image mask to icon as it doesn't clone correctly for non-base icons
				iconSpan.style.mask = window.getComputedStyle($('#' + userLinks[i].id + ' span')[0]).mask;
			}
		}
	}
}
//</nowiki>[[Category:Wikipedia scripts]]