From 112d37deb03b734ca9dc3f29e0017d38fb3dd321 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Sun, 25 Aug 2019 14:27:26 +0200 Subject: [PATCH] Reduce load size of popup --- lib/i18n.ts | 14 ++++++++++--- style/popup.css | 48 ------------------------------------------ windows/popup.html | 52 ++++++++++++++++++++++++++++++++++++++++++++-- windows/popup.ts | 6 +++++- 4 files changed, 66 insertions(+), 54 deletions(-) delete mode 100644 style/popup.css diff --git a/lib/i18n.ts b/lib/i18n.ts index 2982438..af0c4fb 100644 --- a/lib/i18n.ts +++ b/lib/i18n.ts @@ -3,12 +3,20 @@ import {memoize} from "./memoize"; + +declare let browser: any; +declare let chrome: any; + function load() { try { // eslint-disable-next-line @typescript-eslint/no-var-requires - const {i18n} = require("webextension-polyfill"); - - return i18n; + if (typeof browser !== "undefined" && browser.i18n) { + return browser.i18n; + } + if (typeof chrome !== "undefined" && chrome.i18n) { + return chrome.i18n; + } + throw new Error("not in a webext"); } catch (ex) { // We might be running under node for tests diff --git a/style/popup.css b/style/popup.css deleted file mode 100644 index 9e59a83..0000000 --- a/style/popup.css +++ /dev/null @@ -1,48 +0,0 @@ -@import url(common.css); - -html { - box-sizing: content-box !important; -} - -ul { - margin: 1.5ex; - margin-right: 2ex; - padding: 0; - display: grid; - grid-template-columns: auto; - list-style-type: none; - min-width: 14em; -} - -li { - display: flex; - margin: 0; - padding: 1ex; - font-size: 110%; - vertical-align: center; - align-items: center; - border-radius: 4px; -} -li.sep { - display: inline-block; - padding: 0; -} - -li:not(.sep):hover { - background: Highlight; - color: HighlightText; -} - -li > .icon, -li > img { - font-size: 16px; - line-height: 16px; - margin-right: 1ex; - width: 16px; - height: 16px; - object-fit: contain; -} - -#single:not(:hover) > .icon-add { - color: var(--add-color); -} \ No newline at end of file diff --git a/windows/popup.html b/windows/popup.html index e756de3..d921742 100644 --- a/windows/popup.html +++ b/windows/popup.html @@ -3,8 +3,56 @@ + @@ -49,4 +97,4 @@ Preferences - + \ No newline at end of file diff --git a/windows/popup.ts b/windows/popup.ts index 5e36e95..e71cdd9 100644 --- a/windows/popup.ts +++ b/windows/popup.ts @@ -2,7 +2,11 @@ // License: MIT import { localize } from "../lib/i18n"; -import { runtime } from "../lib/browser"; + +declare let browser: any; +declare let chrome: any; + +const runtime = browser !== "undefined" ? browser.runtime : chrome.runtime; addEventListener("DOMContentLoaded", () => { localize(document.documentElement);