User:C.Ezra.M/addPrefixesLink.js

From Bulbapedia, the community-driven Pokémon encyclopedia.
Revision as of 15:42, 2 April 2022 by C.Ezra.M (talk | contribs) (Created page with "/* You can define these variables: nsSpecialName - localized name for the Special namespace specialPrefixIndexName - localized name for "PrefixIndex" title = the hover title...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
⧼bulbapediamonobook-jumptonavigation⧽⧼bulbapediamonobook-jumptosearch⧽

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* You can define these variables:

nsSpecialName - localized name for the Special namespace
specialPrefixIndexName - localized name for "PrefixIndex"
title = the hover title
display = link text
*/

var config = mw.config.values;

if     (config.wgNamespaceNumber != -1) // Exclude special pages
{
    var list = document.querySelector("#p-tb ul");
    var li = document.createElement("li");
    var link = document.createElement("a");

    var href = config.wgArticlePath+"/"+config.wgPageName;
    if (window.nsSpecialName === undefined) {
        window.nsSpecialName = "Special";
    }
    href = href.replace("$1",nsSpecialName.trim()+":$1")
    if (window.specialPrefixIndexName === undefined) {
        window.specialPrefixIndexName = "PrefixIndex";
    }
    href = href.replace("$1",specialPrefixIndexName.trim())
    // Assuming leaving defaults (and wgArticlePath with "/wiki/$1"), the href should be "/wiki/Special:PrefixIndex/<pagename>"
    link.href = href;
    if (window.title === undefined) {
        window.title = "See subpages of this page";
    }
    link.title = title.trim();
    if (window.display === undefined) {
        window.display = "List of subpages";
    }
    link.innerHTML = display.trim();
    li.appendChild(link);
    list.appendChild(li);
}