-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighlightTab.uc.js
More file actions
153 lines (139 loc) · 8.41 KB
/
Copy pathhighlightTab.uc.js
File metadata and controls
153 lines (139 loc) · 8.41 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// ==UserScript==
// @name Double Click Duplicate Tab
// @author Remia
// @version 1.0
// ==/UserScript==
var highlightTab_at_Ulf3000 = {
init: function () {
Services.obs.addObserver(highlightTab_at_Ulf3000.SMObserver, "sessionmanager:restoring-window", false);
window.addEventListener("SSWindowRestored", highlightTab_at_Ulf3000.windowRestore, false); // hack around browser.sessionstore.restore_tabs_lazily
window.document.addEventListener("SSTabRestoring", highlightTab_at_Ulf3000.reHL, false);
let tabbrowser = window.document.getElementById("tabbrowser-tabs");
tabbrowser.onmousedown = highlightTab_at_Ulf3000.clickTab;
highlightTab_at_Ulf3000.createMenu();
},
SMObserver: { //for sesion manager addon
observe: function (aSubject, aTopic, aData) {
alreadyRestored = false;
if (aSubject)
highlightTab_at_Ulf3000.windowRestore(aSubject);
}
},
createMenu: function () {
let menu = document.createXULElement('menu');
menu.setAttribute("id", "highlightTab_at_Ulf3000_Menu");
menu.setAttribute("label", "Highlight Tab(s)");
let menupopup = menu.appendChild(document.createXULElement('menupopup'));
let grid = menupopup.appendChild(document.createXULElement('grid'));
let rows = grid.appendChild(document.createXULElement('rows'));
rows.style.display = "grid";
let row1 = rows.appendChild(document.createXULElement('row'));
let row1i1 = row1.appendChild(document.createXULElement('menuitem'));
row1i1.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#F04F61') }, false);
row1i1.setAttribute('style', 'background : #F04F61 !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row1i2 = row1.appendChild(document.createXULElement('menuitem'));
row1i2.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#f8ada8') }, false);
row1i2.setAttribute('style', 'background : #f8ada8 !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row2 = rows.appendChild(document.createXULElement('row'));
let row2i1 = row2.appendChild(document.createXULElement('menuitem'));
row2i1.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#f48121') }, false);
row2i1.setAttribute('style', 'background : #f48121 !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row2i2 = row2.appendChild(document.createXULElement('menuitem'));
row2i2.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#FAAD5F') }, false);
row2i2.setAttribute('style', 'background : #FAAD5F !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row3 = rows.appendChild(document.createXULElement('row'));
let row3i1 = row3.appendChild(document.createXULElement('menuitem'));
row3i1.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#FFC94D') }, false);
row3i1.setAttribute('style', 'background : #FFC94D !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row3i2 = row3.appendChild(document.createXULElement('menuitem'));
row3i2.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#FFE1A5') }, false);
row3i2.setAttribute('style', 'background : #FFE1A5 !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row4 = rows.appendChild(document.createXULElement('row'));
let row4i1 = row4.appendChild(document.createXULElement('menuitem'));
row4i1.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#A4CF4D') }, false);
row4i1.setAttribute('style', 'background : #A4CF4D !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row4i2 = row4.appendChild(document.createXULElement('menuitem'));
row4i2.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#C5DE92') }, false);
row4i2.setAttribute('style', 'background : #C5DE92 !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row5 = rows.appendChild(document.createXULElement('row'));
let row5i1 = row5.appendChild(document.createXULElement('menuitem'));
row5i1.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#32B0CF') }, false);
row5i1.setAttribute('style', 'background : #32B0CF !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row5i2 = row5.appendChild(document.createXULElement('menuitem'));
row5i2.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#8dcee2') }, false);
row5i2.setAttribute('style', 'background : #8dcee2 !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row6 = rows.appendChild(document.createXULElement('row'));
let row6i1 = row6.appendChild(document.createXULElement('menuitem'));
row6i1.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#8c58a8') }, false);
row6i1.setAttribute('style', 'background : #8c58a8 !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row6i2 = row6.appendChild(document.createXULElement('menuitem'));
row6i2.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#D4B8CF') }, false);
row6i2.setAttribute('style', 'background : #D4B8CF !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row7 = rows.appendChild(document.createXULElement('row'));
let row7i1 = row7.appendChild(document.createXULElement('menuitem'));
row7i1.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#A27D60') }, false);
row7i1.setAttribute('style', 'background : #A27D60 !important;-moz-appearance: unset !important;min-height: 17px !important;');
let row7i2 = row7.appendChild(document.createXULElement('menuitem'));
row7i2.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '#C7B49C') }, false);
row7i2.setAttribute('style', 'background : #C7B49C !important;-moz-appearance: unset !important;min-height: 17px !important;');
let noColorItem = menupopup.appendChild(document.createXULElement('menuitem'));
noColorItem.addEventListener('command', event => { highlightTab_at_Ulf3000.highlightTabFromMenu(event, '') }, false);
noColorItem.setAttribute('label', 'None');
let tabContextMenu = document.getElementById('tabContextMenu');
tabContextMenu.insertBefore(menu, document.getElementById('context_pinTab').nextSibling);
},
windowRestore: function (e) {
for (let tab of gBrowser.tabs) {
highlightTab_at_Ulf3000.reHL2(tab);
}
},
reHL: function (e) { // for SSTabRestoring (session-restore, tab restore, other addons)
//console.log("reHL");
let xxx = SessionStore.getCustomTabValue(e.target, "highlighted_HT");
if (xxx) {
e.target.style.setProperty('background', xxx, "important");
};
},
reHL2: function (tab) { // for SSTabRestoring (session-restore, tab restore, other addons)
//console.log("reHL2");
let xxx = SessionStore.getCustomTabValue(tab, "highlighted_HT");
if (xxx) {
tab.style.setProperty('background', xxx, "important");
};
},
clickTab: function (e) {
//console.log("CLICKTABBBBBBBBBBBBBBBBBB")
//e.preventDefault(); // ToDO ??? still selects the tab
if (e.button == 0 && e.altKey) {
//console.log(e)
let tab = e.target.closest('.tabbrowser-tab');
if (tab) {
highlightTab_at_Ulf3000.highlightTabFromClick(tab, '#C5DE92');
}
}
},
highlightTabFromMenu: function (e, c) {
if (gBrowser.multiSelectedTabsCount > 0) {
console.log("multiSelectedTabsCount");
for (let tab of gBrowser.selectedTabs) {
tab.style.setProperty('background', c, "important");
SessionStore.setCustomTabValue(tab, "highlighted_HT", c);
}
} else {
let tab = TabContextMenu.contextTab;
tab.style.setProperty('background', c, "important");
SessionStore.setCustomTabValue(tab, "highlighted_HT", c);
}
},
highlightTabFromClick: function (node, c) {
//console.log(e)
if (c == '' || c == SessionStore.getCustomTabValue(node, "highlighted_HT")) {
node.style.removeProperty('background');
SessionStore.deleteCustomTabValue(node, "highlighted_HT");
} else {
node.style.setProperty('background', c, "important");
SessionStore.setCustomTabValue(node, "highlighted_HT", c);
}
}
};
highlightTab_at_Ulf3000.init();