0

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! :)

Asaf Kfir
  • 129
  • 2
  • 9
  • 1
    `It's not even opening the first links for me` The code you're using should be started by clicking your extension icon, it doesn't do anything for you otherwise. – wOxxOm Mar 29 '17 at 20:57
  • What *exactly* is shown in the [various appropriate consoles for your extension](http://stackoverflow.com/a/38920982/3773011) when you load and execute your extension? – Makyen Mar 29 '17 at 23:55
  • It works great now after a couple of changes.. added matches in the background code and i believe it solved it. – Asaf Kfir Mar 30 '17 at 13:30

0 Answers0