IdlePixel Loot Popup Remover

Stops vanilla loot popups, leaving only loot log

  1. // ==UserScript==
  2. // @name IdlePixel Loot Popup Remover
  3. // @namespace lbtechnology.info
  4. // @version 1.1.1
  5. // @description Stops vanilla loot popups, leaving only loot log
  6. // @author Lux-Ferre
  7. // @license MIT
  8. // @match *://idle-pixel.com/login/play*
  9. // @grant none
  10. // @require https://greatest.deepsurf.us/scripts/441206-idlepixel/code/IdlePixel+.js?anticache=20220905
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. class NoLootPlugin extends IdlePixelPlusPlugin {
  17. constructor() {
  18. super("noloot", {
  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. label: `<div class="d-flex w-100"><span class="align-self-center col-6">Allowed Popups</span><span class="col-6"><button class="btn btn-primary" type="button" onclick="IdlePixelPlus.plugins.noloot.showModal(&quot;noloot&quot;, &quot;allowedPopups&quot;)">Edit List</button></span></div>`,
  28. type: "label"
  29. }
  30. ]
  31. });
  32. this.previous = "";
  33. this.allowedPopups = new Set()
  34. }
  35.  
  36. onLogin(){
  37. this.addStyles()
  38. this.loadAllowed()
  39. this.createModal()
  40. this.originalOpenLootDialogue = Modals.open_loot_dialogue;
  41. Modals.open_loot_dialogue = this.openLootDialogue;
  42. }
  43. openLootDialogue(loot_images_array, loot_labels_array, loot_background_color_array, extra_data, levelups_data){
  44. const allowedSet = IdlePixelPlus.plugins.noloot.allowedPopups
  45. let showModal = loot_labels_array.some(label => {
  46. return [...allowedSet].some(filterItem => {
  47. return label.toLowerCase().includes(filterItem.toLowerCase())
  48. })
  49. });
  50. if (showModal){
  51. IdlePixelPlus.plugins.noloot.originalOpenLootDialogue(loot_images_array, loot_labels_array, loot_background_color_array, extra_data, levelups_data)
  52. return;
  53. }
  54. var logger = []
  55. for(var i = 0; i < loot_images_array.length; i++){
  56. var image = loot_images_array[i];
  57. var label = loot_labels_array[i];
  58. var background_color = loot_background_color_array[i];
  59.  
  60. logger.push({
  61. 'image': image,
  62. 'label': label,
  63. 'color': background_color,
  64. })
  65. }
  66.  
  67. try {
  68. var logObj = new LogManager()
  69. logObj.add_entry('monster_drop', logger);
  70. } catch (error) {
  71. console.log(error);
  72. }
  73. }
  74. createModal(){
  75. const modalString = `
  76. <div id="listHandleModal" class="modal fade" role="dialog" tabindex="-1"">
  77. <div class="modal-dialog" role="document">
  78. <div id="listHandleModalInner" class="modal-content">
  79. <div class="modal-body">
  80. <div id="listHandleList" class="overflow-auto"></div>
  81. </div>
  82. <div id="listHandleModalFooter">
  83. <form style="margin-right: 10px;margin-left: 10px;" onsubmit="event.preventDefault(); IdlePixelPlus.plugins.noloot.addItemModal();">
  84. <div class="row d-flex flex-fill">
  85. <div class="col-10"><input id="listHandleInput" class="form-control w-100" type="text" /></div>
  86. <div class="col-2"><input id="listHandleButton" class="w-100 h-100 rounded-pill" type="submit" value="Add" /></div>
  87. </div>
  88. </form>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. `
  94. const modalElement = $.parseHTML(modalString)
  95. $(document.body).append(modalElement)
  96. }
  97. loadAllowed(){
  98. const allowedJSON = localStorage.getItem("noLootAllowed")
  99. if (allowedJSON){
  100. const allowedList = JSON.parse(allowedJSON)
  101. allowedList.forEach(item=>{this.allowedPopups.add(item)})
  102. }
  103. }
  104. saveAllowed(){
  105. const allowedSet = this.allowedPopups
  106. const allowedJSON = JSON.stringify([...allowedSet])
  107. localStorage.setItem("noLootAllowed", allowedJSON)
  108. }
  109. addStyles(){
  110. let backgroundColour
  111. let textColour
  112.  
  113. if ("ui-tweaks" in IdlePixelPlus.plugins){
  114. backgroundColour = IdlePixelPlus.plugins["ui-tweaks"].config["color-chat-area"]
  115. textColour = IdlePixelPlus.plugins["ui-tweaks"].config["font-color-chat-area"]
  116. } else {
  117. backgroundColour = "white"
  118. textColour = "black"
  119. }
  120. const styles = `
  121. #listHandleModalFooter {
  122. padding: calc(var(--bs-modal-padding) - var(--bs-modal-footer-gap) * .5);
  123. background-color: var(--bs-modal-footer-bg);
  124. border-top: var(--bs-modal-footer-border-width) solid var(--bs-modal-footer-border-color);
  125. border-bottom-right-radius: var(--bs-modal-inner-border-radius);
  126. border-bottom-left-radius: var(--bs-modal-inner-border-radius);
  127. }
  128.  
  129. .listItem {
  130. background-color: RGBA(1, 150, 150, 0.5);
  131. margin-bottom: 2px;
  132. }
  133.  
  134. .listHandleCross {
  135. border-right-style: ridge;
  136. margin-left: 5px;
  137. padding-right: 3px;
  138. }
  139.  
  140. .listHandleText {
  141. margin-left: 6px;
  142. }
  143.  
  144. #listHandleModalInner {
  145. background-color: ${backgroundColour};
  146. color: ${textColour};
  147. }
  148. `
  149. const styleElement = `<style id="styles-lootRemover">${styles}</style>`
  150. $("head").append(styleElement)
  151. }
  152. addItemModal(){
  153. const inputBox = $("#listHandleInput")
  154. const newItem = inputBox.val()
  155. inputBox.val("")
  156. this.addItem(newItem)
  157. }
  158. addItem(newItem){
  159. this.allowedPopups.add(newItem)
  160. const newItemString = `<div class="listItem rounded-pill" id="${newItem}" onclick="event.preventDefault(); IdlePixelPlus.plugins.noloot.removeItem(this.getAttribute(&#39;id&#39;))"><span class="listHandleCross">❌</span><span class="listHandleText">${newItem}</span></div>`
  161. const newItemElement = $.parseHTML(newItemString)
  162. $("#listHandleList").append(newItemElement)
  163. this.saveAllowed()
  164. }
  165. removeItem(removedItem){
  166. const listHandleModal = $('#listHandleModal')
  167. const currentPlugin = listHandleModal.attr("data-lh-plugin")
  168. const currentList = listHandleModal.attr("data-lh-listName")
  169. this[currentList].delete(removedItem)
  170. $(`#${removedItem}`).remove()
  171. this.saveAllowed()
  172. }
  173. showModal(plugin, listName){
  174. document.body.scrollTop = document.documentElement.scrollTop = 0;
  175. $("#listHandleList").empty()
  176. this[listName].forEach(listItem=>{this.addItem(listItem)})
  177. const listHandleModal = $('#listHandleModal')
  178. listHandleModal.attr("data-lh-plugin", plugin)
  179. listHandleModal.attr("data-lh-listName", listName)
  180. listHandleModal.modal('show');
  181. }
  182. }
  183. const plugin = new NoLootPlugin();
  184. IdlePixelPlus.registerPlugin(plugin);
  185. })();