Override HTML Standard Form Submission Result To Current Or New Tab

Make HTML standard form submission result be loaded in either the current tab (SHIFT key held), or in a new window (CTRL key held), when submitting the form. This script won't work on forms which don't use HTML standard form submission. e.g. AJAX.

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

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

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        Override HTML Standard Form Submission Result To Current Or New Tab
// @namespace   https://greasyfork.org/en/users/85671-jcunews
// @version     1.0.2
// @license     AGPL v3
// @author      jcunews
// @description Make HTML standard form submission result be loaded in either the current tab (SHIFT key held), or in a new window (CTRL key held), when submitting the form. This script won't work on forms which don't use HTML standard form submission. e.g. AJAX.
// @match       *://*/*
// @grant       none
// @run-at      document-start
// ==/UserScript==

(keys => {
  keys = {Shift: false, Control: false, Alt: false};
  function ovr(f, n) {
    f.dataset.tgt = f.target;
    f.target = n;
    setTimeout(() => {
      f.target = f.dataset.tgt;
      delete f.dataset.tgt
    }, 100)
  }
  function chk(f) {
    if ((f.dataset.tgt === undefined) && !keys.Alt) {
      if (keys.Shift && !keys.Control) {
        ovr(f, "")
      } else if (keys.Control && !keys.Shift) ovr(f, "_blank")
    }
  }
  function reset() {
    keys = {Shift: false, Control: false, Alt: false}
  }
  addEventListener("submit", ev => chk(ev.target), true);
  addEventListener("click", ev => ev.target?.form && chk(ev.target.form), true);
  addEventListener("keydown", ev => {
    if (ev.key === "Enter") {
      if (ev.target?.form) chk(ev.target.form)
    } else if (ev.key in keys) keys[ev.key] = true
  }, true);
  addEventListener("keyup", ev => (ev.key in keys) && (keys[ev.key] = false), true);
  addEventListener("blur", reset);
  addEventListener("focus", reset)
})()