Browse Source

Merge branch 'test' into dev_1.0.4_ui

nieyuge 2 years ago
parent
commit
acc3049e1f

+ 31 - 2
src/logic/background/twitter.js

@@ -2,22 +2,51 @@ import { fetchTtwitterRequestToken, fetchTwitterLogin, fetchTwitterShortUrl, fet
 import { LANDING_PAGE, LANDING_PAGE_MID, setChromeStorage, setChromeCookie, getChromeCookie, getChromeStorage, removeChromeCookie } from '@/uilts/chromeExtension.js'
 import { guid } from '@/uilts/help.js'
 import { pageUrl, discordAuthRedirectUri } from '@/http/configAPI'
+import { trueDependencies } from 'mathjs'
 
 let authToken = ''
 let consumerKey = ''
+let tab_flag = true
+
+const isHasTabByUrl = (url, callback) => {
+    let item
+    chrome.tabs.query({}, (tab) => {
+        for (let i in tab) {
+            if (tab[i].url.indexOf(url) >= 0) {
+                item = tab[i]
+                break
+            }
+        }
+        callback(item)
+    })
+}
+
 export function twitterPinLoginToken() {
     // 1.判断是否登陆了
     getChromeStorage('userInfo', (res) => {
         // 没有登陆
         if (!res) {
+            if(tab_flag == false){
+                return
+            }
+            tab_flag = false
             fetchTtwitterRequestToken().then((res) => {
+                tab_flag = true
                 if (res.code == 0) {
                     authToken = res.data.authToken
                     consumerKey = res.data.consumerKey
-                    chrome.tabs.create({
-                        url: `https://api.twitter.com/oauth/authorize?oauth_token=${res.data.authToken}`
+                    isHasTabByUrl('https://api.twitter.com/oauth/authorize?oauth_token', (tab) => {
+                        if (!tab) {
+                            chrome.tabs.create({
+                                url: `https://api.twitter.com/oauth/authorize?oauth_token=${res.data.authToken}`
+                            })
+                        }else{
+                            chrome.tabs.highlight({ windowId: tab.windowId, tabs: tab.index })
+                        }
                     })
                 }
+            }).catch(()=>{
+                tab_flag = true
             })
         }
     })

+ 46 - 43
src/logic/content/twitter.js

@@ -673,7 +673,13 @@ export function findTweetByIdDoTask({ tweet_Id = '', follow_names = [] }, task_t
     }
 }
 
-
+function clickByDataTestId(e, id, callback) {
+    if (e.target.dataset && e.target.dataset.testid && e.target.dataset.testid == id) {
+        callback()
+    } else if (e.target.closest('div[data-testid=' + id + ']')) {
+        callback()
+    }
+}
 
 // 校验关注推特状态 
 export function checkTwitterTaskState() {
@@ -696,49 +702,46 @@ export function checkTwitterTaskState() {
     }
     tweet_Id = getQueryString('tweet_id')
 
-    // 获取关注名字 获取推特Id    
-    let confirm_btn = document.querySelector('div[data-testid=confirmationSheetConfirm]')
-    let confirm_btn_status
-    let cancel_btn = document.querySelector('div[data-testid=confirmationSheetCancel]')
-    let cancel_btn_status
-    
-    // let page_follow_btn = document.querySelector('div[aria-describedby]')
-    // let page_follow_btn_status
-
-    let observer = new MutationObserver(() => {
-        if (confirm_btn && !confirm_btn_status) {
-            confirm_btn_status = true
-            confirm_btn.onclick = (e) => {
-                chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data ,task_done:true}, () => { })
-            }
-        } else {
-            confirm_btn = document.querySelector('div[data-testid=confirmationSheetConfirm]')
-        }
-        if(cancel_btn && !cancel_btn_status){
-            cancel_btn_status= true
-            cancel_btn.onclick = (e) => {
-                chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data ,task_done:false}, () => { })
-            }
-        }else{
-            cancel_btn = document.querySelector('div[data-testid=confirmationSheetCancel]')
+    // let root_status
+    document.body.addEventListener('click', (e) => {
+        // 点击 确认
+        clickByDataTestId(e, 'confirmationSheetConfirm', () => {
+            chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
+        })
+        // 点击取消
+        clickByDataTestId(e, 'confirmationSheetCancel', () => {
+            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 (page_follow_btn && page_follow_btn.dataset && page_follow_btn.dataset.testid && !page_follow_btn_status) {
-        //     page_follow_btn_status = true
-        //     if (page_follow_btn.dataset.testid.includes('unfollow')) {
-        //         // 发送
-        //         chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id }, () => { })
-        //     }
-        // } else {
-        //     page_follow_btn = document.querySelector('div[aria-describedby]')
-        // }
+    }, true)
 
-        if (confirm_btn_status && cancel_btn_status) {
-            observer.disconnect()
+    let timer = setInterval(() => {
+        // 喜欢
+        if (document.querySelector('div[data-testid=unlike]') && task_type == 'like') {
+            clearInterval(timer)
+            chrome.runtime.sendMessage({ actionType: "DO_TASK", tweet_Id, task_type, task_data, task_done: true }, () => { })
         }
-    });
-    observer.observe(document.body, { attributes: false, childList: true, subtree: true });
-
-    // 打开iframe 
-    // 点击操作
-    // 删除iframe
+        // 转推
+        if (document.querySelector('div[data-testid=unretweet]') && task_type == 'retweet') {
+            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')) {
+                follow_area = follow_area.querySelectorAll('div')
+                clearInterval(timer)
+                for (let i in follow_area) {
+                    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
+                    }
+                }
+            }
+        }
+    }, 1000)
 }

+ 1 - 1
src/manifest.json

@@ -2,7 +2,7 @@
     "manifest_version": 3,
     "name": "DeNet",
     "description": "Growing more twitter followers with Denet",
-    "version": "1.0.3",
+    "version": "1.0.4",
     "background": {
         "service_worker": "/js/background.js"
     },

+ 1 - 1
src/view/components/currency-list.vue

@@ -227,7 +227,7 @@ const asyncTokenRechRecord = (cb) => {
     })
 }
 
-const listScroll = () => {
+const listScroll = (e) => {
     let wrapperHeight = listWrapperDom.value.offsetHeight;
     let listContentHeight = listContentDom.value.offsetHeight;
     let scrollTop = e.target.scrollTop || 0;

+ 26 - 22
src/view/iframe/publish/give-dialog.vue

@@ -605,11 +605,7 @@ watch(
             // 更新余额
             clearInterval(timer.value);
             timer.value = setInterval(() => {
-                getChromeStorage('userInfo', (res) => {
-                    if (res && res.accessToken) {
-                        getCurrencyInfo();
-                    }
-                });
+                getCurrencyInfo();
             }, 10000)
         } else {
             clearInterval(timer.value);
@@ -1142,7 +1138,10 @@ const onIptSetErrorTxt = (params = {}) => {
             }
         }
     } else {
-        setDiscordErrTxt({getDuildId: true});
+
+        setDiscordErrTxt({getDuildId: true}, () => {
+            iptErrMsgTxt.value = '';
+        });
     } 
 }
 
@@ -1238,6 +1237,8 @@ const setDiscordErrTxt = (params = {showPop: false}, cb) => {
                 iptErrType = 'discord';
             }
         }
+    } else {
+        cb && cb();
     }
 }
 
@@ -1361,22 +1362,25 @@ const getLocalCurrencyInfoByCode = () => {
     }
 }
 
-const getCurrencyInfo = () => {
-    getChromeStorage('selectCurrencyInfo', (res) => {
-        if(res && res.currencyCode) {
-            getCurrencyInfoByCode({
-                params: {
-                    currencyCode: res.currencyCode
-                }
-            }).then(res => {
-                if(res.code == 0 && res.data) {
-                    currentCurrencyInfo.value = res.data;
-                    tempCurrentCurrencyInfo.value = res.data;
-                    onIptSetErrorTxt();
-                }
-            });
-        }
-    })
+const getCurrencyInfo = async () => {
+    let {accessToken = ''} = await getChromeStorage('userInfo') || {};
+    if (accessToken) {
+        getChromeStorage('selectCurrencyInfo', (res) => {
+            if(res && res.currencyCode) {
+                getCurrencyInfoByCode({
+                    params: {
+                        currencyCode: res.currencyCode
+                    }
+                }).then(res => {
+                    if(res.code == 0 && res.data) {
+                        currentCurrencyInfo.value = res.data;
+                        tempCurrentCurrencyInfo.value = res.data;
+                        onIptSetErrorTxt();
+                    }
+                });
+            }
+        })
+    }
 }
 
 onMounted(() => {

+ 53 - 47
src/view/iframe/red-packet/red-packet.vue

@@ -538,14 +538,15 @@ function getValidity() {
   }, 1000)
 }
 
-const openFollowTabs = () => {
-  let array_finish = state.detail.taskCondition[0].relatedUsers.filter((item) => { return item.finished == false })
+const openFollowTabs = (arr_name) => {
+  let array_finish  = arr_name.filter((item) => { return !item.finished })
+  // let array_finish = state.detail.taskCondition[0].relatedUsers.filter((item) => { return item.finished == false })
   let url
   if (array_finish.length > 0) {
     state.done.follow = false
     // 打开标签页的方法
     array_finish.forEach((item) => {
-      url = `https://twitter.com/intent/follow?screen_name=${item.name}&tweet_id=${state.tweetId}`
+      url = `https://twitter.com/intent/follow?screen_name=${item}&tweet_id=${state.tweetId}`
       chrome.tabs.create({ url }, (tab) => {
         if (follow_open_tabs.filter((item) => { return item.url == tab.url }).length == 0) {
           follow_open_tabs.push(tab)
@@ -560,7 +561,6 @@ async function clickFollowAll(item, is_all) {
   if (!_userInfo) {
     return
   }
-
   let arr_name = []
   for (let i in item) {
     if (!item[i].finished) {
@@ -568,7 +568,7 @@ async function clickFollowAll(item, is_all) {
     }
   }
   if (state.detail.finishTaskType && state.detail.finishTaskType == 2) {
-    openFollowTabs()
+    openFollowTabs(arr_name)
     return
   }
   state.loading_show = true
@@ -586,7 +586,7 @@ async function clickFollowAll(item, is_all) {
           }
         });
       })
-      openFollowTabs()
+      openFollowTabs(arr_name)
     }
   })
 
@@ -814,34 +814,39 @@ function init() {
     }
   })
 }
+
 function initTaskDetail() {
-  // 任务详情
-  getTaskDetail({
-    params: {
-      postId: state.postId
-    }
-  }).then((res) => {
-    if (res.code.toString()) {
-      for (let i in res.data) {
-        switch (res.data[i].type) {
-          case 1:
-            state.done.follow = res.data[i].finished
-            state.detail.taskCondition[0].relatedUsers = res.data[i].detail
-            break
-          case 2:
-            state.done.like = res.data[i].finished
-            break
-          case 3:
-            state.done.retweet = res.data[i].finished
-            break
-          case 7:
-            state.done.join_discord = res.data[i].finished
-            discordAuthorizeRequired = res.data[i].discordAuthorizeRequired
-            break
+  getChromeStorage('userInfo', (_userInfo) => {
+    if (_userInfo.uid) {
+      // 任务详情
+      getTaskDetail({
+        params: {
+          postId: state.postId
         }
-      }
-    } else {
-      handleErrorCode(res)
+      }).then((res) => {
+        if (res.code.toString()) {
+          for (let i in res.data) {
+            switch (res.data[i].type) {
+              case 1:
+                state.done.follow = res.data[i].finished
+                state.detail.taskCondition[0].relatedUsers = res.data[i].detail
+                break
+              case 2:
+                state.done.like = res.data[i].finished
+                break
+              case 3:
+                state.done.retweet = res.data[i].finished
+                break
+              case 7:
+                state.done.join_discord = res.data[i].finished
+                discordAuthorizeRequired = res.data[i].discordAuthorizeRequired
+                break
+            }
+          }
+        } else {
+          handleErrorCode(res)
+        }
+      })
     }
   })
 }
@@ -867,21 +872,20 @@ const doTaskReport = (req, sender) => {
     case 'follow':
       event_type = 1
       chrome.tabs.remove(sender.tab.id)
-      for (let i = 0; i < follow_open_tabs.length; i++) {
-        if (follow_open_tabs[i].id == sender.tab.id) {
-          follow_open_tabs.splice(i, 1)
-          break
-        }
-      }
-
-      chrome.tabs.getCurrent((tab) => {
-        if (follow_open_tabs.length > 0) {
-          tab_index = follow_open_tabs[follow_open_tabs.length - 1].index
-        } else {
-          tab_index = tab.index
-        }
-        chrome.tabs.highlight({ windowId: tab.windowId, tabs: tab_index })
-      })
+      // for (let i = 0; i < follow_open_tabs.length; i++) {
+      //   if (follow_open_tabs[i].id == sender.tab.id) {
+      //     follow_open_tabs.splice(i, 1)
+      //     break
+      //   }
+      // }
+      // chrome.tabs.getCurrent((tab) => {
+      //   if (follow_open_tabs.length > 0) {
+      //     tab_index = follow_open_tabs[follow_open_tabs.length - 1].index
+      //   } else {
+      //     tab_index = tab.index
+      //   }
+      //   chrome.tabs.highlight({ windowId: tab.windowId, tabs: tab_index })
+      // })
       let has_no_finished = false
       state.detail.taskCondition[0].relatedUsers.forEach((item) => {
         if (follow_name == item.name) {
@@ -932,11 +936,13 @@ function clickOpenRedPacket() {
 }
 
 function handleRedPacket() {
+  state.loading_show = true
   getRedPacket({
     params: {
       postId: state.postId
     }
   }).then((res) => {
+    state.loading_show = false
     if (res.code == 0) {
       showOpenedPage()
       init()