37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
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') {
|
|
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");
|
|
}
|
|
});
|
|
}
|