fix: should match all images
This commit is contained in:
parent
3727ec6800
commit
2030e18b82
|
@ -1,13 +1,17 @@
|
||||||
function getElementByXpath(path) {
|
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) {
|
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
|
||||||
if (request.action == "requestPics") {
|
if (request.action == "requestPics") {
|
||||||
// TODO: check url, use different match rule to return data.
|
// TODO: check url, use different match rule to return data.
|
||||||
let a = getElementByXpath("//article[contains(@role,'article')][1]//a[contains(@href,'/photo/')]//img/@src");
|
let a = getElementByXpath("(//article[contains(@role,'article')])[1]//a[contains(@href,'/photo/')]//img/@src");
|
||||||
console.log(a);
|
let arr = [];
|
||||||
sendResponse({dateType: 'urlList', urlList: a});
|
for (i=0; i<a.snapshotLength; i++) {
|
||||||
|
arr.push(a.snapshotItem(i).textContent);
|
||||||
|
}
|
||||||
|
// console.log(arr);
|
||||||
|
sendResponse({dateType: 'urlList', urlList: arr});
|
||||||
} else {
|
} else {
|
||||||
sendResponse({}); // Send nothing..
|
sendResponse({}); // Send nothing..
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<button id="download"></button>
|
<button id="download">Download</button>
|
||||||
<script src="popup.js"></script>
|
<script src="popup.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user