2019-05-08 12:45:21 -05:00
|
|
|
document.getElementById("searchbox").focus();
|
2019-05-06 08:20:28 -05:00
|
|
|
|
2019-05-08 12:45:21 -05:00
|
|
|
browser.search.get().then(engines => {
|
2019-05-06 08:20:28 -05:00
|
|
|
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;
|
|
|
|
}
|
2019-05-08 12:45:21 -05:00
|
|
|
} catch {}
|
2019-05-06 08:20:28 -05:00
|
|
|
let label = document.createElement('label');
|
|
|
|
label.appendChild(document.createTextNode(engine.name));
|
|
|
|
document.getElementById("boxes").appendChild(checkbox);
|
|
|
|
document.getElementById("boxes").appendChild(label);
|
2019-05-08 12:45:21 -05:00
|
|
|
document.getElementById("boxes").appendChild(document.createElement("BR"))
|
2019-05-06 08:20:28 -05:00
|
|
|
}
|
2019-05-08 12:45:21 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2019-05-06 08:20:28 -05:00
|
|
|
}
|
|
|
|
|
2019-05-08 12:45:21 -05:00
|
|
|
const engineselection = () => {
|
|
|
|
let selection = [];
|
2019-05-06 08:20:28 -05:00
|
|
|
for (engine of document.getElementsByTagName('INPUT')) {
|
2019-05-08 12:45:21 -05:00
|
|
|
if (engine.value.includes("engine") && engine.checked) selection.push(engine.value.slice(7));
|
2019-05-06 08:20:28 -05:00
|
|
|
}
|
2019-05-08 12:45:21 -05:00
|
|
|
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();
|
2019-05-06 08:20:28 -05:00
|
|
|
});
|