diff --git a/README.md b/README.md index 88d9e70..e9af4ea 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # chrome-extension-t66ylink-extractor -["*://*.t66y.com/*","*://*.rmdown.com/*"] \ No newline at end of file +["*://*.t66y.com/*","*://*.rmdown.com/*"] diff --git a/background.js b/background.js index c7a9bc4..1bf3d34 100644 --- a/background.js +++ b/background.js @@ -1,18 +1,36 @@ +let retryTimer = null; + 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"); - } - }); + performActionsWithRetry(tabId); chrome.tabs.onUpdated.removeListener(listener); } }); }); + } else if (request.action === "rateLimitReached") { + // Set a timer to retry after 1 hour + if (retryTimer) { + clearTimeout(retryTimer); + } + retryTimer = setTimeout(() => { + chrome.tabs.query({url: "*://rmdown.com/*"}, (tabs) => { + if (tabs.length > 0) { + performActionsWithRetry(tabs[0].id); + } + }); + }, 60 * 60 * 1000); // 1 hour in milliseconds } }); + +function performActionsWithRetry(tabId) { + chrome.tabs.sendMessage(tabId, { action: "performActions" }, (response) => { + if (chrome.runtime.lastError) { + console.error(chrome.runtime.lastError.message); + } else { + console.log("Actions performed successfully"); + } + }); +} diff --git a/content.js b/content.js index e06d98a..d0752d6 100644 --- a/content.js +++ b/content.js @@ -11,17 +11,39 @@ function simulateClick(element) { // Function to perform actions on rmdown.com function performRmdownActions() { console.log("Performing actions on rmdown.com"); + + // Check if the page contains the rate limit message + if (document.body.innerText.includes("Your IP downloads reached the site limit")) { + console.log("Rate limit reached. Stopping actions."); + // Optionally, you can display a notification to the user here + return; + } + + // Random delay between 2 to 5 seconds before starting actions + const initialDelay = 2000 + Math.random() * 3000; + setTimeout(() => { const copyButton = document.getElementById('cbtn'); - const downloadButton = document.querySelector('button[title="Download file"]'); - if (copyButton && downloadButton) { - console.log("Buttons found:", copyButton, downloadButton); + if (copyButton) { + console.log("Copy button found, clicking..."); simulateClick(copyButton); - simulateClick(downloadButton); + + // Random delay between 1 to 3 seconds before next action + const downloadDelay = 1000 + Math.random() * 2000; + + setTimeout(() => { + const downloadButton = document.querySelector('button[title="Download file"]'); + if (downloadButton) { + console.log("Download button found, clicking..."); + simulateClick(downloadButton); + } else { + console.log("Download button not found"); + } + }, downloadDelay); } else { - console.log("Buttons not found"); + console.log("Copy button not found"); } - }, 2000); // Adjust the timeout as needed + }, initialDelay); } // Listen for messages from the popup script