TankTrouble Development Library

Shared library for TankTrouble userscript development

目前为 2023-12-13 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/482092/1294933/TankTrouble%20Development%20Library.js

// ==UserScript==
// @name        TankTrouble Development Library
// @author      commander
// @namespace   https://github.com/asger-finding
// @version     0.0.2
// @license     GPL-3.0
// @description Shared library for TankTrouble userscript development
// @match       *://*.tanktrouble.com/*
// @grant       none
// @run-at      document-start
// @noframes
// ==/UserScript==

/* jshint esversion: 8 */

/**
 * Fires when the document is readyState `interactive` or `complete`
 * @returns Promise that resolves upon content loaded
 */
const contentLoaded = () => new Promise(promiseResolve => {
	if (document.readyState === 'interactive' || document.readyState === 'complete') promiseResolve();
	else document.addEventListener('DOMContentLoaded', () => promiseResolve());
});

/**
 * Fires when the `main()` function is done on TankTrouble.
 * @returns Promise that resolves upon content initialized
 */
const contentInitalized = () => new Promise(promiseResolve => {
	contentLoaded().then(() => {
		const contentInitHook = Content.init;
		Reflect.defineProperty(Content, 'init', {
			/**
			 * Resolve after Content.init call finishes
			 *
			 * @param args Arguments to pass
			 */
			value: (...args) => {
				contentInitHook(...args);

				promiseResolve();
			}
		});
	});
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址