Last active
September 1, 2017 16:23
-
-
Save sloanlance/601094a4a400ddf9fd519072a63e0218 to your computer and use it in GitHub Desktop.
MediaWiki: Hide pages' tables of contents upon loading.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Begin https://example.org/path/to/wiki/MediaWiki:Common.js */ | |
/* Any JavaScript here will be loaded for all users on every page load. */ | |
/* This file will be included in response to requests like https://example.org/path/to/wiki/index.php?action=raw&smaxage=0&gen=js */ | |
/* Hide the table of contents each time any page is loaded. */ | |
function hideToc() { | |
try { | |
// Detect whether the page's TOC is displayed. | |
if (document.getElementById('toc').getElementsByTagName('ul')[0].style.display != 'none') { | |
// Use MW's toggleToc() to hide TOC, change "hide/show" link text, and set cookie. | |
toggleToc(); | |
} | |
} catch (exception) { | |
// Probably this page doesn't have a TOC. Ignore the exception to prevent console clutter. | |
} | |
} | |
// The enclosed code runs only after the page has been loaded and parsed. | |
window.addEventListener('DOMContentLoaded', function() { | |
hideToc(); | |
}, false); | |
/* End https://example.org/path/to/wiki/MediaWiki:Common.js */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment