diff --git a/windows/popup.ts b/windows/popup.ts index e71cdd9..a5e7863 100644 --- a/windows/popup.ts +++ b/windows/popup.ts @@ -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); });