Difference between revisions of "MediaWiki:Common.js"

From The iPhone Wiki
Jump to: navigation, search
m (whoops)
(Filesystem is a tricky one)
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
/**
// @name fixTalkArchiveToc
 
  +
* The iPhone Wiki MediaWiki:Common.js
// @version 1.0
 
  +
* - JavaScript to fix common issues on The iPhone Wiki
// @description Removes the "1 This is an Archive Page" element from the TOC on Talk Archives
 
// @copyright (c) 2013, Cole Johnson <coleharrisjohnson@gmail.com>
+
* Copyright (c) 2013-2017 Cole Johnson <coleharrisjohnson@gmail.com>
  +
* Licensed under CC-BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0/>
function fixTalkArchiveToc() {
 
  +
**/
// Is there a "This is an Archive Page" header block?
 
  +
if ($("table[id=archive-page-notice]").length != 0) {
 
  +
// Removes the "/20##" part of the "Page" link on talk archives
var toc = $("table[id=toc]"); // Is there a TOC?
 
  +
function fixTalkArchiveNSLinks() {
if (toc.length != 0) {
 
  +
// Are we an archive?
// relocate to the children of the TOC table
 
  +
// Would work by checking $(".archive-page-notice").length
toc = toc[0].children;
 
  +
var page = $(".firstHeading")[0].innerHTML;
// MediaWiki is consistent, so don't check length first
 
  +
if (page.trim().match(/\/20[0-9]{2}$/) == null)
if (toc[0].localName == "tbody") {
 
  +
return;
toc = toc[0].children; // skip the tbody tag
 
  +
}
 
  +
var ns = $("#p-namespaces .new");
// Nav to the "ul";
 
  +
if (ns.length == 0) {
toc = toc[0].children[0].children[1].children; // "ul" -> "{li}"
 
  +
console.log("Can't find namespace selector link.");
 
  +
return;
// remove "This is an Archive Page" entry
 
toc[0].remove();
 
 
// Cleanup
 
fixTocSectionNums();
 
}
 
 
}
 
}
  +
  +
ns[0].className = ns[0].className.replace("new", "");
  +
ns = ns.find("a")[0];
  +
ns.href = ns.href.replace(
  +
/w[\/\\]index.php\?title=(.*?)(\/20[0-9]{2}).*$/,
  +
"wiki/$1");
 
}
 
}
   
  +
fixTalkArchiveNSLinks();
// @name fixTocSectionNums
 
// @version 1.0
 
// @description Decrements the section number of each TOC entry
 
// @copyright (c) 2013, Cole Johnson <coleharrisjohnson@gmail.com>
 
function fixTocSectionNums() {
 
var sec = $("span[class=tocnumber]");
 
var len = sec.length;
 
var split;
 
for (var i = 0; i < len; i++) {
 
split = sec[i].innerText.split(".");
 
split[0]--;
 
sec[i].innerText = split.join(".");
 
}
 
}
 
   
  +
// The Apple Wiki migration sitenotice link
fixTalkArchiveToc();
 
  +
(function() {
  +
var url = location.href
  +
.replace(location.origin, "https://theapplewiki.com")
  +
.replace("https://theapplewiki.com/w/", "https://theapplewiki.com/");
  +
var pageName = mw.config.get("wgPageName");
  +
var categories = mw.config.get("wgCategories");
  +
if (categories.indexOf("Filesystem") != -1) {
  +
url = url.replace(/(\/wiki\/|title=)\//, "$1Filesystem:/");
  +
} else if (categories.indexOf("All Key Pages") != -1) {
  +
url = url.replace(pageName, "Keys:" + pageName);
  +
}
  +
$("#siteNotice a[href='https://theapplewiki.com/']")
  +
.attr("href", url);
  +
})();

Latest revision as of 00:37, 6 October 2023

/**
 * The iPhone Wiki MediaWiki:Common.js
 *   - JavaScript to fix common issues on The iPhone Wiki
 * Copyright (c) 2013-2017 Cole Johnson <coleharrisjohnson@gmail.com>
 * Licensed under CC-BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0/>
 **/

// Removes the "/20##" part of the "Page" link on talk archives
function fixTalkArchiveNSLinks() {
    // Are we an archive?
    // Would work by checking $(".archive-page-notice").length
    var page = $(".firstHeading")[0].innerHTML;
    if (page.trim().match(/\/20[0-9]{2}$/) == null)
        return;
    
    var ns = $("#p-namespaces .new");
    if (ns.length == 0) {
        console.log("Can't find namespace selector link.");
        return;
    }
    
    ns[0].className = ns[0].className.replace("new", "");
    ns = ns.find("a")[0];
    ns.href = ns.href.replace(
        /w[\/\\]index.php\?title=(.*?)(\/20[0-9]{2}).*$/,
        "wiki/$1");
}

fixTalkArchiveNSLinks();

// The Apple Wiki migration sitenotice link
(function() {
    var url = location.href
        .replace(location.origin, "https://theapplewiki.com")
        .replace("https://theapplewiki.com/w/", "https://theapplewiki.com/");
    var pageName = mw.config.get("wgPageName");
    var categories = mw.config.get("wgCategories");
    if (categories.indexOf("Filesystem") != -1) {
        url = url.replace(/(\/wiki\/|title=)\//, "$1Filesystem:/");
    } else if (categories.indexOf("All Key Pages") != -1) {
        url = url.replace(pageName, "Keys:" + pageName);
    }
    $("#siteNotice a[href='https://theapplewiki.com/']")
        .attr("href", url);
})();