Please review my JavaScript about blocking news websites, blocking autoplaying of videos and blocking specific websites

I have written the following JavaScript user script (which I run on Chrome with Tampermonkey) to do three things:

  • Blocking all or most news websites
  • Blocking autoplaying of videos
  • Blocking specific websites

I have tested all three JavaScript modules of the script at least twice and found them to work.

// ==UserScript==
// @name        digital_wellbeing
// @run-at      document-start
// @match       *://*/*
// ==/UserScript==

//
// Block news websites as much as possible
//

if (
  document.querySelector('title')?.textContent.includes('News') ||
  document.querySelector('title')?.textContent.includes('news') ||
  document.querySelector('meta[name="title"]')?.content.includes('News') ||
  document.querySelector('meta[name="title"]')?.content.includes('news') ||
  document.querySelector('meta[name="description"]')?.content.includes('News') ||
  document.querySelector('meta[name="description"]')?.content.includes('news') ||
  document.querySelector('meta[name="tags"]')?.content.includes('News') ||
  document.querySelector('meta[name="tags"]')?.content.includes('news')
) {
  window.open("https://google.com/", "_self");
}

//
// Block videos autoplay
//

window.setInterval( () => {
  document.querySelectorAll('video').forEach(anyVideo => {
    anyVideo.pause();
  });
}, 1);

//
// Block specific website/s
//

window.setInterval( () => {
    const urlPatternToBlock = [
        'WEBSITE_URL'
    ];

    for (const element of urlPatternToBlock) {
        if (window.location.href.includes(urlPatternToBlock)) {
        window.open("https://google.com/", "_self");
        }
    }
}, 1);

This is merely my perspective, but it seems like a squandering of energy considering that one can simply turn off JavaScript.

Hi !
I am sorry, I misunderstood you.
How could turning off JavaScript help me achieve the same goal?

Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.