itemremove+buttonadd to functions, button function
This commit is contained in:
parent
564981ecfd
commit
3fbfebb911
2 changed files with 80 additions and 25 deletions
|
@ -25,18 +25,47 @@ chrome.action.onClicked.addListener(async tab => {
|
||||||
hiddenItemsList = JSON.parse(result.hiddenItemsList);
|
hiddenItemsList = JSON.parse(result.hiddenItemsList);
|
||||||
hiddenItemsList = Object.values(hiddenItemsList);
|
hiddenItemsList = Object.values(hiddenItemsList);
|
||||||
console.log(hiddenItemsList);
|
console.log(hiddenItemsList);
|
||||||
|
|
||||||
|
removeItems(hiddenItemsList, tab);
|
||||||
|
|
||||||
|
addButton(hiddenItemsList, tab);
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
await chrome.scripting.insertCSS({
|
// await chrome.scripting.insertCSS({
|
||||||
target: {
|
// target: {
|
||||||
tabId: tab.id,
|
// tabId: tab.id,
|
||||||
},
|
// },
|
||||||
css: `.s-item a.s-item__link { border-style: solid; }`
|
// css: `.s-item a.s-item__link { border-style: solid; }`
|
||||||
|
// });
|
||||||
|
// } 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!"
|
||||||
});
|
});
|
||||||
} catch (error) {
|
}, {
|
||||||
console.error('CSS insert failed! ' + error);
|
url: [{
|
||||||
}
|
urlMatches : 'https://www.ebay.co.uk/'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
async function removeItems(hiddenItemsList, tab) {
|
||||||
|
console.log(hiddenItemsList);
|
||||||
|
|
||||||
|
console.log(JSON.stringify(hiddenItemsList));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await chrome.scripting.executeScript({
|
await chrome.scripting.executeScript({
|
||||||
|
@ -60,7 +89,7 @@ chrome.action.onClicked.addListener(async tab => {
|
||||||
console.log(itemID);
|
console.log(itemID);
|
||||||
console.log(element.closest('.s-item'));
|
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) {
|
} catch (error) {
|
||||||
console.error('Get HREFs failed! ' + error);
|
console.error('Get HREFs failed! ' + error);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
chrome.webNavigation.onCompleted.addListener(function() {
|
async function addButton(hiddenItemsList, tab) {
|
||||||
chrome.notifications.create({
|
try {
|
||||||
"type": "basic",
|
await chrome.scripting.executeScript({
|
||||||
"iconUrl": "icons/ebay-48.png",
|
target: {
|
||||||
"title": 'eBay Item Remover',
|
tabId: tab.id,
|
||||||
"message": "eBay Item Remover is running - and you've just loaded an eBay page!"
|
},
|
||||||
|
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";
|
||||||
|
} );
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
}, {
|
})
|
||||||
url: [{
|
}
|
||||||
urlMatches : 'https://www.ebay.co.uk/'
|
}
|
||||||
}]
|
);
|
||||||
});
|
} catch (error) {
|
||||||
|
console.log("Error adding removal button! " + error);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "eBay Item Remove - DEVELOPMENT BUILD",
|
"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",
|
"description": "Remove items you don't want to see from eBay",
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue