The iPhone Wiki is no longer updated. Visit this article on The Apple Wiki for current information. |
Difference between revisions of "MediaWiki:Common.js"
m |
m |
||
Line 2: | Line 2: | ||
* The iPhone Wiki MediaWiki:Common.js |
* The iPhone Wiki MediaWiki:Common.js |
||
* - JavaScript to fix common issues on The iPhone Wiki |
* - JavaScript to fix common issues on The iPhone Wiki |
||
− | * Copyright (c) 2013-2014 Cole Johnson <coleharrisjohnson@gmail.com> |
+ | * Copyright (c) 2013-2014, 2016 Cole Johnson <coleharrisjohnson@gmail.com> |
* Licensed under CC-BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0/> |
* Licensed under CC-BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0/> |
||
**/ |
**/ |
||
Line 35: | Line 35: | ||
function fixTalkArchiveNSLinks() { |
function fixTalkArchiveNSLinks() { |
||
// Are we an archive? |
// Are we an archive? |
||
− | var page = $(" |
+ | var page = $(".firstHeading")[0].innerText; |
if (page.match(/\/20[0-9]{2}$/) == null) |
if (page.match(/\/20[0-9]{2}$/) == null) |
||
return; |
return; |
Revision as of 19:36, 27 April 2016
/**
* The iPhone Wiki MediaWiki:Common.js
* - JavaScript to fix common issues on The iPhone Wiki
* Copyright (c) 2013-2014, 2016 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?
var page = $(".firstHeading")[0].innerText;
if (page.match(/\/20[0-9]{2}$/) == null)
return;
if (page.indexOf("The iPhone Wiki:Community Portal") != -1)
return;
var ns = $("[class=new]");
if (ns.length == 0) {
console.log("Can't find namespace selector thingy!");
return;
}
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");
}
fixTalkArchiveToc();
fixTalkArchiveNSLinks();