2020-06-09 21:27:28 +08:00
|
|
|
function getElementByXpath(path) {
|
2020-06-09 23:08:05 +08:00
|
|
|
return document.evaluate(path, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
2020-06-09 21:27:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
|
|
|
|
if (request.action == "requestPics") {
|
|
|
|
// TODO: check url, use different match rule to return data.
|
2020-06-09 23:08:05 +08:00
|
|
|
let a = getElementByXpath("(//article[contains(@role,'article')])[1]//a[contains(@href,'/photo/')]//img/@src");
|
|
|
|
let arr = [];
|
|
|
|
for (i=0; i<a.snapshotLength; i++) {
|
|
|
|
arr.push(a.snapshotItem(i).textContent);
|
|
|
|
}
|
|
|
|
// console.log(arr);
|
|
|
|
sendResponse({dateType: 'urlList', urlList: arr});
|
2020-06-09 21:27:28 +08:00
|
|
|
} else {
|
|
|
|
sendResponse({}); // Send nothing..
|
|
|
|
}
|
|
|
|
});
|