Ctrl+Won't

Prevents accidental Ctrl+W from closing current tab while you are typing something (input/textarea tag is active). You can change the whit list of websites (on which this script will be "enabled").

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Ctrl+Won't
// @namespace    http://tampermonkey.net/
// @version      2024-03-17
// @description  Prevents accidental Ctrl+W from closing current tab while you are typing something (input/textarea tag is active). You can change the whit list of websites (on which this script will be "enabled").
// @author       Andrew15-5
// @match        *://*/*
// @icon         https://i.ytimg.com/vi/Qa5xfIbMaqw/maxresdefault.jpg
// @grant        none
// @license      AGPL-3.0
// ==/UserScript==

(function () {
  'use strict';
  const whitelist = [
    'github.com',
    'discord.com',
    'stackoverflow.com',
    'greasyfork.org',
  ];
  if (!whitelist.includes(location.hostname)) {
    return;
  }
  addEventListener(
    'beforeunload',
    function (e) {
      if (location.hostname === 'discord.com') {
        if (
          document.activeElement.localName !== 'div' ||
          document.activeElement.getAttribute('role') !== 'textbox'
        ) {
          return;
        }
      } else if (
        !['input', 'textarea'].includes(document.activeElement.localName)
      ) {
        return;
      }
      e.stopPropagation();
      e.preventDefault();
      return false;
    },
    true,
  );
})();