AutoExit(CAVEGAME.IO)

Fixed exit confirmation bug. Press F4 to auto-exit and rejoin

  1. // ==UserScript==
  2. // @name AutoExit(CAVEGAME.IO)
  3. // @namespace Violentmonkey Scripts
  4. // @match https://cavegame.io/*
  5. // @grant none
  6. // @version 2.0
  7. // @author Drik
  8. // @description Fixed exit confirmation bug. Press F4 to auto-exit and rejoin
  9. // @license MIT
  10. // @run-at document-start
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14.  
  15. Object.defineProperty(window, 'onbeforeunload', {
  16. configurable: true,
  17. get: () => null,
  18. set: () => {}
  19. });
  20.  
  21. const originalAdd = window.addEventListener;
  22. window.addEventListener = function(type, listener, options) {
  23. if (type === 'beforeunload') return;
  24. return originalAdd.call(this, type, listener, options);
  25. };
  26.  
  27. document.addEventListener('keydown', e => {
  28. if (e.key === 'F4') {
  29. const tryExit = () => {
  30. const btn = document.querySelector('.exit-button.exit-button-top.no-select');
  31. if (btn) {
  32. btn.click();
  33. setTimeout(() => {
  34. document.querySelector('#play-cavegame-io')?.click();
  35. }, 200);
  36. }
  37. };
  38. setTimeout(tryExit, 0);
  39. }
  40. });
  41. })();