Ver código fonte

[bug][follow]

zhangwei 2 anos atrás
pai
commit
dce141e9fc
1 arquivos alterados com 7 adições e 8 exclusões
  1. 7 8
      src/logic/content/twitter.js

+ 7 - 8
src/logic/content/twitter.js

@@ -717,31 +717,30 @@ export function checkTwitterTaskState() {
         }
     }, true)
 
-    let observer = new MutationObserver(() => {
+    let timer = setInterval(() => {
         // 喜欢
         if (document.querySelector('div[data-testid=unlike]') && task_type == 'like') {
-            observer.disconnect()
+            clearInterval(timer)
             chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
         }
         // 转推
         if (document.querySelector('div[data-testid=unretweet]') && task_type == 'retweet') {
-            observer.disconnect()
+            clearInterval(timer)
             chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
         }
         // 关注
         if (task_type == 'follow') {
             let follow_area = document.querySelector('div[data-testid=placementTracking]')
             if (follow_area && follow_area.querySelectorAll('div')) {
-                observer.disconnect()
+                follow_area = follow_area.querySelectorAll('div')
+                clearInterval(timer)
                 for (let i in follow_area) {
-                    if (follow_area[i].dataset && follow_area[i].dataset.testid && follow_area[i].dataset.testid.indexOf('unfollow') > 0) {
+                    if (follow_area[i] && follow_area[i].dataset && follow_area[i].dataset.testid && follow_area[i].dataset.testid.indexOf('unfollow') > 0) {
                         chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
                         break
                     }
                 }
             }
         }
-    });
-    const config = { attributes: false, childList: true, subtree: true };
-    observer.observe(document.body, config);
+    }, 1000)
 }