Skip to content

Commit

Permalink
✨ Remove Sidebar Items
Browse files Browse the repository at this point in the history
  • Loading branch information
PressJump committed Sep 29, 2022
1 parent 64724bf commit 04668bc
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,43 @@ browser.sidebars.add({
isBottom: true,
})

getFromStorage();
getFromStorage().then(createSidebarItems);

async function getFromStorage() {
//get from storage
let sidebaritems = await browser.storage.local.get("sidebaritems");
if (sidebaritems.sidebaritems == undefined) {
sidebaritems.sidebaritems = [];
}
console.log(sidebaritems);
return sidebaritems;
}

async function createSidebarItems(sidebaritems) {
//create sidebar items
for (let i = 0; i < sidebaritems.sidebaritems.length; i++) {
browser.sidebars.add({
title: sidebaritems.sidebaritems[i].title,
iconUrl: sidebaritems.sidebaritems[i].iconUrl,
webviewUrl: sidebaritems.sidebaritems[i].webviewUrl,
});
browser.sidebars.add({
title: sidebaritems.sidebaritems[i].title,
iconUrl: sidebaritems.sidebaritems[i].iconUrl,
webviewUrl: sidebaritems.sidebaritems[i].webviewUrl,
});
}
}

async function removeSidebarItems(itemId)
{
const item = await browser.sidebars.get(itemId);

//remove from storage
let storagearray = await getFromStorage();
let storageitems = storagearray.sidebaritems;

for (let i = 0; i < storageitems.length; i++) {
if (storageitems[i].webviewUrl == item.webviewUrl) {
storageitems.splice(i, 1);
}
}

browser.storage.local.set(storagearray);
}

browser.sidebars.onRemove.addListener((itemId) => {
console.log(itemId);
removeSidebarItems(itemId);
})

0 comments on commit 04668bc

Please sign in to comment.