popup: handle right click too

This commit is contained in:
Nils Maier 2019-08-26 20:40:20 +02:00
parent b4ce2d1d75
commit 256c091f15

View File

@ -8,23 +8,27 @@ declare let chrome: any;
const runtime = browser !== "undefined" ? browser.runtime : chrome.runtime; 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", () => { addEventListener("DOMContentLoaded", () => {
localize(document.documentElement); localize(document.documentElement);
document.body.addEventListener("click", e => { document.body.addEventListener("contextmenu", handler);
let target = e.target as HTMLElement; document.body.addEventListener("click", handler);
if (!target) {
return;
}
while (target) {
const {action} = target.dataset;
if (!action) {
target = target.parentElement as HTMLElement;
continue;
}
runtime.sendMessage(action);
close();
return;
}
});
}); });