diff --git a/README.md b/README.md new file mode 100644 index 0000000..8ede447 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Multi engine Search + +This Firefox extension allows you to use multiple of your installed search engines at once. diff --git a/icons/icon.png b/icons/icon.png new file mode 100644 index 0000000..8a9641d Binary files /dev/null and b/icons/icon.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..d20d02c --- /dev/null +++ b/manifest.json @@ -0,0 +1,24 @@ +{ + + "manifest_version": 2, + "name": "Multi engine search", + "version": "1.0", + + "description": "Search on Multiple search engines.", + "homepage_url": "https://github.com/Javojav/Multi-engine-search", + + "icons": { + "48": "icons/icon.png" + }, + + "permissions": [ + "search" + ], + + "browser_action": { + "default_icon": "icons/icon.png", + "default_title": "Multi engine search", + "default_popup": "popup/search.html" + } + +} diff --git a/popup/search.html b/popup/search.html new file mode 100644 index 0000000..92b30bc --- /dev/null +++ b/popup/search.html @@ -0,0 +1,16 @@ + + + + + + + + +
+ +
+ +
+
+ + diff --git a/popup/search.js b/popup/search.js new file mode 100644 index 0000000..e33b348 --- /dev/null +++ b/popup/search.js @@ -0,0 +1,62 @@ +browser.search.get().then(installedEngines); + +let engineselection = []; + +function search(tab) { + for (selected of engineselection) { + browser.search.search({ + query: document.getElementById("searchbox").value, + engine: selected, + tabId: tab.id + }); + } +} + +browser.browserAction.onClicked.addListener(search); + +function saveselection() { + try { + localStorage.removeItem('defaultengines'); + } catch {} + localStorage.setItem('defaultengines', engineselection); +} + +function installedEngines(engines) { + for (engine of engines) { + let checkbox = document.createElement("INPUT"); + checkbox.type = "checkbox"; + checkbox.setAttribute('value', 'engine ' + engine.name); + try { + let defaultengines = localStorage.getItem('defaultengines').split(","); + for (eng of defaultengines) { + if (engine.name == eng) checkbox.checked = true; + } + } + catch {} + + let label = document.createElement('label'); + label.appendChild(document.createTextNode(engine.name)); + document.getElementById("boxes").appendChild(checkbox); + document.getElementById("boxes").appendChild(label); + + let br = document.createElement("BR"); + document.getElementById("boxes").appendChild(br) + } +} + +document.addEventListener("click", (e) => { + engineselection = []; + for (engine of document.getElementsByTagName('INPUT')) { + if (engine.value.includes("engine") && engine.checked) engineselection.push(engine.value.slice(7)); + } + if (e.target.classList.contains("search")) { + browser.tabs.query({active: true, currentWindow: true}) + .then(search); + } else if (e.target.classList.contains("default")) { + browser.tabs.query({active: true, currentWindow: true}) + .then(saveselection); + } else if (e.target.classList.contains("image")) { + browser.tabs.query({active: true, currentWindow: true}) + .then(searchimage); + } +});