Difference between revisions of "MediaWiki:Common.js"

From The iPhone Wiki
Jump to: navigation, search
(updated to work)
m (negated if logic)
Line 9: Line 9:
 
function fixTalkArchiveToc() {
 
function fixTalkArchiveToc() {
 
// Is there a "This is an Archive Page" header block?
 
// Is there a "This is an Archive Page" header block?
if ($("[id=archive-page-notice]").length != 0) {
+
if ($("[id=archive-page-notice]").length == 0)
  +
return;
// Is there a TOC? If so, get the list
 
  +
var toc = $("[id=toc]>ul>li");
 
  +
// Is there a TOC?
if (toc.length != 0) {
 
  +
var toc = $("[id=toc]>ul>li");
// Remove "This is an Archive Page" entry
 
+
return;
  +
// Decrement the outermost section number for each TOC entry
 
  +
// Remove "This is an Archive Page" entry
var sec = $("[class=tocnumber]");
 
  +
toc[0].remove();
var len = sec.length;
 
  +
var arr;
 
  +
// Decrement the outermost section number for each TOC entry
for (var i = 0; i < len; i++) {
 
  +
var sec = $("[class=tocnumber]");
arr = sec[i].innerText.split(".");
 
  +
var arr;
sec[i].innerText = arr.join(".");
 
}
+
for (var i = 0; i < len; i++) {
  +
arr = sec[i].innerText.split(".");
}
 
toc[0].remove();
+
if (toc.length == 0)
arr[0]--;
+
var len = sec.length;
  +
arr[0]--;
  +
sec[i].innerText = arr.join(".");
 
}
 
}
 
}
 
}
   
 
// Removes the "/20##" part of the "Page" link on talk archives
 
// Removes the "/20##" part of the "Page" link on talk archives
  +
// TODO: Work on [[The iPhone Wiki:Community Portal]]'s archives
 
function fixTalkArchiveNSLinks() {
 
function fixTalkArchiveNSLinks() {
  +
// Are we an archive?
var match = $("#firstHeading")[0].innerText.match(/\/20[0-9]{2}$/);
 
if (match != null && match.length != 0) {
+
if ($("#firstHeading")[0].innerText.match(/\/20[0-9]{2}$/) == null)
  +
return;
var ns = $("#p-namespaces li[class!=selected] a");
 
  +
if (ns != null && ns.length != 0) {
 
  +
var ns = $("#p-namespaces li[class!=selected] a");
// Vector skin
 
  +
if (ns != null && ns.length != 0) {
// TODO: Change link color back to blue
 
  +
// Vector skin
ns[0].href = ns[0].href.replace(
 
  +
// TODO: Change link color back to blue
/w[\/\\]index.php\?title=(.*?)(\/20[0-9]{2}).*$/,
 
  +
/w[\/\\]index.php\?title=(.*?)(\/20[0-9]{2}).*$/,
return;
 
}
+
"wiki/$1");
  +
return;
ns = $("div[class=pBody] li[class=new]");
 
  +
}
if (ns != null && ns.length != 0) {
 
  +
// Modern skin
 
  +
ns = $("div[class=pBody] li[class=new]");
ns[0].className = ns[0].className.replace("new", "");
 
  +
// Modern skin
ns[0].href = ns[0].href.replace(
 
  +
ns[0].className = ns[0].className.replace("new", "");
/w[\/\\]index.php\?title=(.*?)(\/20[0-9]{2}).*$/,
 
"wiki/$1");
+
ns = ns.find("a");
return;
+
ns[0].href = ns[0].href.replace(
  +
/w[\/\\]index.php\?title=(.*?)(\/20[0-9]{2}).*$/,
}
 
"wiki/$1");
+
ns[0].href = ns[0].href.replace(
ns = ns.find("a");
+
if (ns != null && ns.length != 0) {
  +
"wiki/$1");
  +
return;
 
}
 
}
 
}
 
}
   
//fixTalkArchiveToc();
+
fixTalkArchiveToc();
 
fixTalkArchiveNSLinks();
 
fixTalkArchiveNSLinks();

Revision as of 00:46, 22 November 2014

/**
 * 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)
        return;
    
    // Is there a TOC?
    var toc = $("[id=toc]>ul>li");
    if (toc.length == 0)
        return;
    
    // 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
// TODO: Work on [[The iPhone Wiki:Community Portal]]'s archives
function fixTalkArchiveNSLinks() {
    // Are we an archive?
    if ($("#firstHeading")[0].innerText.match(/\/20[0-9]{2}$/) == null)
        return;
    
    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();