chrome-extension-t66ylink-e.../content.js

54 lines
1.7 KiB
JavaScript

// 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();
}