Created
April 28, 2011 22:49
-
-
Save themasch/947513 to your computer and use it in GitHub Desktop.
simple quick & dirty userscript for fast planet switch
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
// ==UserScript== | |
// @match http://*.stargate-galaxys.com/* | |
// ==/UserScript== | |
var elements = new Array(), | |
currentIndex = 0, | |
selectElement = document.getElementById('planetid'), | |
currentValue = selectElement.value, | |
optionElements = selectElement.getElementsByTagName('option'), | |
formElement = document.getElementById('form'); | |
for(var i=0;i<optionElements.length;i++) { | |
var val = optionElements[i]; | |
if(val.value == currentValue) { | |
currentIndex = i; | |
} | |
}; | |
var prefix = document.createElement('span'); | |
if(currentIndex !== 0) { | |
prefix.innerHTML = '<<'; | |
prefix.value = currentIndex - 1; | |
} | |
var suffix = document.createElement('span'); | |
if(currentIndex < optionElements.length-1) { | |
suffix.innerHTML = '>>'; | |
suffix.value = currentIndex + 1; | |
} | |
function onClick() { | |
var ele = optionElements[this.value]; | |
selectElement.value = ele.value; | |
selectElement.onchange(); | |
} | |
suffix.onclick = onClick; | |
prefix.onclick = onClick; | |
formElement.insertBefore(prefix, selectElement); | |
formElement.insertBefore(suffix, selectElement.nextElementSibling); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment