IdlePixel Dialogue Handler

Library which creates a modal for opening plugin panels.

当前为 2025-02-19 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/527481/1540081/IdlePixel%20Dialogue%20Handler.js

  1. // ==UserScript==
  2. // @name IdlePixel Dialogue Handler
  3. // @namespace luxferre.dev
  4. // @version 1.0.1
  5. // @description Library which creates a modal for opening plugin panels.
  6. // @author Lux-Ferre
  7. // @license MIT
  8. // @match *://idle-pixel.com/login/play*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. if (window.dialoguer) {
  14. // already loaded
  15. return;
  16. }
  17.  
  18. class Dialoguer {
  19. constructor() {
  20. this.original_dialogue = Modals.open_image_modal
  21. this.handlers = {}
  22.  
  23. Modals.open_image_modal = this.open_image_modal
  24. }
  25.  
  26. register_handler(selector, handler, propagate) {
  27. this.handlers[selector] = {
  28. handler: handler,
  29. propagate: propagate
  30. }
  31. }
  32.  
  33. open_image_modal(title, image_path, message, primary_button_text, secondary_button_text, command, force_unclosable) {
  34. const check_text = title + image_path + message
  35.  
  36. for (const [selector, handler] of Object.entries(this.handlers)) {
  37. if (check_text.includes(selector)) {
  38. [title, image_path, message, primary_button_text, secondary_button_text, command, force_unclosable] = handler.handler(title, image_path, message, primary_button_text, secondary_button_text, command, force_unclosable)
  39. if (!handler.propagate) {
  40. return
  41. }
  42. }
  43. }
  44.  
  45. this.original_dialogue(title, image_path, message, primary_button_text, secondary_button_text, command, force_unclosable)
  46. }
  47. }
  48.  
  49. // Add to window and init
  50. window.dialoguer = new Dialoguer();
  51. })();