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.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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)
})()