WK Emblems turn-in

Speeds up the turning in of your WK emblems

  1. // ==UserScript==
  2. // @name WK Emblems turn-in
  3. // @namespace Conster
  4. // @description Speeds up the turning in of your WK emblems
  5. // @version 1.3
  6. // @history 1.3 New domain - animecubedgaming.com - Channel28
  7. // @history 1.2 Now https compatible (Updated by Channel28)
  8. // @history 1.1 Added grant permissions (Updated by Channel28)
  9. // @history 1.0 Initial Release
  10. // @include http*://*animecubed.com/billy/bvs/worldkaiju-spend.html
  11. // @include http*://*animecubedgaming.com/billy/bvs/worldkaiju-spend.html
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // ==/UserScript==
  15. var playername = "";
  16. var altprizes = false;
  17. var quantity = 11;
  18. loadPlayerName();
  19. var goback = document.forms.namedItem("backemblem");
  20. if (goback) { //there's a "Back to Emblem List" button, so we're at a specific redemption thingie
  21. if (altprizes) {
  22. var v = document.evaluate("//input [@name = 'wkaltprize']",document, null,
  23. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);
  24. if (v) {
  25. v.checked = true;
  26. }
  27. }
  28. changeAmount();
  29. }
  30.  
  31. function loadPlayerName() {
  32. try {
  33. var temp = document.getElementsByName("player")[1];
  34. if ((temp == null) || (temp.localName.toLowerCase() == "text") || (temp.value.length == 0))
  35. return;
  36. playername = temp.value;
  37. altprizes = GM_getValue(playername+"_altprizes", false);
  38. quantity = GM_getValue(playername+"_quantity", 11);
  39. } catch(e) {
  40. alert("Exception!\n\nError name: " + e.name + "\nError message: " + e.message);
  41. }
  42. }
  43.  
  44. function changeAmount() {
  45. var s = "//option [@value = '" + quantity + "']";
  46. var v = document.evaluate(s,document, null,
  47. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);
  48. if (v) {
  49. v.selected = true;
  50. }
  51. }
  52.  
  53. function process_event(event) {
  54. if (goback) {
  55. if (event.keyCode == 65) { //a for "Alt Prize": switch on or off
  56. altprizes = !altprizes;
  57. GM_setValue(playername+"_altprizes",altprizes);
  58. var v = document.evaluate("//input [@name = 'wkaltprize']",document, null,
  59. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);
  60. if (v) {
  61. v.checked = !(v.checked);
  62. }
  63. } else if (event.keyCode == 107) { //+ to increase amount to hand in
  64. quantity = quantity + 1;
  65. if (quantity > 11) { quantity = 1; }
  66. alert("New quantity to hand in at a time: "+quantity);
  67. GM_setValue(playername+"_quantity",quantity);
  68. changeAmount();
  69. } else if (event.keyCode == 109) { //- to increase amount to hand in
  70. quantity = quantity - 1;
  71. if (quantity == 0) { quantity = 11; }
  72. alert("New quantity to hand in at a time: "+quantity);
  73. GM_setValue(playername+"_quantity",quantity);
  74. changeAmount();
  75. } else if (event.keyCode == 85) { //u for "Use Emblems"
  76. var s = "//option [@value = '" + quantity + "']";
  77. var v = document.evaluate(s,document, null,
  78. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);
  79. if (v) {
  80. document.evaluate("//input [@name = 'wkconfirmcheck']",document, null,
  81. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).checked = true;
  82. document.forms.namedItem("chooseemblem").wrappedJSObject.submit();
  83. }
  84. }
  85. }
  86. }
  87.  
  88. document.documentElement.addEventListener("keyup", process_event, true);