Disable Confirmation Dialog When Leaving A Web Page

Disable confirmation dialog when leaving a web page

  1. // ==UserScript==
  2. // @name Disable Confirmation Dialog When Leaving A Web Page
  3. // @namespace DisableConfirmationDialogWhenLeavingAWebPage
  4. // @description Disable confirmation dialog when leaving a web page
  5. // @license GNU AGPLv3
  6. // @author jcunews
  7. // @match *://*/*
  8. // @version 1.0.5
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (() => {
  14. var d = Object.getOwnPropertyDescriptor(window, "onbeforeunload");
  15. d.set = function(f) {
  16. return f;
  17. };
  18. Object.defineProperty(window, "onbeforeunload", d);
  19. d = EventTarget.prototype.addEventListener;
  20. EventTarget.prototype.addEventListener = function(typ) {
  21. if (typ.toLowerCase() !== "beforeunload") return d.apply(this, arguments);
  22. };
  23. })();