diff --git a/content.js b/content.js index d0752d6..febf5ec 100644 --- a/content.js +++ b/content.js @@ -66,6 +66,16 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { performRmdownActions(); sendResponse({ success: true }); return true; + } else if (request.action === "copyTitle") { + const pageTitle = document.title; + navigator.clipboard.writeText(pageTitle).then(() => { + console.log("Title copied to clipboard:", pageTitle); + sendResponse({ success: true, title: pageTitle }); + }).catch(err => { + console.error("Failed to copy title:", err); + sendResponse({ success: false, error: err.message }); + }); + return true; // Indicates that the response is sent asynchronously } }); diff --git a/popup.html b/popup.html index cd07543..49f5e36 100644 --- a/popup.html +++ b/popup.html @@ -3,9 +3,14 @@ Auto Download Link +

Auto Download Link

+ diff --git a/popup.js b/popup.js index 716d3b9..b085687 100644 --- a/popup.js +++ b/popup.js @@ -1,28 +1,43 @@ 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]); - - // Inject the content script - chrome.scripting.executeScript({ - target: { tabId: tabs[0].id }, - files: ['content.js'] - }, () => { - // After injection, send the message - 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); - } - }); + 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"); + } }); \ No newline at end of file