dtp-webextension/popup.js

52 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2020-06-09 21:27:28 +08:00
let downloadBtn = document.getElementById('download');
let download2Btn = document.getElementById('download2');
let download3Btn = document.getElementById('download3');
let download4Btn = document.getElementById('download4');
2020-06-09 21:27:28 +08:00
//
// chrome.storage.sync.get('color', function(data) {
// changeColor.style.backgroundColor = data.color;
// changeColor.setAttribute('value', data.color);
// });
function sendActionAndResponse(actionStr) {
2024-06-03 22:50:19 +08:00
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
2020-06-09 21:27:28 +08:00
// Send a request to the content script.
2024-06-03 22:50:19 +08:00
chrome.tabs.sendMessage(tabs[0].id, {action: actionStr}, (response) => {
2020-06-09 21:27:28 +08:00
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);
});
2024-06-03 22:50:19 +08:00
} else {
console.log(response.dataType)
}
2020-06-09 21:27:28 +08:00
});
});
}
downloadBtn.onclick = function(element) {
// chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
// console.log(tabs[0].url);
// });
sendActionAndResponse("requestPics");
2020-06-09 21:27:28 +08:00
// let color = element.target.value;
// chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
// chrome.tabs.executeScript(
// tabs[0].id,
// {code: 'document.body.style.backgroundColor = "' + color + '";'});
// });
};
download2Btn.onclick = function(element) { sendActionAndResponse("requestPics2"); }
download3Btn.onclick = function(element) { sendActionAndResponse("requestPics3"); }
download4Btn.onclick = function(element) { sendActionAndResponse("requestPics4"); }