Deleting of engine presets
Adds a "Delete" button for removing an engine preset
This commit is contained in:
parent
db7f5b4b9b
commit
ccd196dabc
|
@ -8,10 +8,13 @@
|
||||||
<button type="button" class="search button">Search</button>
|
<button type="button" class="search button">Search</button>
|
||||||
<br/>
|
<br/>
|
||||||
<script src="search.js"></script>
|
<script src="search.js"></script>
|
||||||
|
<div>
|
||||||
<select id="presets">
|
<select id="presets">
|
||||||
</select>
|
</select>
|
||||||
|
<button type="button" class="save">Save</button>
|
||||||
|
<button type="button" class="remove">Delete</button>
|
||||||
|
</div>
|
||||||
<div id="boxes">
|
<div id="boxes">
|
||||||
<button type="button" class="save default">Save preset</button>
|
|
||||||
<br/>
|
<br/>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -78,16 +78,11 @@ const savepreset = (preset, name) => {
|
||||||
|
|
||||||
try { localStorage.removeItem('preset_' + presetName); } catch {}
|
try { localStorage.removeItem('preset_' + presetName); } catch {}
|
||||||
|
|
||||||
let sanitizedPresets = presets.filter((thisName, i) =>
|
presets = removefromarray(removeredundantitems(presets), presetName);
|
||||||
{
|
presets.push(presetName);
|
||||||
return (presets.indexOf(thisName) === i)
|
|
||||||
&& (thisName != name);
|
|
||||||
});
|
|
||||||
|
|
||||||
sanitizedPresets.push(presetName);
|
|
||||||
|
|
||||||
localStorage.setItem('preset_' + presetName, preset);
|
localStorage.setItem('preset_' + presetName, preset);
|
||||||
localStorage.setItem('presets', sanitizedPresets);
|
localStorage.setItem('presets', presets);
|
||||||
|
|
||||||
// Update UI & listed presets
|
// Update UI & listed presets
|
||||||
resetsearchbox(true);
|
resetsearchbox(true);
|
||||||
|
@ -95,11 +90,28 @@ const savepreset = (preset, name) => {
|
||||||
enablepresetbyname(name);
|
enablepresetbyname(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const removecurrentpreset = () => {
|
||||||
|
let presetName = document.getElementById("presets").value;
|
||||||
|
if (presetName == "noPreset" || presetName == "newPreset")
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let presets = localStorage.getItem('presets').split(',');
|
||||||
|
localStorage.removeItem('preset_' + presetName);
|
||||||
|
localStorage.setItem('presets', removefromarray(presets, presetName));
|
||||||
|
}
|
||||||
|
catch {}
|
||||||
|
|
||||||
|
deselectengines();
|
||||||
|
populatepresets();
|
||||||
|
document.getElementById("presets").value = "noPreset";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Search-box is also used for setting the name of new
|
// Search-box is also used for setting the name of new
|
||||||
// presets; this sets the placeholder accordingly
|
// presets; this sets the placeholder accordingly
|
||||||
const searchboxaspresetname = () => {
|
const searchboxaspresetname = () => {
|
||||||
let textbox = document.getElementById("searchbox");
|
let textbox = document.getElementById("searchbox");
|
||||||
textbox.focus();
|
|
||||||
textbox.setAttribute("placeholder", "New preset name…");
|
textbox.setAttribute("placeholder", "New preset name…");
|
||||||
deselectengines();
|
deselectengines();
|
||||||
}
|
}
|
||||||
|
@ -145,6 +157,22 @@ const onpresetselected = (value) => {
|
||||||
searchboxaspresetname();
|
searchboxaspresetname();
|
||||||
else
|
else
|
||||||
enablepresetbyname(value);
|
enablepresetbyname(value);
|
||||||
|
|
||||||
|
document.getElementById("searchbox").focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
const removefromarray = (array, item) => {
|
||||||
|
return array.filter((testItem, index) =>
|
||||||
|
{
|
||||||
|
return testItem != item;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeredundantitems = (array) => {
|
||||||
|
return array.filter((item, index) =>
|
||||||
|
{
|
||||||
|
return (array.indexOf(item) === index);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.search.get().then(populateengines);
|
browser.search.get().then(populateengines);
|
||||||
|
@ -156,8 +184,10 @@ document.getElementById("searchbox").addEventListener("keypress", key => {
|
||||||
document.addEventListener("click", e => {
|
document.addEventListener("click", e => {
|
||||||
if (e.target.classList.contains("search"))
|
if (e.target.classList.contains("search"))
|
||||||
search();
|
search();
|
||||||
else if (e.target.classList.contains("default"))
|
else if (e.target.classList.contains("save"))
|
||||||
saveselection();
|
saveselection();
|
||||||
|
else if (e.target.classList.contains("remove"))
|
||||||
|
removecurrentpreset();
|
||||||
else if (e.target.tagName == "OPTION") {
|
else if (e.target.tagName == "OPTION") {
|
||||||
onpresetselected(e.target.getAttribute("value"));
|
onpresetselected(e.target.getAttribute("value"));
|
||||||
}
|
}
|
||||||
|
|
Ŝarĝante…
Reference in New Issue