GC - Gormball character selector and prize logger

Remembers your last played character and up to 100 prizes

  1. // ==UserScript==
  2. // @name GC - Gormball character selector and prize logger
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.1
  5. // @description Remembers your last played character and up to 100 prizes
  6. // @author wibreth
  7. // @match https://www.grundos.cafe/games/gormball/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant GM_addStyle
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. /* globals $:false */
  17.  
  18. GM_addStyle('#prize-list {\
  19. max-width: 200px;\
  20. font-size: .8em;\
  21. max-height: 200px;\
  22. overflow: auto;\
  23. border: 1px solid #000;\
  24. position: absolute;\
  25. background: #fff;\
  26. padding: 5px 5px 5px 35px;\
  27. z-index: 3;\
  28. right: 0;\
  29. }\
  30. #prize-list-btn, #clear-list-btn {\
  31. float: right;\
  32. margin-top: -6px;\
  33. }\
  34. #page_content > p:first-of-type {\
  35. position: relative;\
  36. }\
  37. img[src$="gorm.gif"] {\
  38. cursor: pointer;\
  39. }');
  40.  
  41.  
  42. $('document').ready(() => {
  43. let listLoaded = false;
  44. let listVisible = false;
  45.  
  46. // log prizes
  47. if ($('strong:contains("Your Prize")').length != 0) { //win page
  48. let prizeList = GM_getValue("prizeList", []);
  49. if (prizeList.push($('.mt-1 strong').text()) > 100) // max of 100 items stored
  50. prizeList.shift();
  51. GM_setValue("prizeList", prizeList);
  52. }
  53.  
  54. // show prizes
  55. let showbtn = $('<input type="button" id="prize-list-btn" value="Show Prize Log">');
  56. showbtn.click(() => {
  57. if (listVisible) {
  58. $('#prize-list').hide();
  59. listVisible = false;
  60. return;
  61. }
  62. if (listLoaded) {
  63. $('#prize-list').show();
  64. listVisible = true;
  65. return;
  66. }
  67. let prizeList = GM_getValue("prizeList", []);
  68. let $prizeList = $('<ol id="prize-list">');
  69. if (!prizeList.length)
  70. $prizeList.append('<li>none!</li>');
  71. for (const prize of prizeList)
  72. $prizeList.append(`<li>${prize}</li>`);
  73. $('#page_content > p:first-of-type').append($prizeList);
  74. listLoaded = true;
  75. listVisible = true;
  76. });
  77. let clearbtn = $('<input type="button" id="clear-list-btn" value="Clear Prize Log">');
  78. clearbtn.click((e) => {
  79. if (!confirm("Are you sure you want to clear the prize log?")) {
  80. e.preventDefault();
  81. return;
  82. }
  83. if (listLoaded)
  84. $('#prize-list').empty();
  85. GM_setValue("prizeList", []);
  86. });
  87. $('#page_content > p:first-of-type').append(showbtn);
  88. $('#page_content > p:first-of-type').append(clearbtn);
  89.  
  90.  
  91. if ($('img[src$="gorm.gif"]').length == 0)
  92. return; //not on the character select page
  93.  
  94. let playerDD = GM_getValue("playerDD", 1); //default Thyassa
  95. $('#playerDD').val(playerDD);
  96.  
  97. $('.gormball_player').click(function() {
  98. playerDD = $(this).data('id');
  99. GM_setValue("playerDD", playerDD);
  100. });
  101.  
  102. let clicked = false;
  103. $('img[src$="gorm.gif"]').click(() => {
  104. if (clicked)
  105. return;
  106. clicked = true;
  107. $('form#play_gormball').submit();
  108. });
  109.  
  110.  
  111. });
  112. })();