diff --git a/README.md b/README.md index 5d366eb..88d9e70 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # chrome-extension-t66ylink-extractor +["*://*.t66y.com/*","*://*.rmdown.com/*"] \ No newline at end of file diff --git a/background.js b/background.js new file mode 100644 index 0000000..c7a9bc4 --- /dev/null +++ b/background.js @@ -0,0 +1,18 @@ +chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { + if (request.action === "openLink") { + chrome.tabs.create({ url: request.url }, (tab) => { + chrome.tabs.onUpdated.addListener(function listener(tabId, changeInfo, tab) { + if (tabId === tab.id && changeInfo.status === 'complete') { + chrome.tabs.sendMessage(tabId, { action: "performActions" }, (response) => { + if (chrome.runtime.lastError) { + console.error(chrome.runtime.lastError.message); + } else { + console.log("Actions performed successfully"); + } + }); + chrome.tabs.onUpdated.removeListener(listener); + } + }); + }); + } +}); diff --git a/content.js b/content.js new file mode 100644 index 0000000..e06d98a --- /dev/null +++ b/content.js @@ -0,0 +1,53 @@ +// Function to simulate a click event +function simulateClick(element) { + const event = new MouseEvent('click', { + view: window, + bubbles: true, + cancelable: true + }); + element.dispatchEvent(event); +} + +// Function to perform actions on rmdown.com +function performRmdownActions() { + console.log("Performing actions on rmdown.com"); + setTimeout(() => { + const copyButton = document.getElementById('cbtn'); + const downloadButton = document.querySelector('button[title="Download file"]'); + if (copyButton && downloadButton) { + console.log("Buttons found:", copyButton, downloadButton); + simulateClick(copyButton); + simulateClick(downloadButton); + } else { + console.log("Buttons not found"); + } + }, 2000); // Adjust the timeout as needed +} + +// Listen for messages from the popup script +chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { + console.log("Message received in content script:", request); + if (request.action === "initiateDownload") { + // Find the link on the page + const link = document.querySelector('a[href*="rmdown.com/link.php?hash="]'); + if (link) { + console.log("Link found:", link); + // Open the link in a new tab + chrome.runtime.sendMessage({ action: "openLink", url: link.href }); + sendResponse({ success: true }); + } else { + console.log("Link not found"); + sendResponse({ success: false }); + } + return true; // Indicates that the response is sent asynchronously + } else if (request.action === "performActions") { + performRmdownActions(); + sendResponse({ success: true }); + return true; + } +}); + +// Automatically perform actions if on rmdown.com +if (window.location.hostname === "rmdown.com") { + performRmdownActions(); +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..f316c19 --- /dev/null +++ b/manifest.json @@ -0,0 +1,27 @@ +{ + "manifest_version": 3, + "name": "Auto Download Link", + "version": "1.0", + "description": "Automate the process of copying and downloading a link.", + "permissions": [ + "activeTab", + "scripting", + "tabs" + ], + "background": { + "service_worker": "background.js" + }, + "action": { + "default_popup": "popup.html" + }, + "content_scripts": [ + { + "matches": ["*://*.t66y.com/*", "*://rmdown.com/*"], + "js": ["content.js"] + } + ], + "host_permissions": [ + "*://*.t66y.com/*", + "*://rmdown.com/*" + ] +} diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..cd07543 --- /dev/null +++ b/popup.html @@ -0,0 +1,11 @@ + + + + Auto Download Link + + + +

Auto Download Link

+ + + diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..716d3b9 --- /dev/null +++ b/popup.js @@ -0,0 +1,28 @@ +document.addEventListener('DOMContentLoaded', () => { + const startButton = document.getElementById('start'); + 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); + } + }); + }); + }); + }); + } else { + console.error("Start button not found"); + } +}); \ No newline at end of file