// ==UserScript== // @name Ultimate Popup Blocker // @namespace https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs // @version 1 // @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_openInTab // @grant GM_listValues // @grant GM_deleteValue // @grant GM_registerMenuCommand // @downloadURL none // ==/UserScript== (function() { 'use strict'; var timeleft = 15; //Create a variable to hold the time left unsafeWindow.upb_counter = 0; //Count amount of blocked popups const domain = location.host; //Save the domain url const logDiv = document.createElement('div'); //Create the script menu logDiv.style.cssText = 'position: fixed; bottom: 0px; left: 0px; z-index: 99999; width: unset; padding: 5px; font: inherit; background-color: black; color: white; cursor: help; display: block;'; //Add the script menu style document.body.appendChild(logDiv); //Add the script menu on the page GM_registerMenuCommand('Configure popup permissions', () => { GM_openInTab('https://f.org/ultimate-popup-blocker/settings.html', false); }); //Add a settings page on the Tampermonkey menu if (!GM_getValue(`trusted_${domain}`)) { //Override the browser default "window.open" implementation with the script fakeWindowOpen method unsafeWindow.open = (function(Url) { //Run the script fake Window Open function when the browser tries to open a new window unsafeWindow.upb_counter += 1; //Count the amount of blocked popups logDiv.innerHTML = `Allow ${domain} to open a popup? (${unsafeWindow.upb_counter})`; //Shows the script menu logDiv.title = Url; //Shows the blocked url logDiv.style.display = 'block'; //Make the menu visible function createButton(text, id, clickCallback, inlineStyle) { //Create the script menu buttons const button = document.createElement('button'); //Create the button element button.innerHTML = text; //Add a text to the button element button.id = id; //Add an id to the button element (just because of the Close Button) button.style.cssText =`text-decoration: none; color: black; cursor: pointer; margin: 0 5px; padding: 1px 3px; background-color: rgb(255, 255, 255); border-width: 0px; border-radius: 5px; color: black; ${inlineStyle}`; //Add a style to each button (Use inlineStyle just because of the Close/createButton Buttons) logDiv.appendChild(button); //Add the button on the menu button.addEventListener('click', clickCallback); //Add a button on click action } createButton('Allow ↗️', 'upb_open', () => { open(Url, '_blank'); logDiv.style.display = 'none'; }, '',); //Create the Open Popup Button createButton('Always Allow ✅', 'upb_trust', () => { GM_setValue(`trusted_${domain}`, true); open(Url, '_blank'); logDiv.style.display = 'none'; }, '', ); //Create the Trust Button createButton(`Deny (${timeleft}) ❌`, 'upb_close', () => { logDiv.style.display = 'none'; }, ' background-color: #a00; color: white;', ); //Create the Close Button createButton('Config ⚙️', 'upb_config', () => { GM_openInTab('https://f.org/ultimate-popup-blocker/settings.html', false); }, ' float: right; margin: 0 10px 0 0;', ); //Create the Config Button if (timeleft === 15) { //If the time left is exactly 15 secs const Timer = setInterval(() => { //Start a interval function checker document.getElementById('upb_close').innerHTML = `Deny (${timeleft}) ❌`; //Update the 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 logDiv.style.display = 'none'; //Hide the script menu timeleft = 15; //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 current page head document.body.remove(); //Remove current page body document.querySelector("html").innerHTML = `[UPB] Permission manager

Ultimate Popup Blocker

Trusted websites:

Add
`; //Add the script settings page on the website function addDomainToPermissionList(domain) { //For each domain on the Tampermonkey storage const li = document.createElement('li'); //Create a new li element li.appendChild(document.createTextNode(domain.replace('trusted_', ''))); //Add the domain on the li element list document.getElementById('List').appendChild(li); //Add the list on the page const span = document.createElement('SPAN'); //Create a new span X element const txt = document.createTextNode('✘'); //Add a remove X button to li span.className = 'close'; //Add a class name to the span element (so that the page's internal CSS knows where to place the X button) span.appendChild(txt); //Add the remove X button on the page span.onclick = (function() { //When the X span element is clicked GM_deleteValue(`trusted_${this.parentElement.innerText.replace('\n✘', '')}`); //Remove the domain from the Tampermonkey storage this.parentElement.style.display = 'none'; //Hide the removed domain from the page list }); //Finishes the onclick function li.appendChild(span); //Add each span X element on the list } //Finishes the addDomainToPermissionList function document.getElementsByClassName('addBtn')[0].addEventListener('click', () => { //If the Add Button is clicked on the page if (document.getElementById('Input').value !== '') { //If the user is not trying to add a blank domain GM_setValue(`trusted_${document.getElementById('Input').value}`, true); //Add the domain on the Tampermonkey storage } //Finishes the if condition document.getElementById('Input').value = ''; //Reset the domain the user wrote }); //Finishes the onclick function //Show already stored elements in the list GM_listValues().forEach(addDomainToPermissionList); //Run the addDomainToPermissionList ForEach domain on the Tampermonkey Storage } //Finishes the if condition })();