Userscript:修订间差异

来自Gea-Suan Lin's Wiki
跳到导航 跳到搜索
此页面具有访问限制。如果您看见此消息,则说明您没有权限访问此页面。
 
(未显示同一用户的12个中间版本)
第12行: 第12行:


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
let ob = new window.MutationObserver(events => {
const ob = new window.MutationObserver(mutations => {
   events.forEach(ev => {
  mutations.forEach(mutation => {
     ev.addedNodes.forEach(node => {
   mutation.addedNodes.forEach(node => {
      });
    if (...) {
      // Uninstall
     ob.disconnect();
    }
    });
    });
  });
});
});


ob.observe(document, {
ob.observe(document, {
   childList: true,
  childList: true,
   subtree: true,
  subtree: true,
});
});
</syntaxhighlight>
</syntaxhighlight>
== 自用 ==
重新安裝時用的,自己寫的就不列出來了:
* ​https://greasyfork.org/en/scripts/12493-hacker-news-folding-subtrees
* https://greasyfork.org/en/scripts/15261-facebook-sort-recent-newsfeed-by-default
* https://greasyfork.org/en/scripts/23661-youtube-hd
* ​https://greasyfork.org/en/scripts/383093-twitch-disable-automatic-video-downscale
* https://greasyfork.org/en/scripts/394512-youtube-progressbar-preserver
* https://greasyfork.org/en/scripts/396936-yt-not-interested-in-one-click
* ​https://greasyfork.org/en/scripts/403045-dmhy-bangumi-current-season
* https://greasyfork.org/en/scripts/431970-facebook-ad-block
另外的一些:
* https://adsbypasser.github.io/


== 外部連結 ==
== 外部連結 ==


* https://en.wikipedia.org/wiki/Userscript
* https://en.wikipedia.org/wiki/Userscript
* https://greasyfork.org/en/users/13655-gslin


=== Hosting ===
=== Hosting ===

2023年4月30日 (日) 19:31的最新版本

Userscript是一个让开发者更容易操作(与修改)网页的方式,通常是以JavaScript撰写。

软件

目前推荐使用开源的Violentmonkey,支援Chromium系列浏览器,以及Firefox浏览器。

范例

SPA

对于SPA类常用的方式,听HTML元素的事件(这边是听document元素,可以自己考虑听更小的范围):

const ob = new window.MutationObserver(mutations => {
  mutations.forEach(mutation => {
    mutation.addedNodes.forEach(node => {
      if (...) {
        // Uninstall
        ob.disconnect();
      }
    });
  });
});

ob.observe(document, {
  childList: true,
  subtree: true,
});

自用

重新安装时用的,自己写的就不列出来了:

另外的一些:

外部链接

Hosting