Greasy Fork is available in English.

Disable page close confirmation

Disable page close confirmation (onBeforeUnload)

  1. // ==UserScript==
  2. // @name Disable page close confirmation
  3. // @description Disable page close confirmation (onBeforeUnload)
  4. // @namespace http://nags.must.die
  5. // @version 2.0
  6. // @grant none
  7. // @run-at document-start
  8. // @match *://*/*
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. var spoofer = {
  13. enumerable: true,
  14. configurable: false,
  15. get: () => null,
  16. set: fn => fn,
  17. };
  18. Object.defineProperties(window, {
  19. onbeforeunload: spoofer,
  20. onunload: spoofer,
  21. });
  22.  
  23. var originalAdd = EventTarget.prototype.addEventListener;
  24. EventTarget.prototype.addEventListener = function (type) {
  25. var tl;
  26. if (this !== window ||
  27. typeof type !== 'string' ||
  28. (tl = type.toLowerCase()) !== 'beforeunload' && tl !== 'unload') {
  29. originalAdd.apply(this, arguments);
  30. }
  31. };
  32. })();