IdlePixel Brewing Quick Filter

Adds quick filter buttons for monster, rocket and rotten, as well as a clear button. Can be configured in the plugin options.

  1. // ==UserScript==
  2. // @name IdlePixel Brewing Quick Filter
  3. // @namespace com.zlef.idlepixel
  4. // @version 1.1.0
  5. // @description Adds quick filter buttons for monster, rocket and rotten, as well as a clear button. Can be configured in the plugin options.
  6. // @author Zlef
  7. // @license MIT
  8. // @match *://idle-pixel.com/login/play*
  9. // @grant none
  10. // @require https://greasyfork.org/scripts/441206-idlepixel/code/IdlePixel+.js?anticache=20220905
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. class BrewFilter extends IdlePixelPlusPlugin {
  17. constructor() {
  18. super("brew_filter", {
  19. about: {
  20. name: GM_info.script.name,
  21. version: GM_info.script.version,
  22. author: GM_info.script.author,
  23. description: GM_info.script.description
  24. },
  25. config: [
  26. {
  27. type: "label",
  28. label: "Specify filter buttons. Separate by comma only:"
  29. },
  30. {
  31. id: "filters",
  32. label: "Brewing filter buttons",
  33. type: "string",
  34. max: 200000,
  35. default: "monster,rocket,rotten"
  36. }
  37. ]
  38. });
  39.  
  40. this.filterButtons = [];
  41. this.buttonElements = {};
  42. this.first_load = true;
  43. }
  44.  
  45. onConfigsChanged() {
  46. this.filterButtons = IdlePixelPlus.plugins.brew_filter.getConfig("filters").replace(";",",").replace(" ,", ",").replace(" , ",",").replace(", ",",").toLowerCase().split(',');
  47. if (this.first_load){
  48. this.first_load = false;
  49. } else {
  50. this.updateFilterButtons();
  51. }
  52. }
  53.  
  54. onLogin() {
  55. this.searchBarInput = document.querySelector('input[onkeyup="Brewing.search(this)"]');
  56. this.searchBarDiv = this.searchBarInput.parentElement;
  57.  
  58. if (!this.clearButton) { // Check if clearButton already exists
  59. this.clearButton = this.createButton('Clear', () => {
  60. this.searchBarInput.value = '';
  61. Brewing.search(this.searchBarInput);
  62. });
  63. this.searchBarDiv.appendChild(this.clearButton);
  64. }
  65.  
  66. this.updateFilterButtons();
  67. }
  68.  
  69. updateFilterButtons() {
  70. // Remove buttons that are not in the filterButtons array anymore
  71. for (let key in this.buttonElements) {
  72. if (!this.filterButtons.includes(key)) {
  73. this.searchBarDiv.removeChild(this.buttonElements[key]);
  74. delete this.buttonElements[key];
  75. }
  76. }
  77.  
  78. // Add new buttons
  79. this.filterButtons.forEach(filter => {
  80. if (!this.buttonElements[filter]) { // Check if button for this filter already exists
  81. const button = this.createButton(filter, () => {
  82. this.searchBarInput.value = filter;
  83. Brewing.search(this.searchBarInput);
  84. });
  85. this.searchBarDiv.appendChild(button);
  86. this.buttonElements[filter] = button;
  87. }
  88. });
  89. }
  90.  
  91. createButton(text, onclickFunction) {
  92. const button = document.createElement('button');
  93. button.textContent = text;
  94. button.type = 'button';
  95. button.onclick = onclickFunction;
  96. button.style.marginLeft = '5px';
  97. button.classList.add('btn-sm');
  98. return button;
  99. }
  100. }
  101.  
  102. const plugin = new BrewFilter();
  103. IdlePixelPlus.registerPlugin(plugin);
  104. })();
  105.  
  106.