Skip to content

Instantly share code, notes, and snippets.

@leigero
Created February 7, 2016 07:05
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 leigero/64ebd5cdd9af711786d6 to your computer and use it in GitHub Desktop.
Save leigero/64ebd5cdd9af711786d6 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Wise Grumpy Old King - Auto-Fill
// @namespace http://www.leigero.com
// @version 0.1
// @description Finally, no more pesky drop-down selecting. Tell the king your business and move on with life.
// @author leigero
// @match http://www.neopets.com/medieval/grumpyking.phtml
// @match http://www.neopets.com/medieval/wiseking.phtml
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
// Continue if success && not yet reached desired max round
randomizeResponse();
function randomizeResponse(){
var fields = Array.prototype.slice.call((document).getElementsByTagName('select'));
var length = fields.length;
for(var i = 0; i < length; i++){
var selected = randomOptionFrom(fields[i]);
while(selected.value == "none"){
selected = randomOptionFrom(fields[i]);
}
fields[i].value = selected.value;
}
}
function randomItemFrom(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
function randomOptionFrom(select) {
return randomItemFrom(select.options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment