Reddit Watcher

Consolidated mutation observer handler for use by other reddit userscripts. By itself doesn't do much, but other scripts can use hooks to avoid redundant observers watching the same thing.

目前為 2022-03-09 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

作者
Lawrence Sim
評價
0 0 0
版本
1.0.0
建立日期
2022-03-08
更新日期
2022-03-09
尺寸
4.2 KB
授權條款
WTFPL (http://www.wtfpl.net)
腳本執行於

Reddit Watcher

Consolidated MutationObserver handler for use by other Reddit userscripts. By itself doesn't do much, but other scripts can use hooks to avoid redundant observers watching the same thing. The main benefit being that overloading MutationObservers could slow down the browser. As such, if using multiple userscripts that use this function, a centralized handler will avoid unnecessary duplication.

Can use with:

Ensure in userscript dashboard that this is loaded before any dependent scripts by moving it above in the sorted list of installed userscripts.

Details

Creates variable named redditWatcher in window as simplest way of making itself available to other userscripts.

Within are three watcher objects for redditWatcher.body, redditWatcher.listing, and redditWatcher.feed. Each handles changes to the document body (with subtree), the listing outer container (with subtree), and the post feed respectively. The latter two are written to handle deletions and recreations of the watched element, should it be removed and readded.

Pass function to onUpdate() to run said function when MutationObserver detects an update on the watched element. Parameters passed will be the watched element and the array of MutationRecords.

Pass function to onChange() to run said function when element itself is changed. Usually this is triggered if the element is removed and/or readded. For the feed watcher, this is also triggered when the feed itself is changed, as Reddit reuses the same container, but empties/repopulates the content when the page is 'changed'.