43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
const startButton = document.getElementById('start');
|
|
const copyTitleButton = document.getElementById('copyTitle');
|
|
|
|
if (startButton) {
|
|
startButton.addEventListener('click', () => {
|
|
console.log("Start button clicked");
|
|
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
|
console.log("Active tab:", tabs[0]);
|
|
chrome.tabs.sendMessage(tabs[0].id, { action: "initiateDownload" }, (response) => {
|
|
if (chrome.runtime.lastError) {
|
|
console.error("Error:", chrome.runtime.lastError.message);
|
|
} else {
|
|
console.log("Message sent to content script, response:", response);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
} else {
|
|
console.error("Start button not found");
|
|
}
|
|
|
|
if (copyTitleButton) {
|
|
copyTitleButton.addEventListener('click', () => {
|
|
console.log("Copy Title button clicked");
|
|
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
|
chrome.tabs.sendMessage(tabs[0].id, { action: "copyTitle" }, (response) => {
|
|
if (chrome.runtime.lastError) {
|
|
console.error("Error:", chrome.runtime.lastError.message);
|
|
} else {
|
|
console.log("Title copied:", response.title);
|
|
copyTitleButton.textContent = "Title Copied!";
|
|
setTimeout(() => {
|
|
copyTitleButton.textContent = "Copy Title";
|
|
}, 2000);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
} else {
|
|
console.error("Copy Title button not found");
|
|
}
|
|
}); |