added keyboard shortcuts and improved code
This commit is contained in:
parent
3ec81347c2
commit
7b93a67ec0
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Multi engine search",
|
"name": "Multi engine search",
|
||||||
"version": "1.0",
|
"version": "1.1",
|
||||||
|
|
||||||
"description": "Search on Multiple search engines.",
|
"description": "Search on Multiple search engines.",
|
||||||
"homepage_url": "https://github.com/Javojav/Multi-engine-search",
|
"homepage_url": "https://github.com/Javojav/Multi-engine-search",
|
||||||
|
@ -15,6 +15,14 @@
|
||||||
"search"
|
"search"
|
||||||
],
|
],
|
||||||
|
|
||||||
|
"commands": {
|
||||||
|
"_execute_browser_action": {
|
||||||
|
"suggested_key": {
|
||||||
|
"default": "Ctrl+Shift+L"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_icon": "icons/icon.png",
|
"default_icon": "icons/icon.png",
|
||||||
"default_title": "Multi engine search",
|
"default_title": "Multi engine search",
|
||||||
|
|
|
@ -1,27 +1,6 @@
|
||||||
browser.search.get().then(installedEngines);
|
document.getElementById("searchbox").focus();
|
||||||
|
|
||||||
let engineselection = [];
|
browser.search.get().then(engines => {
|
||||||
|
|
||||||
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) {
|
for (engine of engines) {
|
||||||
let checkbox = document.createElement("INPUT");
|
let checkbox = document.createElement("INPUT");
|
||||||
checkbox.type = "checkbox";
|
checkbox.type = "checkbox";
|
||||||
|
@ -31,32 +10,49 @@ function installedEngines(engines) {
|
||||||
for (eng of defaultengines) {
|
for (eng of defaultengines) {
|
||||||
if (engine.name == eng) checkbox.checked = true;
|
if (engine.name == eng) checkbox.checked = true;
|
||||||
}
|
}
|
||||||
}
|
} catch {}
|
||||||
catch {}
|
|
||||||
|
|
||||||
let label = document.createElement('label');
|
let label = document.createElement('label');
|
||||||
label.appendChild(document.createTextNode(engine.name));
|
label.appendChild(document.createTextNode(engine.name));
|
||||||
document.getElementById("boxes").appendChild(checkbox);
|
document.getElementById("boxes").appendChild(checkbox);
|
||||||
document.getElementById("boxes").appendChild(label);
|
document.getElementById("boxes").appendChild(label);
|
||||||
|
document.getElementById("boxes").appendChild(document.createElement("BR"))
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const search = tab => {
|
||||||
|
browser.tabs.query({active: true, currentWindow: true})
|
||||||
|
.then(() => {
|
||||||
|
for (selected of engineselection()) {
|
||||||
|
browser.search.search({
|
||||||
|
query: document.getElementById("searchbox").value,
|
||||||
|
engine: selected,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const engineselection = () => {
|
||||||
|
let selection = [];
|
||||||
|
for (engine of document.getElementsByTagName('INPUT')) {
|
||||||
|
if (engine.value.includes("engine") && engine.checked) selection.push(engine.value.slice(7));
|
||||||
|
}
|
||||||
|
return selection;
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveselection = () => {
|
||||||
|
try {
|
||||||
|
localStorage.removeItem('defaultengines');
|
||||||
|
} catch {}
|
||||||
|
localStorage.setItem('defaultengines', engineselection());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
document.getElementById("searchbox").addEventListener("keypress", key => {
|
||||||
|
if (event.key == "Enter") search();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener("click", e => {
|
||||||
|
if (e.target.classList.contains("search")) search();
|
||||||
|
else if (e.target.classList.contains("default")) saveselection();
|
||||||
|
});
|
||||||
|
|
Ŝarĝante…
Reference in New Issue