// ==UserScript== // @name Ultimate Popup Blocker // @namespace https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs // @version 2 // @description Configurable popup blocker that blocks all popup windows by default. // @author hacker09 // @include * // @icon https://i.imgur.com/6SGMd42.png // @run-at document-end // @grant GM_getValue // @grant GM_setValue // @grant GM_listValues // @grant GM_deleteValue // @grant GM_registerMenuCommand // @downloadURL https://update.greasyfork.icu/scripts/478508/Ultimate%20Popup%20Blocker.user.js // @updateURL https://update.greasyfork.icu/scripts/478508/Ultimate%20Popup%20Blocker.meta.js // ==/UserScript== (function() { 'use strict'; var upb_counter = 0; //Count amount of blocked popups var timeleft = 10; //Create a variable to hold the time left GM_registerMenuCommand('Configure popup permissions', () => { open('https://f.org/ultimate-popup-blocker/settings.html', '_blank'); }); //Add a settings page on the Tampermonkey menu if (!GM_getValue(`trusted_${location.host}`)) { //Override the browser default "window.open" implementation with the script fakeWindowOpen method unsafeWindow.open = (function(Url) { //Run the script fake Window Open function below when the browser tries to open a new window if (timeleft === 10 && document.querySelector("#upb_menu") === null) { //If the time left is exactly 10 secs and the menu has not been created yet upb_counter += 1; //Count the amount of blocked popups document.body.insertAdjacentHTML('beforeend', `
`); //Add the script menu on the page [{ text: 'Allow ↗️', id: 'upb_open', clickCallback: () => { open(Url, '_blank'); document.querySelector("#upb_menu").style.display = 'none'; } }, { text: 'Always Allow ✅', id: 'upb_trust', clickCallback: () => { GM_setValue(`trusted_${location.host}`, true); open(Url, '_blank'); document.querySelector("#upb_menu").style.display = 'none'; } }, { text: `Deny (${timeleft}) ❌`, id: 'upb_close', clickCallback: () => { document.querySelector("#upb_menu").style.display = 'none'; }, inlineStyle: 'background-color:#a00;color:white;' },{ text: 'Config ⚙️', id: 'upb_config', clickCallback: () => { open('https://f.org/ultimate-popup-blocker/settings.html', '_blank'); }, inlineStyle: 'float:right;margin:0 10px 0 0;' } ].forEach(button => { //ForEach menu buttons data document.querySelector("#upb_menu").insertAdjacentHTML('beforeend', ``); //Add the all buttons on the menu document.getElementById(button.id).addEventListener('click', button.clickCallback); //Add a click function to each button }); //Finishes the ForEach loop const Timer = setInterval(() => { //Start a interval function checker document.getElementById('upb_close').innerHTML = `Deny (${timeleft}) ❌`; //Update the displayed timer timeleft -= 1; //Decrease the time left if (timeleft < 0) { //If the time left is less than 0 clearInterval(Timer); //Stop the timer from running document.querySelector("#upb_menu").remove(); //Remove the script menu timeleft = 10; //Reset the time left } //Finishes the if condition }, 1000); //Update the displayed timer each second } //Finishes the if condition return { blur() { return false; }, focus() { return false; }, }; }); //Return the fake window function to not encounter JS runtime error when the popup originator page wants to call focus() or blur() } //Finishes the if condition if (location.href === 'https://f.org/ultimate-popup-blocker/settings.html') { //If the user is on the page settings website document.head.remove(); //Remove the current page head document.body.remove(); //Remove the current page body document.querySelector("html").innerHTML = `