diff --git a/background.js b/background.js index 4cb6d7c..8b7989e 100644 --- a/background.js +++ b/background.js @@ -1,7 +1,7 @@ -let autoClaimOption = 1; +const autoClaimOption = 1; let state; -let autoClaimInterval; +let autoClaimTimeout; let claiming; let lastClaimOption = 0; let lastClaimTime = Date.now(); @@ -67,7 +67,7 @@ function onEndClaimAll() { lastClaimTime = Date.now(); if(state == 'automatic') { - autoClaimInterval = setInterval(function() { claimAll(autoClaimOption); }, getClaimOptionLength(autoClaimOption)); + autoClaimTimeout = setTimeout(function() { claimAll(autoClaimOption); }, getClaimOptionLength(autoClaimOption)); } updateBadgeText(); @@ -92,7 +92,7 @@ function updateBadgeText() { } else if(timeLeft < 60 * 60 * 1000) { timeText = Math.trunc(timeLeft / 60 / 1000) + 'm'; } else { - timeText = Math.trunc(timeLeft / 60 / 60 / 1000) + 'h' + Math.trunc((timeLeft % (60 * 60 * 1000)) / 60/ 1000) + 'm'; + timeText = Math.trunc(timeLeft / 60 / 60 / 1000) + 'h' + Math.trunc((timeLeft % (60 * 60 * 1000)) / 60 / 1000) + 'm'; } chrome.browserAction.setBadgeText({ text: state == 'manual' ? '(' + timeText + ')' : timeText }); @@ -120,7 +120,7 @@ function updateState(newState) { chrome.browserAction.setBadgeBackgroundColor({ color: 'green' }); } else if(newState == 'manual') { - clearInterval(autoClaimInterval); + clearTimeout(autoClaimTimeout); chrome.browserAction.setBadgeBackgroundColor({ color: 'red' }); } @@ -176,3 +176,4 @@ chrome.contextMenus.create({ updateBrowserActionStatus(); updateState('manual'); setInterval(updateBadgeText, 500); + diff --git a/content.js b/content.js index 30c5331..8f639d7 100644 --- a/content.js +++ b/content.js @@ -1,9 +1,8 @@ -let headElement = document.getElementsByTagName('head')[0]; - let idInjection = document.createElement('script'); idInjection.innerHTML = 'let extensionId = "' + chrome.runtime.id + '";'; -headElement.appendChild(idInjection); +document.head.appendChild(idInjection); let scriptInjection = document.createElement('script'); scriptInjection.src = chrome.runtime.getURL('injection.js'); -headElement.appendChild(scriptInjection); +document.head.appendChild(scriptInjection); + diff --git a/injection.js b/injection.js index 5ad18a1..5f4bdb6 100644 --- a/injection.js +++ b/injection.js @@ -115,3 +115,4 @@ extensionPort.onMessage.addListener(function(message) { claimAll(message.args[0]); } }); + diff --git a/manifest.json b/manifest.json index dce31fe..9d02d18 100644 --- a/manifest.json +++ b/manifest.json @@ -26,3 +26,4 @@ "permissions": ["tabs", "contextMenus"], "short_name": "Grepolis Bot" } +