A Tempermonkey script for rewriting <a>
redirect href links to its target url.
- YouTube
- Zhihu
- X
Deploy cloudflare-worker.js
as a serverless cloudflare worker.
see https://developers.cloudflare.com/workers/
- Initial Scan: When the page loads, the script scans the entire document for YouTube redirect links and adds them to the queue.
- Queue Processing: The queue is processed periodically (debounced to 500ms) to rewrite the href attributes of the links.
- Dynamic Content: The MutationObserver detects new content added to the DOM and ensures that any new YouTube redirect links are added to the queue.
- Efficient Processing: Links are processed in batches, and the debouncing ensures that the script doesn't overwhelm the browser.
- No Missed Links: The queue ensures that all links are processed, even if the observer is throttled.
- Efficient: Debouncing prevents excessive DOM updates and improves performance.
- Scalable: Works well on pages with frequent DOM updates or dynamically loaded content.
- No External Dependencies: The script uses a custom debounce function, so no external libraries like Lodash are required.