Right Open & Close

RClick open link, Double RClick close tab

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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