YouTube - Hide Watched.
目前為
// ==UserScript==
// @name YouTube - Hide Watched
// @description YouTube - Hide Watched.
// @version 0.1
// @author to
// @namespace https://github.com/to
// @license MIT
//
// @match https://www.youtube.com/feed/subscriptions
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
//
// @run-at document-idle
// ==/UserScript==
const THRESHOLD = 90;
new MutationObserver(throttleAndDebounce(() => {
for (let progress of document.querySelectorAll('#progress')) {
if (parseInt(progress.style.width) > THRESHOLD) {
let video = progress.closest('ytd-grid-video-renderer');
video.classList.add('tm-watched')
video.style.display = 'none';
}
}
}, 1000)).observe(document.body, {
childList: true,
subtree: true,
});
function throttleAndDebounce(fn, interval) {
let timer;
let lastTime = Date.now() - interval;
return function () {
if ((Date.now() - lastTime) > interval) {
lastTime = Date.now();
fn();
} else {
clearTimeout(timer);
timer = setTimeout(() => {
fn();
}, interval);
}
}
}