IdlePixel Dialogue Handler

Library which creates a modal for opening plugin panels.

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/527481/1540082/IdlePixel%20Dialogue%20Handler.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name			IdlePixel Dialogue Handler
// @namespace		luxferre.dev
// @version			1.0.2
// @description		Library which creates a modal for opening plugin panels.
// @author			Lux-Ferre
// @license			MIT
// @match			*://idle-pixel.com/login/play*
// @grant			none
// ==/UserScript==

(function () {
	if (window.dialoguer) {
		// already loaded
		return;
	}

	class Dialoguer {
		constructor() {
			this.original_dialogue = Modals.open_image_modal
			this.handlers = {}

			Modals.open_image_modal = function (title, image_path, message, primary_button_text, secondary_button_text, command, force_unclosable) {
				const check_text = title + image_path + message

				for (const [selector, handler] of Object.entries(window.dialoguer.handlers)) {
					if (check_text.includes(selector)) {
						[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)
						if (!handler.propagate) {
							return
						}
					}
				}

				window.dialoguer.original_dialogue(title, image_path, message, primary_button_text, secondary_button_text, command, force_unclosable)
			}
		}

		register_handler(selector, handler, propagate) {
			this.handlers[selector] = {
				handler: handler,
				propagate: propagate
			}
		}
	}

	// Add to window and init
	window.dialoguer = new Dialoguer();
})();