10/30/2021, 12:35:27 AM
当前为
// ==UserScript==
// @name Youtube: Remove Overlays
// @namespace https://greasyfork.org/en/users/221281-klaufir
// @match https://www.youtube.com/embed/*
// @match https://www.youtube.com/watch*
// @grant none
// @version 1.7
// @author -
// @description 10/30/2021, 12:35:27 AM
// ==/UserScript==
function idle_waiter(wait_for_idle_ms, on_idle_callback) {
// source: https://stackoverflow.com/a/47406751
var action = function(o) {
o.disconnect();
on_idle_callback();
}
var resetTimer = function(changes, observer) {
clearTimeout(timer);
timer = setTimeout(action, wait_for_idle_ms, observer);
}
var observer = new MutationObserver(resetTimer);
var timer = setTimeout(action, wait_for_idle_ms, observer); // wait for the page to stay still for 3 seconds
observer.observe(document, {childList: true, subtree: true});
}
function removeAllByClass(classes) {
classes.forEach(cls => {
Array.from(document.getElementsByClassName(cls)).map(e => e.remove());
});
}
function cleanupOverlays() {
const classes = [
'ytp-paid-content-overlay', // paid promotion notification overlay in the bottom left corner
'ytp-pause-overlay', // "More Videos" overlay on paused embeds
'ytp-ce-element', // covering overlays at the end of the video
'iv-branding', // branding overlay in the bottom right corner
'ytp-cards-teaser', // info cards in the top right corner
'ytp-cards-button-icon', // info cards in the top right corner
'ytp-cards-button-title', // info cards in the top right corner
'ytp-endscreen-content' // endscreen recommended videos
];
removeAllByClass(classes);
}
// overkill but works
idle_waiter(100, cleanupOverlays);
idle_waiter(500, cleanupOverlays);
idle_waiter(1000, cleanupOverlays);
setTimeout(cleanupOverlays, 2000);