-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpanel-doubleclick-automation.js
45 lines (41 loc) · 1.4 KB
/
panel-doubleclick-automation.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
// Panel doubleclick automation
// https://forum.vivaldi.net/post/391224
// Switches the tab or opens a bookmark by simulating a doubleclick on a tab or a bookmark, in the windows or bookmark panel.
{
function doClick(event) {
event.stopPropagation();
event.preventDefault();
var ev = document.createEvent("MouseEvents");
ev.initEvent("dblclick", true, true);
this.parentNode.dispatchEvent(ev);
}
function checkParents(el, sel) {
while (el.parentNode) {
el = el.parentNode;
if (el.id === sel[0]) {
return win;
} else if (el.classList !== undefined && el.classList.contains(sel[1])) {
return book;
}
}
return null;
}
// Set win to 0 or 1 for either triggering the doubleclick on favicon, or window title.
// Set book to 0 or 1 for either triggering the doubleclick on favicon, or bookmark title.
const win = 1;
const book = 1;
var appendChild = Element.prototype.appendChild;
Element.prototype.appendChild = function () {
if (this.tagName === "LABEL" && arguments[0].tagName === "IMG") {
setTimeout(
function () {
var check = checkParents(this, ["window-panel", "panel-bookmarks"]);
if (check === 0 || check === 1) {
this.childNodes[check].addEventListener("click", doClick);
}
}.bind(this, arguments[0])
);
}
return appendChild.apply(this, arguments);
};
}