downthemall/windows/popup.ts
Nils Maier 164aa99eca Initial Chrome support
Part of #35
2019-09-02 18:05:06 +02:00

37 lines
748 B
TypeScript

"use strict";
// License: MIT
import { localize } from "../lib/i18n";
declare let browser: any;
declare let chrome: any;
const runtime = typeof 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("contextmenu", handler);
document.body.addEventListener("click", handler);
});