侦听网页节点变化

侦听节点变化

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/479253/1276618/%E4%BE%A6%E5%90%AC%E7%BD%91%E9%A1%B5%E8%8A%82%E7%82%B9%E5%8F%98%E5%8C%96.js

  1. // ==UserScript==
  2. // @name 侦听网页节点变化
  3. // @namespace https://leochan.me
  4. // @version 1.0.0
  5. // @description 侦听节点变化
  6. // @author Leo
  7. // @match *://*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=leochan.me
  9. // @homepage https://leochan.me
  10. // @licesen GPLv2
  11. // @grant none
  12. // ==/UserScript==
  13. function leoChanWatchTargetElement(selector, cb){
  14. const targetElement = document.querySelector(selector);
  15. if(!targetElement){
  16. return;
  17. }
  18. const config = { attributes: true, childList: true, subtree: true };
  19. const observer = new MutationObserver(cb);
  20. observer.observe(targetElement, config);
  21. return observer;
  22. }

QingJ © 2025

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