I wrote the following Greasemonkey script to prevent myself from accessing a few web apps (web sites), usually these I feel a bit addicted to. This is the closest I got to prevent my Browsers to display these sites:
// ==UserScript==
// @name blocko
// @include *
// ==/UserScript==
window.addEventListener('load', function() {
let sites = ['example-1.com', 'example-2.com', 'example-3.com'];
let dotTLD_andAllAfterIt = /\..+/;
let href = window.location.href;
for (let i = 0; i < sites.length; i++) {
if (href.includes(sites[i])) {
let domain = sites[i].replace(dotTLD_andAllAfterIt, '');
document.body.innerHTML =`
<div style="direction: ltr; position: fixed; top: 0; z-index: 999999; display: block; width: 100%; height: 100%; background: red">
<p style="position: relative; top: 40%; display: block; font-size: 66px; font-weight: bold; color: #fff; margin: 0 auto; text-align: center">
Enough with this ${domain} bullshit!
</p>
</div>
`;
}
}
}, true);
I'm not satisfied of my achievement here as this script gets me into the site and I need to wait 1/2/3/4 or even 5 or more seconds in rare cases, until the site will vanish and the message I print to the screen with red background will appear instead. Thus I'm unwillingly exposed to the site's content, from which I want to avoid.
I desire to prevent the browser from even navigating into a website, through JavaScript. There is a Chrome addon named "BlockSite" that helps with this and I tried to examine its (huge) source code but failed to understand how it prevents the user to be moved into a website, unlike my script above that moves the user to the website but vanishes the website with a message after a few seconds (after the load
event was triggered).
Please share a way to totally prevent yourself of moving into a website, as with "BlockSite".