I'm having trouble in letting an extension open links in chrome tab, and filter it by some class inner text. I want it to open all the links that starts with 'http://www.ebay.com/usr/', and after that filter the open windows by class "mem_loc" if it's innerText is for example "United States" (then close it). Else, If it's false, I want it to get the href attribute of button id="AnalyzeLink" and open it.
manifest.json:
{
"name": "Asaf's Extension",
"version": "1.0",
"manifest_version": 2,
"description": "Asaf's ZIK Extension",
"permissions": [
"<all_urls>", "tabs", "activeTab"
],
"background": {
"matches": [ "*://*.zikanalytics.com/Analyze/Index/*" ],
"scripts" : [ "event.js" ],
"persistent": false
},
"browser_action": {
"default_icon": "icon.png"
},
"content_scripts": [
{
"matches": [ "*://*.ebay.com/usr/*" ],
"css": [ "ebayButton.css" ],
"js": [ "ebayButton.js" ],
"run_at": "document_end"
},
{
"matches": [ "*://*.zikanalytics.com/Analyze/Index/*" ],
"css": [ "ZIKeyword.css" ],
"js": [ "ZIKeyword.js" ],
"persistent": false
}
]
}
event.js:
chrome.browserAction.onClicked.addListener(sellersList);
function sellersList(tab) {
chrome.tabs.executeScript(tab.id, {file: 'sellersList.js'}, results => {
results[0].forEach(openSeller);
});
}
function openSeller(url) {
chrome.tabs.create({url, pinned: true, active: true}, collectCountry);
}
function collectCountry(tab) {
chrome.tabs.executeScript(tab.id, {file: 'collectCountry.js'}, results => {
chrome.tabs.remove(tab.id);
results[0].forEach(analyzeSeller);
});
}
function analyzeSeller(url) {
chrome.tabs.create({url, active: false});
}
sellersList.js:
let urls = [...document.links]
.filter(a => a.href.startsWith('http://www.ebay.com/usr/'))
.map(a => a.href);
[...new Set(urls)];
collectCountry.js:
[...document.getElementsByClassName("mem_loc")]
.filter(a => a.textContent.trim().endsWith('s'))
.map(a=> document.URL)
It's opening the links, and filter them, but I don't know how to save the previous url if it finds a match, so it will open it later.
Thanks in advance! :)