Skip to content

Instantly share code, notes, and snippets.

@undergroundmonorail
Last active January 12, 2019 19:20
Show Gist options
  • Save undergroundmonorail/96478ce254a7009dd868 to your computer and use it in GitHub Desktop.
Save undergroundmonorail/96478ce254a7009dd868 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Kingly Dailies
// @namespace https://www.reddit.com/u/undergroundmonorail
// @version 0.3
// @description Writes something incredibly wise or hilarious. (Wiseness/hilarity not guaranteed.)
// @author monorail
// @match http://www.neopets.com/medieval/grumpyking.phtml
// @match http://www.neopets.com/medieval/wiseking.phtml
// @grant none
// ==/UserScript==
(function(){
function randomizeBoxes() {
// joke for the avatar
var joke = "What,do,you do if,*Leave blank*,fierce,Peophins,*Leave blank*,has eaten too much,*Leave blank*,tin of olives".split(",");
var boxes = $('select');
for (var i = 0; i < boxes.length; i++)
{
if (/^[qa]p\d+$/.test(boxes[i].id))
{
if (window.location.href.includes("grumpyking") && boxes[i].id[0] == 'q') {
boxes[i].value = joke[i];
// setting the value to *Leave blank* directly causes a visual bug because of some neo javascript
// set the selectedIndex from -1 to 1 to fix it
boxes[i].selectedIndex = Math.abs(boxes[i].selectedIndex);
} else {
boxes[i].selectedIndex = Math.floor(Math.random() * (boxes[i].length - 2)) + 2;
}
}
}
}
var script = document.createElement('script');
script.appendChild(document.createTextNode(randomizeBoxes));
(document.body || document.head || document.documentElement).appendChild(script);
$('input[value="Tell the King your joke!"], input[value="Impress King Hagan with your wisdom!"]').before('<input type="button" value="Choose Random" onClick="randomizeBoxes();"><br>');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment