63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
// ==UserScript==
|
|
// @name YouTube main page remover
|
|
// @version 1
|
|
// @description self explanatory
|
|
// @match *://www.youtube.com/*
|
|
// @grant none
|
|
// @run-at document-start
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
///// CONFIGURATION /////
|
|
|
|
const main_page_timeout = 1000 * 5; // timeout for removing main page videos element (in ms)
|
|
|
|
/////////////////////////
|
|
|
|
var main_page_div;
|
|
var start_time;
|
|
|
|
// Check if the url is https://www.youtube.com (main page) every second (stops when main page is already removed)
|
|
const interval_id = setInterval(function() {
|
|
console.log("url check loop running");
|
|
|
|
if (window.location.href == "https://www.youtube.com/") {
|
|
remove_main_page();
|
|
}
|
|
}, 1000);
|
|
|
|
|
|
|
|
// function to try to remove main page videos element
|
|
function remove_main_page() {
|
|
console.log("starting to try to remove main page");
|
|
|
|
// stop interval loop
|
|
clearInterval(interval_id);
|
|
|
|
start_time = Date.now();
|
|
window.requestAnimationFrame(loop);
|
|
}
|
|
|
|
|
|
function loop() {
|
|
// check if main page videos element exists
|
|
main_page_div = document.querySelector("ytd-rich-grid-renderer > #contents");
|
|
|
|
// if it exists, remove it
|
|
console.log("trying to remove main page");
|
|
if (main_page_div) {
|
|
main_page_div.remove();
|
|
console.log("removed main page");
|
|
} else {
|
|
// check if the timeout has NOT been reached
|
|
if (Date.now() - start_time < main_page_timeout) {
|
|
window.requestAnimationFrame(loop);
|
|
} else {
|
|
console.log("main page timeout reached");
|
|
}
|
|
}
|
|
}
|
|
})(); |