moved getting hiddenItemsList to async function

This commit is contained in:
Dovi Cowan 2022-07-20 17:17:44 +01:00
parent 3fbfebb911
commit 7caa357e35
Signed by: dcowan
GPG key ID: CC4A4CB950D7E579

View file

@ -21,15 +21,11 @@ chrome.runtime.onInstalled.addListener(function(details) {
chrome.action.onClicked.addListener(async tab => { chrome.action.onClicked.addListener(async tab => {
var hiddenItemsList; var hiddenItemsList;
chrome.storage.sync.get(['hiddenItemsList'], function(result) { hiddenItemsList = await getHiddenItemsList();
hiddenItemsList = JSON.parse(result.hiddenItemsList);
hiddenItemsList = Object.values(hiddenItemsList);
console.log(hiddenItemsList);
removeItems(hiddenItemsList, tab); await removeItems();
addButton(hiddenItemsList, tab); addButton();
});
// try { // try {
// await chrome.scripting.insertCSS({ // await chrome.scripting.insertCSS({
@ -62,10 +58,28 @@ chrome.webNavigation.onCompleted.addListener(function() {
}] }]
}); });
async function removeItems(hiddenItemsList, tab) { const getHiddenItemsList = async () => {
var hiddenItemsList;
return new Promise((resolve, reject) => {
chrome.storage.sync.get(['hiddenItemsList'], async (result) => {
hiddenItemsList = JSON.parse(result.hiddenItemsList);
hiddenItemsList = Object.values(hiddenItemsList);
resolve(hiddenItemsList);
});
});
console.log(hiddenItemsList); console.log(hiddenItemsList);
console.log(JSON.stringify(hiddenItemsList)); return hiddenItemsList;
}
async function removeItems() {
let queryOptions = { active: true, lastFocusedWindow: true };
let [tab] = await chrome.tabs.query(queryOptions);
let hiddenItemsList = await getHiddenItemsList();
try { try {
await chrome.scripting.executeScript({ await chrome.scripting.executeScript({
@ -101,7 +115,12 @@ async function removeItems(hiddenItemsList, tab) {
} }
} }
async function addButton(hiddenItemsList, tab) { async function addButton() {
let queryOptions = { active: true, lastFocusedWindow: true };
let [tab] = await chrome.tabs.query(queryOptions);
let hiddenItemsList = await getHiddenItemsList();
try { try {
await chrome.scripting.executeScript({ await chrome.scripting.executeScript({
target: { target: {
@ -126,7 +145,8 @@ async function addButton(hiddenItemsList, tab) {
} }
chrome.storage.sync.set( {'hiddenItemsList': JSON.stringify(hiddenItemsList)}, (parent) => { chrome.storage.sync.set( {'hiddenItemsList': JSON.stringify(hiddenItemsList)}, (parent) => {
parent.innerHTML = "REMOVED BY EBAY ITEM REMOVER"; // parent.innerHTML = "REMOVED BY EBAY ITEM REMOVER";
} ); } );
event.preventDefault(); event.preventDefault();