popup: handle right click too
This commit is contained in:
parent
b4ce2d1d75
commit
256c091f15
@ -8,23 +8,27 @@ declare let chrome: any;
|
||||
|
||||
const runtime = browser !== "undefined" ? browser.runtime : chrome.runtime;
|
||||
|
||||
function handler(e: Event) {
|
||||
e.preventDefault();
|
||||
let target = e.target as HTMLElement;
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
while (target) {
|
||||
const {action} = target.dataset;
|
||||
if (!action) {
|
||||
target = target.parentElement as HTMLElement;
|
||||
continue;
|
||||
}
|
||||
runtime.sendMessage(action);
|
||||
close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
addEventListener("DOMContentLoaded", () => {
|
||||
localize(document.documentElement);
|
||||
|
||||
document.body.addEventListener("click", e => {
|
||||
let target = e.target as HTMLElement;
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
while (target) {
|
||||
const {action} = target.dataset;
|
||||
if (!action) {
|
||||
target = target.parentElement as HTMLElement;
|
||||
continue;
|
||||
}
|
||||
runtime.sendMessage(action);
|
||||
close();
|
||||
return;
|
||||
}
|
||||
});
|
||||
document.body.addEventListener("contextmenu", handler);
|
||||
document.body.addEventListener("click", handler);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user