Skip to content

Commit

Permalink
fix save search button
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Jul 19, 2022
1 parent bd2fd05 commit f560322
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions layouts/search/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,15 +918,28 @@ async function updateSavedButton() {
if(saved) {
document.getElementById('save-search').innerText = "Remove from saved";
document.getElementById('save-search').classList.add('saved');
} else {
document.getElementById('save-search').innerText = "Save search";
document.getElementById('save-search').classList.remove('saved');
}
document.getElementById('save-search').addEventListener('click', async () => {
if(saved) {
await API.deleteSavedSearch(saved.id_str);
document.getElementById('save-search').innerText = "Save search";
document.getElementById('save-search').classList.remove('saved');
savedSearches = savedSearches.filter(s => s.id_str !== saved.id_str);
chrome.storage.local.set({savedSearches: {
date: Date.now(),
data: savedSearches
}}, () => {});
saved = undefined;
} else {
let saveData = await API.saveSearch(searchParams.q);
savedSearches.push(saveData);
chrome.storage.local.set({savedSearches: {
date: Date.now(),
data: savedSearches
}}, () => {});
saved = saveData;
document.getElementById('save-search').innerText = "Remove from saved";
document.getElementById('save-search').classList.add('saved');
Expand Down

0 comments on commit f560322

Please sign in to comment.