MediaWiki:Common.js

From The iPhone Wiki
Revision as of 00:37, 22 November 2014 by 5urd (talk | contribs) (updated to work)
Jump to: navigation, search

Note: After saving, 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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/**
 * The iPhone Wiki MediaWiki:Common.js
 *   - JavaScript to fix common issues on The iPhone Wiki
 * Copyright (c) 2013-2014 Cole Johnson <coleharrisjohnson@gmail.com>
 * Licensed under CC-BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0/>
 **/

// Removes the "1 This is an Archive Page" element from the TOC on Talk Archives
function fixTalkArchiveToc() {
    // Is there a "This is an Archive Page" header block?
    if ($("[id=archive-page-notice]").length != 0) {
        // Is there a TOC? If so, get the list
        var toc = $("[id=toc]>ul>li");
        if (toc.length != 0) {
            // Remove "This is an Archive Page" entry
            toc[0].remove();
            
            // Decrement the outermost section number for each TOC entry
            var sec = $("[class=tocnumber]");
            var len = sec.length;
            var arr;
            for (var i = 0; i < len; i++) {
                arr = sec[i].innerText.split(".");
                arr[0]--;
                sec[i].innerText = arr.join(".");
            }
        }
    }
}

// Removes the "/20##" part of the "Page" link on talk archives
function fixTalkArchiveNSLinks() {
    var match = $("#firstHeading")[0].innerText.match(/\/20[0-9]{2}$/);
    if (match != null && match.length != 0) {
        var ns = $("#p-namespaces li[class!=selected] a");
        if (ns != null && ns.length != 0) {
            // Vector skin
            // TODO: Change link color back to blue
            ns[0].href = ns[0].href.replace(
                /w[\/\\]index.php\?title=(.*?)(\/20[0-9]{2}).*$/,
                "wiki/$1");
            return;
        }
        ns = $("div[class=pBody] li[class=new]");
        if (ns != null && ns.length != 0) {
            // Modern skin
            ns[0].className = ns[0].className.replace("new", "");
            ns = ns.find("a");
            ns[0].href = ns[0].href.replace(
                /w[\/\\]index.php\?title=(.*?)(\/20[0-9]{2}).*$/,
                "wiki/$1");
            return;
        }
    }
}

//fixTalkArchiveToc();
fixTalkArchiveNSLinks();