From 256c091f1582beb00aa0e66d40ab3830c59c3059 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Mon, 26 Aug 2019 20:40:20 +0200 Subject: [PATCH] popup: handle right click too --- windows/popup.ts | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) 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); });