From 324322cf2399921fc62e7fd5afa0e68d1e0c8517 Mon Sep 17 00:00:00 2001 From: eson Date: Tue, 17 Nov 2020 19:54:25 +0800 Subject: [PATCH] =?UTF-8?q?TODO:=20=20worker.js=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E6=95=B0=E6=8D=AE=E7=9A=84=E6=96=B9=E6=A1=88?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- myblock/content/inject.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) 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);
+    }
   })
 }