User:Terasail/HeaderIcons.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Terasail/HeaderIcons. |
/* //<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]]