forked from ywzhaiqi/userChromeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabFocus.uc.js
53 lines (47 loc) · 1.66 KB
/
TabFocus.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
42
43
44
45
46
47
48
49
50
51
52
53
// ==UserScript==
// @name TabFocus.uc.js
// @startup window.tab_hover.onLoad();
// @shutdown window.tab_hover.onUnload();
// @version 2014.8.23
// @note 修改为无需重启的方式
// ==/UserScript==
if (window.tab_hover) {
window.tab_hover.onUnload();
delete window.tab_hover;
}
window.tab_hover = {
delay: 150,
event: null,
tid: null,
onLoad: function() {
gBrowser.tabContainer.addEventListener("mouseout", tab_hover.onMouseOut, false);
gBrowser.tabContainer.addEventListener("mouseover", tab_hover.onMouseOver, false);
// 右键点击则暂停 focus,但由于点击的相应时间问题,可能会更混乱
// gBrowser.tabContainer.addEventListener("click", tab_hover.onMouseClicked, false);
},
onUnload: function() {
gBrowser.tabContainer.removeEventListener("mouseover", tab_hover.onMouseOver, false);
gBrowser.tabContainer.removeEventListener("mouseout", tab_hover.onMouseOut, false);
// gBrowser.tabContainer.removeEventListener("click", tab_hover.onMouseClicked, false);
},
onMouseOver: function(event) {
tab_hover.event = event.target;
tab_hover.tid = setTimeout(function() {
gBrowser.selectedTab = tab_hover.event;
tab_hover.event=null;
}, tab_hover.delay);
},
onMouseOut: function() {
if (tab_hover.tid) {
clearTimeout(tab_hover.tid);
tab_hover.tid = null;
}
},
onMouseClicked: function() {
if (tab_hover.tid) {
clearTimeout(tab_hover.tid);
tab_hover.tid = null;
}
},
};
tab_hover.onLoad();