您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Simple wrapper around `MutationObserver` API to watch DOM changes.
此脚本不应直接安装,它是供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.org/scripts/488160/1335044/make-mutation-observer.js
// ==UserScript== // @name make-mutation-observer // @description Simple wrapper around `MutationObserver` API to watch DOM changes. // @version 0.1.0 // @namespace owowed.moe // @author owowed <[email protected]> // @license LGPL-3.0 // ==/UserScript== /** * @typedef {(info: { records: MutationRecord[], observer: MutationObserver }) => void} MakeMutationObserverCallback */ /** * @typedef MakeMutationObserverOptionsBasic * @prop {HTMLElement} target * @prop {MakeMutationObserverCallback} callback * @prop {AbortSignal} [abortSignal] * @prop {boolean} [once] */ /** @typedef {MakeMutationObserverOptionsBasic & MutationObserverInit} MakeMutationObserverOptions */ /** * Create a new `MutationObserver` from target and callback. * @param {Node} target target node * @param {MakeMutationObserverCallback} callback observer callback * @param {MakeMutationObserverOptions} options additional observer options * @returns {MutationObserver} */ function makeMutationObserver(target, callback, options) { return makeMutationObserverOptions({ target, ...options }, callback); } /** * Create a new `MutationObserver` with options and callback. * @param {MakeMutationObserverOptions} options * @param {MakeMutationObserverCallback} callback * @returns {MutationObserver} */ function makeMutationObserverOptions({ target, abortSignal, once, ...options }, callback) { const observer = new MutationObserver(records => { abortSignal?.throwIfAborted(); if (once) observer.disconnect(); callback({ records, observer }); }); observer.observe(target, options); abortSignal?.addEventListener("abort", () => { observer.disconnect(); }); return observer; }