I tried to write a Greasemonkey userscript that checks to see if the user is in one of a list of websites.
If the user is indeed in one of them, the script will alert:
Enough with this domain already!
The purpose of the script is to remind the user that he stop visiting this site (addiction-like behavior).
The output should include only the domain, without the TLD.
I have tried the following code which failed (the code runs on a collection of tlds and uses the collection to strip these away):
let sites = ['walla.com', 'mako.co.il'];
let tlds = new RegExp('\.+(com|co.il)');
for (let i = 0; i < sites.length; i++) {
if (window.location.href.indexOf(sites[i]) != -1 ) {
sites.forEach((e)=>{
e.replace(tlds, '').split('.').pop(),
});
alert(` Enough with this ${sites[i]} already! `);
}
}
No console errors.
To reproduce, install the script in Greasemoneky/Tampermonkey and try it in the listed sites.