MediaWiki:Common.js: Difference between revisions

Move Gadvia score calculator to a gadget
No edit summary
Tag: Manual revert
 
(11 intermediate revisions by the same user not shown)
Line 16: Line 16:
findAndExecute(".rgwiki-main-negative-tabindex", (element) => {
findAndExecute(".rgwiki-main-negative-tabindex", (element) => {
     element.tabIndex = -1;
     element.tabIndex = -1;
});
/* Links without href/links to "javascript:void(0)" are not allowed by MediaWiki, this is a workaround */
/* Use Template:EmptyLink to activate this piece of code. */
findAndExecute(".rgwiki-main-emptylink", (span) => {
  const a = span.querySelector("a");
  for (const className of span.classList) {
    if (className !== "rgwiki-main-emptylink") {
      a.classList.add(className);
    }
  }
  a.href = "javascript:void(0)";
  const parent = span.parentNode;
  parent.replaceChild(a, span);
});
});


Line 26: Line 40:
});
});


/* OS tabs */
findAndExecute(".tabber.rgwiki-main-os-tabber", (tabber) => {
    const osString = (window.navigator.oscpu || window.navigator.platform || window.navigator.userAgent).toLowerCase();
    let userOs = null;
    if (osString.includes("linux")) userOs = "linux";
    if (osString.includes("mac")) userOs = "mac";
    if (osString.includes("win")) userOs = "win";


/* Rizline clickable bio chips */
    const oldAnchor = window.location.hash;
findAndExecute(".rgwiki-rizline-bio-chip-focusable", (chip) => {
    tabber.querySelectorAll(".tabber__header > .tabber__tabs > a.tabber__tab").forEach(tab => {
    chip.addEventListener("click", () => {
         const tabName = tab.textContent.toLowerCase();
         const isLeft = chip.classList.contains("rgwiki-rizline-bio-chip-left");
         if (userOs === "linux" && tabName.includes("linux")) tab.click();
         const isRight = chip.classList.contains("rgwiki-rizline-bio-chip-right");
         if (userOs === "mac" && tabName.includes("macos")) tab.click();
         if (isLeft) {
         if (userOs === "win" && tabName.includes("windows")) tab.click();
            document.querySelectorAll(".rgwiki-rizline-bio-chip-focusable.rgwiki-rizline-bio-chip-left.rgwiki-rizline-bio-chip-clicked").forEach((x) => {
                x.classList.remove("rgwiki-rizline-bio-chip-clicked");
            });
        }
         if (isRight) {
            document.querySelectorAll(".rgwiki-rizline-bio-chip-focusable.rgwiki-rizline-bio-chip-right.rgwiki-rizline-bio-chip-clicked").forEach((x) => {
                x.classList.remove("rgwiki-rizline-bio-chip-clicked");
            });
        }
        chip.classList.add("rgwiki-rizline-bio-chip-clicked");
     });
     });
    setTimeout(() => {
        window.location.hash = oldAnchor;
    }, 100);
});
});