basic: send url list and original source url
This commit is contained in:
parent
2030e18b82
commit
75695f9d11
|
@ -8,10 +8,15 @@ chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
|
|||
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);
|
||||
let oneUrl = a.snapshotItem(i).textContent;
|
||||
let splited = oneUrl.split('?');
|
||||
let baseUrl = splited[0];
|
||||
var getParas = new URLSearchParams(splited[1]);
|
||||
getParas.set("name", "orig");
|
||||
arr.push(baseUrl + '?' + getParas.toString());
|
||||
}
|
||||
// console.log(arr);
|
||||
sendResponse({dateType: 'urlList', urlList: arr});
|
||||
sendResponse({dataType: 'urlList', urlList: arr, source: window.location.href});
|
||||
} else {
|
||||
sendResponse({}); // Send nothing..
|
||||
}
|
||||
|
|
|
@ -16,5 +16,7 @@
|
|||
"js": ["common_content_script.js"]
|
||||
}
|
||||
],
|
||||
"permissions": ["activeTab", "declarativeContent"]
|
||||
"permissions": [
|
||||
"activeTab", "declarativeContent"
|
||||
]
|
||||
}
|
||||
|
|
12
popup.js
12
popup.js
|
@ -15,6 +15,18 @@ downloadBtn.onclick = function(element) {
|
|||
// Send a request to the content script.
|
||||
chrome.tabs.sendRequest(tab.id, {action: "requestPics"}, function(response) {
|
||||
console.log(response);
|
||||
if (response.dataType == "urlList") {
|
||||
const data = new URLSearchParams();
|
||||
data.append("source", response.source);
|
||||
data.append("urlList", JSON.stringify(response.urlList));
|
||||
|
||||
fetch('http://localhost:1704/urlList', {
|
||||
method: 'post',
|
||||
body: data,
|
||||
}).then(data => {
|
||||
console.log(data);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user