Skip to content

Instantly share code, notes, and snippets.

@themasch
Created April 28, 2011 22:49
Show Gist options
  • Save themasch/947513 to your computer and use it in GitHub Desktop.
Save themasch/947513 to your computer and use it in GitHub Desktop.
simple quick & dirty userscript for fast planet switch
// ==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 = '&lt&lt;';
prefix.value = currentIndex - 1;
}
var suffix = document.createElement('span');
if(currentIndex < optionElements.length-1) {
suffix.innerHTML = '&gt;&gt;';
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