Right Open & Close

RClick open link, Double RClick close tab

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ć!)

Advertisement:

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ć!)

Advertisement:

// ==UserScript==
// @name        Right Open & Close
// @namespace   Violentmonkey Scripts
// @match       *://*/*
// @match       file:///*
// @run-at      document-start
// @grant       unsafeWindow
// @grant       GM_openInTab
// @grant       window.close
// @version     1.2
// @author      leoshone
// @description RClick open link, Double RClick close tab
// ==/UserScript==
(function() {
  //Hide context menu, Press CTRL + RClick show context menu
  document.addEventListener('contextmenu', function(e) {
    if (!e.ctrlKey)
      e.preventDefault();
  }, false);
  
  //RClick open link in background tab, Double RClick close tab
  var clickNo = 0;
  var resetId;
  document.addEventListener('mousedown', function(e) {
    if (!e.ctrlKey && e.button == 2) {
      clickNo++;
      if (clickNo == 1) {
        resetId = setTimeout(function() {
          clickNo = 0;
          var href = e.target.closest('a').href;  
          if (href !== "" && !/^javascript:/i.test(href.toString()))
            GM_openInTab(href, {active: false, insert: false});
        }, 300);
      } else if (clickNo == 2) {
        clickNo = 0;
        clearTimeout(resetId);
        window.close();
      } 
    }
    else
      clickNo = 0;
  }, false);
})();