disable_pop_ups_button.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // ==UserScript==
  2. // @name Disable Pop-ups Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description 在任意页面添加按钮,点击后禁用 window.open 弹窗行为
  6. // @author Jack
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12. // 创建按钮
  13. const button = document.createElement('button');
  14. button.textContent = "Disable Pop-ups";
  15. // 按钮样式
  16. button.style.position = "fixed";
  17. button.style.top = "12.5%";
  18. button.style.right = "1%";
  19. button.style.transform = "translateY(-50%)";
  20. button.style.padding = "3px 8px";
  21. button.style.fontSize = "10px";
  22. button.style.backgroundColor = "#007baf";
  23. button.style.color = "#fff";
  24. button.style.border = "none";
  25. button.style.borderRadius = "5px";
  26. button.style.cursor = "pointer";
  27. button.style.zIndex = "10000";
  28. // 点击事件,覆盖 window.open
  29. button.addEventListener('click', () => {
  30. const originalOpen = window.open;
  31. window.open = function() {
  32. return originalOpen('', '_self');
  33. };
  34. // 可选:点击后提示用户已禁用弹窗
  35. alert('Pop-ups have been disabled for this page.');
  36. });
  37. // 挂载按钮到页面
  38. document.body.appendChild(button);
  39. })();