diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3d041a6 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +default: all + +all: popup + +clean: + rm pages/popup.js + +popup: + cat common.js pages/popup.src.js > pages/popup.js diff --git a/common.js b/common.js new file mode 100644 index 0000000..4e16e34 --- /dev/null +++ b/common.js @@ -0,0 +1,21 @@ +// Saves a search-group of the given `name`, containing all search-engines of +// `preset` (which is an array of search-engine display-names truncated to 7 chars). +function savepreset(preset, name) { + let presets = Array(); + let presetName = name.replace(',', ' '); + try { presets = localStorage.getItem('presets').split(','); } catch {} + + try { localStorage.removeItem('preset_' + presetName); } catch {} + + presets = removefromarray(removeredundantitems(presets), presetName); + presets.push(presetName); + + localStorage.setItem('preset_' + presetName, preset); + localStorage.setItem('presets', presets); +} + + +// Load an array of all saved preset's names. +function loadpresets() { + try { return localStorage.getItem('presets').split(','); } catch { return []; } +} diff --git a/manifest.json b/manifest.json index 4b91cc6..f4a4d30 100644 --- a/manifest.json +++ b/manifest.json @@ -2,18 +2,21 @@ "manifest_version": 2, "name": "Multi engine search", - "version": "1.1", + "version": "1.2", - "description": "Search on Multiple search engines.", - "homepage_url": "https://github.com/Javojav/Multi-engine-search", + "description": "Search with multiple search engines simultaneously.", + "homepage_url": "https://notabug.org/jadedctrl/octosearch", "icons": { "48": "icons/icon.png" }, - "permissions": [ - "search" - ], + "permissions": [ + "search", + "webRequest", + "webRequestBlocking", + "*://octosearch.invalid/*" + ], "commands": { "_execute_browser_action": { @@ -25,8 +28,14 @@ "browser_action": { "default_icon": "icons/icon.png", - "default_title": "Multi engine search", + "default_title": "OctoSearch", "default_popup": "pages/popup.html" + }, + + "background": { + "scripts": [ + "background.js" + ] } } diff --git a/pages/popup.js b/pages/popup.src.js similarity index 84% rename from pages/popup.js rename to pages/popup.src.js index cc1312e..b36989a 100644 --- a/pages/popup.js +++ b/pages/popup.src.js @@ -19,8 +19,7 @@ const populateengines = (engines) => { const populatepresets = () => { let presetDropdown = document.getElementById("presets"); - let presets = Array(); - try { presets = localStorage.getItem('presets').split(','); } catch {} + let presets = loadpresets() while (presetDropdown.firstChild) { presetDropdown.removeChild(presetDropdown.lastChild); @@ -71,25 +70,6 @@ const enablepreset = (preset) => { } } -const savepreset = (preset, name) => { - let presets = Array(); - let presetName = name.replace(',', ' '); - try { presets = localStorage.getItem('presets').split(','); } catch {} - - try { localStorage.removeItem('preset_' + presetName); } catch {} - - presets = removefromarray(removeredundantitems(presets), presetName); - presets.push(presetName); - - localStorage.setItem('preset_' + presetName, preset); - localStorage.setItem('presets', presets); - - // Update UI & listed presets - resetsearchbox(true); - populatepresets(); - enablepresetbyname(name); -} - const removecurrentpreset = () => { let presetName = document.getElementById("presets").value; if (presetName == "noPreset" || presetName == "newPreset") @@ -138,13 +118,17 @@ const engineselection = () => { } const saveselection = () => { - let textbox = document.getElementById("searchbox"); - let selection = document.getElementById("presets").value; - let name = selection; + let textbox = document.getElementById("searchbox"); + let selection = document.getElementById("presets").value; + let name = selection; - if (selection == "newPreset") - name = textbox.value; - savepreset(engineselection(), name); + if (selection == "newPreset") + name = textbox.value; + savepreset(engineselection(), name); + // Update UI & listed presets + resetsearchbox(true); + populatepresets(); + enablepresetbyname(name); } const onpresetselected = (event) => {