Userscript:修订间差异

来自Gea-Suan Lin's Wiki
跳到导航 跳到搜索
此页面具有访问限制。如果您看见此消息,则说明您没有权限访问此页面。
(创建页面,内容为“== 範例 == 對於SPA類常用的方式,聽HTML元素的事件: <syntaxhighlight lang="javascript"> let ob = new window.MutationObserver(events => {…”)
 
 
(未显示同一用户的19个中间版本)
第1行: 第1行:
'''Userscript'''是一個讓開發者更容易操作(與修改)網頁的方式,通常是以[[JavaScript]]撰寫。
== 軟體 ==
目前推薦使用開源的[[Violentmonkey]],支援[[Chromium]]系列瀏覽器,以及[[Firefox]]瀏覽器。
== 範例 ==
== 範例 ==


 對於SPA類常用的方式,聽HTML元素的事件:
=== SPA ===
 
 對於SPA類常用的方式,聽HTML元素的事件 (這邊是聽<code>document</code>元素,可以自己考慮聽更小的範圍)


<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://greasyfork.org/en/users/13655-gslin
=== Hosting ===
* https://greasyfork.org/
* https://openuserjs.org/
* https://sleazyfork.org/

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