Block Pop-ups Only

Block pop-ups while preserving normal button functionality

当前为 2025-03-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2.  
  3. // @name Block Pop-ups Only
  4.  
  5. // @namespace https://viayoo.com/
  6.  
  7. // @version 0.3
  8.  
  9. // @description Block pop-ups while preserving normal button functionality
  10.  
  11. // @author You
  12.  
  13. // @run-at document-start
  14.  
  15. // @match https://*/*
  16.  
  17. // @grant none
  18.  
  19. // @license MI
  20.  
  21. // ==/UserScript==
  22.  
  23. (function() {
  24. // Block alert, confirm, and prompt pop-ups
  25. window.alert = function() {
  26. console.log("Alert pop-up blocked: ", arguments);
  27. };
  28.  
  29. window.confirm = function() {
  30. console.log("Confirm pop-up blocked: ", arguments);
  31. return true; // Default to "OK"
  32. };
  33.  
  34. window.prompt = function() {
  35. console.log("Prompt pop-up blocked: ", arguments);
  36. return null; // Default to "Cancel"
  37. };
  38.  
  39. // Block window.open pop-ups
  40. const originalWindowOpen = window.open;
  41. window.open = function() {
  42. console.log("Window.open pop-up blocked: ", arguments);
  43. return null;
  44. };
  45.  
  46. // Block unwanted behaviors without breaking buttons
  47. document.addEventListener('DOMContentLoaded', function() {
  48. // Prevent <a target="_blank"> from opening new windows
  49. document.addEventListener('click', function(event) {
  50. const target = event.target;
  51. if (target.tagName === 'A' && target.target === '_blank') {
  52. event.preventDefault();
  53. console.log("Blocked new window from opening: ", target.href);
  54. // Optionally, open the link in the same tab
  55. window.location.href = target.href;
  56. }
  57. }, true);
  58.  
  59. // Prevent form submissions that trigger pop-ups
  60. document.addEventListener('submit', function(event) {
  61. const form = event.target;
  62. console.log("Form submission intercepted: ", form);
  63. // Allow the form to submit if it doesn't trigger a pop-up
  64. if (!form.target || form.target !== '_blank') {
  65. return; // Let the form submit normally
  66. }
  67. event.preventDefault();
  68. console.log("Blocked form submission that would open a pop-up: ", form);
  69. }, true);
  70. });
  71.  
  72. console.log("Pop-up blocker script is active");
  73. })();