No Popup Windows

Convert popup windows to new tabs

目前为 2023-12-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name No Popup Windows
  3. // @namespace No Popup Windows
  4. // @version 0.1
  5. // @description Convert popup windows to new tabs
  6. // @author hangriver
  7. // @include *://*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=chinadfm.com
  9. // @grant none
  10. // @license WTFPL
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. //Get original descriptor
  17. const openWindow = Object.getOwnPropertyDescriptor(window, 'open')
  18.  
  19. //Intercept function
  20. if(openWindow){
  21. const openWindowFunc = openWindow.value;
  22. const blocker = function(...args){
  23. console.log('Args:', args)
  24. if(args[2]) args[2] = null;
  25. const res = openWindowFunc.apply(this, args)
  26. return res;
  27. }
  28. openWindow.value = blocker;
  29. }
  30.  
  31. Object.defineProperty(window, 'open', openWindow);
  32. })();