diff --git a/myblock/content/inject.js b/myblock/content/inject.js index 1725856..8a2c5d6 100644 --- a/myblock/content/inject.js +++ b/myblock/content/inject.js @@ -1,31 +1,33 @@ - - - var href = window.location.href; var content = document.documentElement.innerHTML; -var interval = setInterval(function(){ - GetTask(); -}, 6000) - -if (href.startsWith("https://playerduo.com")) { - if (content.startsWith('
')) {
-    SendContent();
-    clearInterval(interval);
-    GetTask();
-  }
+if (href.startsWith("https://playerduo.com") && content.startsWith('
')) {
+  SendContent();
+} else {
+  GetTask()
 }
 
+
 function SendContent() {
   chrome.runtime.sendMessage({ type: BackgroundMsgType.CONTENT, content: content },
     function (response) {
-      console.log(response.type, response);
+      console.log(response);
+      GetTask();
     })
 }
 
 function GetTask() {
   chrome.runtime.sendMessage({ type: BackgroundMsgType.GETTASK }, function (response) {
-    console.log(response);
+    switch(response.type) {
+      case BackgroundMsgType.FETCH:
+        setTimeout(function(){
+          GetTask();
+        }, 6000)
+      case BackgroundMsgType.WAIT:
+        setTimeout(function(){
+          GetTask();
+        }, 1000);
+    }
   })
 }