Forráskód Böngészése

[edit][完成bug]

zhangwei 3 éve
szülő
commit
75980459cd
1 módosított fájl, 30 hozzáadás és 3 törlés
  1. 30 3
      src/logic/content/twitter.js

+ 30 - 3
src/logic/content/twitter.js

@@ -712,9 +712,36 @@ export function checkTwitterTaskState() {
             chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: false }, () => { })
         })
         // 点击 蒙层
-        if (e.target && e.target.nextSibling && e.target.nextSibling.dataset && e.target.nextSibling.dataset.testid == 'confirmationSheetDialog') {
-            chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: false }, () => { })
-        }
+        // if (e.target && e.target.nextSibling && e.target.nextSibling.dataset && e.target.nextSibling.dataset.testid == 'confirmationSheetDialog') {
+        //     chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: false }, () => { })
+        // }
     }, true)
 
+    let observer = new MutationObserver(() => {
+        // 喜欢
+        if (document.querySelector('div[data-testid=unlike]') && task_type == 'like') {
+            observer.disconnect()
+            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()
+            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()
+                for (let i in follow_area) {
+                    if (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);
 }