MediaWiki:Common.js

From The iPhone Wiki
Revision as of 04:45, 16 August 2013 by 5urd (talk | contribs) (javascript to remove the "This is an Archive Page" heading from the TOC)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.
// @name        fixTalkArchiveToc
// @version     1.0
// @description Removes the "1 This is an Archive Page" element from the TOC on Talk Archives
// @copyright   (c) 2013, Cole Johnson <coleharrisjohnson@gmail.com>
function fixTalkArchiveToc() {
	// Is there a "This is an Archive Page" header block?
    if ($("table[id=archive-page-notice]").length != 0) {
        var toc = $("table[id=toc]"); // Is there a TOC?
		if (toc.length != 0) {
			// relocate to the children of the TOC table
			toc = toc[0].children;
			// MediaWiki is consistent, so don't check length first
			if (toc[0].localName == "tbody") {
				toc = toc[0].children; // skip the tbody tag
			}
			// Nav to the "ul"; 
			toc = toc[0].children[0].children[1].children; // "ul" -> "{li}"
			
			// remove "This is an Archive Page" entry
			toc[0].remove();
			
			// Cleanup
			fixTocSectionNums();
		}
    }
}

// @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].split(".");
		split[0]--;
		sec[i] = split.join(".");
	}
}

fixTalkArchiveToc();