-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathright_click_close_tab.uc.js
executable file
·41 lines (31 loc) · 1.09 KB
/
right_click_close_tab.uc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Firefox userChrome script
* Right-clicking on tab button to close tab
* Shift + right-clicking to popup menu
* Tested on Firefox 91
* Author: garywill (https://garywill.github.io)
*/
// ==UserScript==
// @include main
// ==/UserScript==
console.log("right_click_close_tab.js");
(() => {
gBrowser.tabContainer.addEventListener("TabOpen", eventTabAdded, false);
function eventTabAdded(event) {
var tab = event.target;
tab.addEventListener('click', onTabEvent);
tab.addEventListener('contextmenu', onTabEvent);
}
function onTabEvent(event) {
//console.log(event.type);
if (event.button != 2 || event.shiftKey )
return;
event.preventDefault();
event.stopPropagation();
if (event.type == 'click')
gBrowser.removeTab(this, {animate: true});
}
gBrowser.tabContainer.querySelectorAll('tab').forEach( function(tab, index) {
tab.addEventListener('click', onTabEvent);
tab.addEventListener('contextmenu', onTabEvent);
});
})();