remove-ebay-items/background-script.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-07-20 00:46:09 +01:00
/* chrome.browserAction.onClicked.addListener(function () {
console.log("Test");
// let title = browser.i18n.getMessage("notificationTitle");
// let content = browser.i18n.getMessage("notificationContent", message.url);
}) */
chrome.action.onClicked.addListener(async tab => {
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);
}
try {
await chrome.scripting.executeScript({
target: {
tabId: tab.id,
},
func: () => {
document.querySelectorAll('.s-item a.s-item__link').forEach(element => {
let href = element.getAttribute('href');
href = href.split('/');
let itemID = href[href.length-1].split('?')[0];
console.log(itemID);
});
}
});
} catch (error) {
console.error('Get HREFs failed! ' + error);
}
});
chrome.webNavigation.onCompleted.addListener(function() {
chrome.notifications.create({
"type": "basic",
"iconUrl": "icons/ebay-48.png",
"title": 'My Notification',
"message": 'Hi, this is eBay!'
});
}, {
url: [{
urlMatches : 'https://www.ebay.co.uk/'
}]
});