diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 9b23067..ff76173 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -549,6 +549,26 @@ "description": "Preferences/General", "message": "Add new downloads paused, instead of starting them immediately" }, + "pref_button_type": { + "description": "label", + "message": "DownThemAll! button:" + }, + "pref_button_type_dta": { + "description": "label", + "message": "DownThemAll! selection" + }, + "pref_button_type_manager": { + "description": "label", + "message": "Open Manager" + }, + "pref_button_type_popup": { + "description": "label", + "message": "Popup menu" + }, + "pref_button_type_turbo": { + "description": "label", + "message": "OneClick!" + }, "pref_concurrent_downloads": { "description": "Preferences/Network", "message": "Concurrent downloads" @@ -557,10 +577,6 @@ "description": "Preferences/General", "message": "Show a notification when the queue finishes downloading" }, - "pref_global_turbo": { - "description": "Preferences/General", - "message": "Browser button should be OneClick!" - }, "pref_hide_context": { "description": "Preferences/General", "message": "Do not show general context menu items" diff --git a/data/prefs.json b/data/prefs.json index 2dceb48..4fa81fd 100644 --- a/data/prefs.json +++ b/data/prefs.json @@ -1,5 +1,5 @@ { - "global-turbo": false, + "button-type": "popup", "concurrent": 4, "queue-notification": true, "finish-notification": true, diff --git a/lib/background.ts b/lib/background.ts index e9d983c..d2b2bef 100644 --- a/lib/background.ts +++ b/lib/background.ts @@ -136,35 +136,6 @@ class Handler { } locale.then(() => { - new class Action extends Handler { - constructor() { - super(); - this.onClicked = this.onClicked.bind(this); - action.onClicked.addListener(this.onClicked); - } - - async onClicked(tab: {id: number}) { - if (!tab.id) { - return; - } - try { - await this.processResults( - true, - await runContentJob( - tab, "/bundles/content-gather.js", { - type: "DTA:gather", - selectionOnly: false, - textLinks: await Prefs.get("text-links", true), - schemes: Array.from(ALLOWED_SCHEMES.values()), - transferable: TRANSFERABLE_PROPERTIES, - })); - } - catch (ex) { - console.error(ex); - } - } - }(); - const menuHandler = new class Menus extends Handler { constructor() { super(); @@ -421,7 +392,7 @@ locale.then(() => { } } - async enumulate(action: string) { + async emulate(action: string) { const tab = await tabs.query({ active: true, currentWindow: true, @@ -543,34 +514,88 @@ locale.then(() => { } }(); - Bus.on("do-regular", () => menuHandler.enumulate("DTARegular")); - Bus.on("do-regular-all", () => menuHandler.enumulate("DTARegularAll")); - Bus.on("do-turbo", () => menuHandler.enumulate("DTATurbo")); - Bus.on("do-turbo-all", () => menuHandler.enumulate("DTATurboAll")); + new class Action extends Handler { + constructor() { + super(); + this.onClicked = this.onClicked.bind(this); + action.onClicked.addListener(this.onClicked); + Prefs.get("button-type", false).then(v => this.adjust(v)); + Prefs.on("button-type", (prefs, key, value) => { + this.adjust(value); + }); + } + + adjust(type: string) { + action.setPopup({ + popup: type !== "popup" ? "" : "/windows/popup.html" + }); + let icons; + switch (type) { + case "popup": + icons = { + 16: "/style/icon16.png", + 32: "/style/icon32.png", + 48: "/style/icon48.png", + 64: "/style/icon64.png", + 96: "/style/icon96.png", + 128: "/style/icon128.png", + 256: "/style/icon256.png" + }; + break; + + case "dta": + icons = { + 16: "/style/button-regular.png", + 32: "/style/button-regular@2x.png", + }; + break; + + case "turbo": + icons = { + 16: "/style/button-turbo.png", + 32: "/style/button-turbo@2x.png", + }; + break; + + case "manager": + icons = { + 16: "/style/button-manager.png", + 32: "/style/button-manager@2x.png", + }; + break; + } + action.setIcon({path: icons}); + } + + async onClicked() { + switch (await Prefs.get("button-type")) { + case "popup": + break; + + case "dta": + menuHandler.emulate("DTARegular"); + break; + + case "turbo": + menuHandler.emulate("DTATurbo"); + break; + + case "manager": + menuHandler.emulate("DTAManager"); + break; + } + } + }(); + + + Bus.on("do-regular", () => menuHandler.emulate("DTARegular")); + Bus.on("do-regular-all", () => menuHandler.emulate("DTARegularAll")); + Bus.on("do-turbo", () => menuHandler.emulate("DTATurbo")); + Bus.on("do-turbo-all", () => menuHandler.emulate("DTATurboAll")); Bus.on("do-single", () => API.singleRegular(null)); Bus.on("open-manager", () => openManager(true)); Bus.on("open-prefs", () => openPrefs()); - function adjustAction(globalTurbo: boolean) { - action.setPopup({ - popup: globalTurbo ? "" : "/windows/popup.html" - }); - action.setIcon({ - path: globalTurbo ? { - 16: "/style/button-turbo.png", - 32: "/style/button-turbo@2x.png", - } : { - 16: "/style/icon16.png", - 32: "/style/icon32.png", - 48: "/style/icon48.png", - 64: "/style/icon64.png", - 96: "/style/icon96.png", - 128: "/style/icon128.png", - 256: "/style/icon256.png" - } - }); - } - (async function init() { const urlBase = runtime.getURL(""); history.onVisited.addListener(({url}: {url: string}) => { @@ -610,10 +635,6 @@ locale.then(() => { } await Prefs.set("last-run", new Date()); - Prefs.get("global-turbo", false).then(v => adjustAction(v)); - Prefs.on("global-turbo", (prefs, key, value) => { - adjustAction(value); - }); await filters(); await getManager(); })().catch(ex => { diff --git a/windows/prefs.html b/windows/prefs.html index 21edfba..db1228b 100644 --- a/windows/prefs.html +++ b/windows/prefs.html @@ -43,7 +43,14 @@
UI - +
+ + + + + +
+
diff --git a/windows/prefs.ts b/windows/prefs.ts index 592f378..f9eca55 100644 --- a/windows/prefs.ts +++ b/windows/prefs.ts @@ -554,7 +554,6 @@ addEventListener("DOMContentLoaded", async () => { await localize(document.documentElement); // General - new BoolPref("pref-global-turbo", "global-turbo"); new BoolPref("pref-queue-notification", "queue-notification"); new BoolPref("pref-finish-notification", "finish-notification"); new BoolPref("pref-sounds", "sounds"); @@ -565,6 +564,7 @@ addEventListener("DOMContentLoaded", async () => { new BoolPref("pref-add-paused", "add-paused"); new BoolPref("pref-show-urls", "show-urls"); new BoolPref("pref-remove-missing-on-init", "remove-missing-on-init"); + new OptionPref("pref-button-type", "button-type"); new OptionPref("pref-conflict-action", "conflict-action"); $("#reset-confirmations").addEventListener("click", async () => {