Skip to content

Instantly share code, notes, and snippets.

@wolph
Last active July 19, 2016 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolph/9115fefa1795dc39c9fd1d58fe5f7e10 to your computer and use it in GitHub Desktop.
Save wolph/9115fefa1795dc39c9fd1d58fe5f7e10 to your computer and use it in GitHub Desktop.
Computer futures usability enhancer
// ==UserScript==
// @name Computer Futures Worksheet Usability Enhancer
// @namespace http://wol.ph/
// @description try to take over the world!
// @author Wolph
// @match https://worksheets.computerfutures.com/index.php?*
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
function sortSelect(selElem) {
var tmpAry = new Array();
if(!selElem || !selElem.options)return;
var options = selElem.options;
for (var i=0;i<options.length;i++) {
var option = options[i];
tmpAry[i] = new Array();
tmpAry[i][0] = option.value;
tmpAry[i][1] = option.text;
tmpAry[i][2] = selElem.selectedIndex == i;
}
tmpAry.sort();
while (selElem.options.length > 0) {
selElem.options[0] = null;
}
for (var i=0;i<tmpAry.length;i++) {
var op = new Option(tmpAry[i][1], tmpAry[i][0]);
selElem.options[i] = op;
if(tmpAry[i][2]){
selElem.selectedIndex = i;
}
}
return;
}
sortSelect(document.getElementById('projectSelector'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment