From 2030e18b821da1aa164663a7506d41d5a2ad6523 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Tue, 9 Jun 2020 23:08:05 +0800 Subject: [PATCH] fix: should match all images --- common_content_script.js | 12 ++++++++---- popup.html | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/common_content_script.js b/common_content_script.js index 8011c6b..48bdf5b 100644 --- a/common_content_script.js +++ b/common_content_script.js @@ -1,13 +1,17 @@ function getElementByXpath(path) { - return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + return document.evaluate(path, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); } chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { if (request.action == "requestPics") { // TODO: check url, use different match rule to return data. - let a = getElementByXpath("//article[contains(@role,'article')][1]//a[contains(@href,'/photo/')]//img/@src"); - console.log(a); - sendResponse({dateType: 'urlList', urlList: a}); + let a = getElementByXpath("(//article[contains(@role,'article')])[1]//a[contains(@href,'/photo/')]//img/@src"); + let arr = []; + for (i=0; i - +