Add files

This commit is contained in:
Javojav 2019-05-06 15:20:28 +02:00
parent 9f7797e8df
commit 5934d96e8d
5 changed files with 105 additions and 0 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# Multi engine Search
This Firefox extension allows you to use multiple of your installed search engines at once.

BIN
icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

24
manifest.json Normal file
View File

@ -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"
}
}

16
popup/search.html Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<input type="text" id="searchbox" placeholder="Search"/>
<button type="button" class="search button">Search</button>
<br/>
<script src="search.js"></script>
<div id="boxes">
<button type="button" class="save default">Save selection as default</button>
<br/>
</div>
</body>
</html>

62
popup/search.js Normal file
View File

@ -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);
}
});