-
-
Save Repflez/7a68c28252e387f42042 to your computer and use it in GitHub Desktop.
osu!wiki Preferences Fix
This file contains 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
// ==UserScript== | |
// @name Preferences fix | |
// @namespace osu!wiki.preferencesFix | |
// @include https://osu.ppy.sh/wiki/*Special:Preferences* | |
// @version 2 | |
// @grant none | |
// ==/UserScript== | |
/* Fix for Preferences page -- Repflez */ | |
var prefTabLinks = new Array(); | |
var prefContentDivs = new Array(); | |
function initPrefFix() { | |
// Grab the tab links and content divs from the page | |
var prefTabListItems = document.getElementById('preftoc').childNodes; | |
for ( var i = 0; i < prefTabListItems.length; i++ ) { | |
if ( prefTabListItems[i].nodeName == "LI" ) { | |
var prefTabLink = prefGetFirstChildWithTagName( prefTabListItems[i], 'A' ); | |
var id = prefGetHash( prefTabLink.getAttribute('href') ); | |
prefTabLinks[id] = prefTabLink; | |
prefContentDivs[id] = document.getElementById( id ); | |
} | |
} | |
// Assign onclick events to the tab links, and | |
// highlight the first tab | |
var i = 0; | |
for ( var id in prefTabLinks ) { | |
prefTabLinks[id].onclick = prefShowTab; | |
prefTabLinks[id].onfocus = function() { this.blur() }; | |
if ( i == 0 ) prefTabLinks[id].className = 'selected'; | |
i++; | |
} | |
// Hide all content divs except the first | |
var i = 0; | |
for ( var id in prefContentDivs ) { | |
if ( i != 0 ) prefContentDivs[id].style = 'display: none;'; | |
else prefContentDivs[id].style = 'display: block;'; | |
i++; | |
} | |
} | |
function prefShowTab() { | |
var selectedId = prefGetHash( this.getAttribute('href') ); | |
// Highlight the selected tab, and dim all others. | |
// Also show the selected content div, and hide all others. | |
for ( var id in prefContentDivs ) { | |
if ( id == selectedId ) { | |
prefTabLinks[id].parentElement.className = 'selected'; | |
prefContentDivs[id].style.display = 'block'; | |
} else { | |
prefTabLinks[id].parentElement.className = ''; | |
prefContentDivs[id].style.display = 'none'; | |
} | |
} | |
// Stop the browser following the link | |
return false; | |
} | |
function prefGetFirstChildWithTagName( element, tagName ) { | |
for ( var i = 0; i < element.childNodes.length; i++ ) { | |
if ( element.childNodes[i].nodeName == tagName ) return element.childNodes[i]; | |
} | |
} | |
function prefGetHash( url ) { | |
var hashPos = url.lastIndexOf ( '#' ); | |
return url.substring( hashPos + 1 ); | |
} | |
if (wgPageName == 'Special:Preferences') { | |
initPrefFix(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment