itemremove+buttonadd to functions, button function

This commit is contained in:
Dovi Cowan 2022-07-20 16:53:41 +01:00
parent 564981ecfd
commit 3fbfebb911
Signed by: dcowan
GPG key ID: CC4A4CB950D7E579
2 changed files with 80 additions and 25 deletions

View file

@ -25,18 +25,47 @@ chrome.action.onClicked.addListener(async tab => {
hiddenItemsList = JSON.parse(result.hiddenItemsList);
hiddenItemsList = Object.values(hiddenItemsList);
console.log(hiddenItemsList);
removeItems(hiddenItemsList, tab);
addButton(hiddenItemsList, tab);
});
try {
await chrome.scripting.insertCSS({
target: {
tabId: tab.id,
},
css: `.s-item a.s-item__link { border-style: solid; }`
// try {
// await chrome.scripting.insertCSS({
// target: {
// tabId: tab.id,
// },
// css: `.s-item a.s-item__link { border-style: solid; }`
// });
// } catch (error) {
// console.error('CSS insert failed! ' + error);
// }
});
} catch (error) {
console.error('CSS insert failed! ' + error);
}
// document.getElementsByClassName('ebayitemremover-extension_removeitem').forEach(element => {
// element.addEventListener('click', (elm) => {
// console.log(elm.getAttribute('ebayitemremover-extension_itemid') + ' clicked');
// });
// })
chrome.webNavigation.onCompleted.addListener(function() {
chrome.notifications.create({
"type": "basic",
"iconUrl": "icons/ebay-48.png",
"title": 'eBay Item Remover',
"message": "eBay Item Remover is running - and you've just loaded an eBay page!"
});
}, {
url: [{
urlMatches : 'https://www.ebay.co.uk/'
}]
});
async function removeItems(hiddenItemsList, tab) {
console.log(hiddenItemsList);
console.log(JSON.stringify(hiddenItemsList));
try {
await chrome.scripting.executeScript({
@ -60,7 +89,7 @@ chrome.action.onClicked.addListener(async tab => {
console.log(itemID);
console.log(element.closest('.s-item'));
parent.insertAdjacentHTML('beforeend', '<span class="s-item__watchheart at-corner s-item__watchheart--watch" style="right: 30px; bottom: 10px;"><a aria-label="remove item" href="#"><span class="s-item__watchheart-icon"><svg class="icon icon--save-small" focusable="false" aria-hidden="true"><circle cx="10" cy="9" r="6.5" stroke="black" stroke-width="2" fill="none"></circle></svg><svg class="icon icon--save-selected-small" focusable="false" aria-hidden="true"><use xlink:href="#icon-save-selected-small"></use></svg></span></a></span>')
parent.insertAdjacentHTML('beforeend', '<span class="s-item__watchheart at-corner s-item__watchheart--watch ebayitemremover-extension_removeitem" ebayitemremover-extension_itemid=' + itemID + ' style="right: 30px; bottom: 10px;"><a aria-label="remove item" href="#"><span class="s-item__watchheart-icon"><svg class="icon icon--save-small" focusable="false" aria-hidden="true"><circle cx="10" cy="9" r="6.5" stroke="black" stroke-width="2" fill="none"></circle></svg><svg class="icon icon--save-selected-small" focusable="false" aria-hidden="true"><use xlink:href="#icon-save-selected-small"></use></svg></span></a></span>')
}
});
@ -70,17 +99,43 @@ chrome.action.onClicked.addListener(async tab => {
} catch (error) {
console.error('Get HREFs failed! ' + error);
}
}
async function addButton(hiddenItemsList, tab) {
try {
await chrome.scripting.executeScript({
target: {
tabId: tab.id,
},
args: [ hiddenItemsList ],
func: (hiddenItemsList) => {
Array.from(document.getElementsByClassName('ebayitemremover-extension_removeitem')).forEach(element => {
element.addEventListener('click', (event) => {
let parent = event.target.closest('.ebayitemremover-extension_removeitem');
let itemID = parseInt(parent.getAttribute('ebayitemremover-extension_itemid'));
console.log(itemID + ' clicked');
let sureRemove = confirm('Sure you want to remove this item?');
if(sureRemove) {
hiddenItemsList[hiddenItemsList.length] = itemID;
} else {
event.preventDefault();
return;
}
chrome.storage.sync.set( {'hiddenItemsList': JSON.stringify(hiddenItemsList)}, (parent) => {
parent.innerHTML = "REMOVED BY EBAY ITEM REMOVER";
} );
chrome.webNavigation.onCompleted.addListener(function() {
chrome.notifications.create({
"type": "basic",
"iconUrl": "icons/ebay-48.png",
"title": 'eBay Item Remover',
"message": "eBay Item Remover is running - and you've just loaded an eBay page!"
});
}, {
url: [{
urlMatches : 'https://www.ebay.co.uk/'
}]
event.preventDefault();
});
})
}
}
);
} catch (error) {
console.log("Error adding removal button! " + error);
}
}

View file

@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "eBay Item Remove - DEVELOPMENT BUILD",
"version": "0.0.2",
"version": "0.0.3",
"description": "Remove items you don't want to see from eBay",