소스 검색

[bug][double like & 分页 & 推文repost]

zhangwei 2 년 전
부모
커밋
b9ade01f35

+ 5 - 1
src/entry/content.js

@@ -37,7 +37,8 @@ import {
     refreshTabGroup,
     groupTipsSelectGroupTab,
     TwitterApiUserByScreenName,
-    showPublishDialog
+    showPublishDialog,
+    sendContentByTwitterID
 } from "@/logic/content/twitter.js";
 
 import { httpBackToContentCallBack } from '@/uilts/chromeExtension.js'
@@ -222,6 +223,9 @@ chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
         case 'Hide_ToolBox_By_Nft':
             toolBox.hideBuyNft(req)
             break;
+        case 'GET_CONTENT_BY_TWITTER_ID':
+            sendContentByTwitterID(req.data.tweet_Id)
+            break
     }
     sendResponse && sendResponse('ok');
 })

+ 16 - 1
src/http/help.js

@@ -1,6 +1,6 @@
 import { getChromeStorage } from '@/uilts/chromeExtension.js'
 import { srcPublishSuccess } from '@/http/publishApi'
-import { bindRepost } from '@/http/treasure'
+import { bindRepost, bindPostContent } from '@/http/treasure'
 
 // 重新绑定推文id
 export const reSetBindTwtterId = ({
@@ -39,3 +39,18 @@ export const reSetBindRepost = (params, callback) => {
     })
 }
 
+
+
+export const reSetBindPostContent = (params, callback) => {
+    getChromeStorage('userInfo', (_userInfo) => {
+        if (_userInfo && _userInfo.uid) {
+            bindPostContent({
+                params
+            }).then((res) => {
+                if (res.code == 0 || res.code == 3003) {
+                    callback && callback()
+                }
+            })
+        }
+    })
+}

+ 8 - 0
src/http/treasure.js

@@ -83,4 +83,12 @@ export function bindRepost(params) {
         method: "post",
         data: params,
     });
+}
+
+export function bindPostContent(params) {
+    return service({
+        url: `/post/bindPostSrcContent`,
+        method: "post",
+        data: params,
+    });
 }

+ 29 - 8
src/logic/content/ParseCard.js

@@ -1,3 +1,4 @@
+import { iframeHost } from '@/http/configAPI'
 import { getChromeStorage, setChromeStorage } from '@/uilts/chromeExtension.js'
 import ToolBox from '@/view/content/tool-box/index.vue'
 import { createApp } from 'vue'
@@ -61,19 +62,29 @@ class ParseCard {
         // 是否有#DeNet
         return has_denet
     }
-    parseAllDeNetCard() {
+    parseAllDeNetCard(has_iframe = false) {
         let de_net_card = []
         try {
             let arr_article = document.querySelectorAll('article') || []
             let _txt
             for (let i in arr_article) {
                 _txt = arr_article[i].innerText || ''
-                if ((_txt.includes('#DeNet') || _txt.includes('#DNFT') || this.compatibleMask(arr_article[i])) && !this.isHasIframeByArticle(arr_article[i])) {
-                    de_net_card.push({
-                        time: new Date().getTime(),
-                        dom: arr_article[i]
-                    })
+                if (has_iframe) {
+                    if ((_txt.includes('#DeNet') || _txt.includes('#DNFT') || this.compatibleMask(arr_article[i]))) {
+                        de_net_card.push({
+                            time: new Date().getTime(),
+                            dom: arr_article[i]
+                        })
+                    }
+                } else {
+                    if ((_txt.includes('#DeNet') || _txt.includes('#DNFT') || this.compatibleMask(arr_article[i])) && !this.isHasIframeByArticle(arr_article[i])) {
+                        de_net_card.push({
+                            time: new Date().getTime(),
+                            dom: arr_article[i]
+                        })
+                    }
                 }
+
             }
         } catch (error) {
         }
@@ -154,9 +165,9 @@ class ParseCard {
             return
         }
     }
-    parseAllDeNetCardParmas() {
+    parseAllDeNetCardParmas(has_iframe = false) {
         let json_data = []
-        this.parseAllDeNetCard().forEach((item) => {
+        this.parseAllDeNetCard(has_iframe).forEach((item) => {
             let _obj = this.parseCardParmas(item.dom)
             if (_obj.tweet_Id && _obj.short_url && _obj.dom_card) {
                 _obj.time = item.time
@@ -572,5 +583,15 @@ class ParseCard {
             dom.appendChild(this.createNftGroupIframe({ project_Id, tweet_Id }))
         }
     }
+    // 根据推特id获取文章推文
+    getContentByTwitterId(tweet_Id) {
+        let txt = ''
+        let card_json_data = this.parseAllDeNetCardParmas(true)
+        let result = card_json_data.filter((item) => { return item.tweet_Id == tweet_Id }) || []
+        if (result.length > 0 && result[0].dom_card) {
+            txt = result[0].dom_card.querySelector('[data-testid="tweetText"]').innerText.replace('…', ' ')
+        }
+        return txt
+    }
 }
 export default new ParseCard()

+ 13 - 1
src/logic/content/twitter.js

@@ -23,7 +23,6 @@ let systemInfo = {
     theme: 'light'
 }
 
-let str = document.querySelector('article').querySelector('[data-testid="tweetText"]').innerText.replaceAll('…', '')
 
 let fixProfileTabAutoTimer = null;
 
@@ -2605,3 +2604,16 @@ export const showPublishDialog = () => {
         smallBtn.click();
     }
 }
+
+// 获取推文发送回去 
+export const sendContentByTwitterID = (tweet_Id) => {
+    // 获取内容
+    let txt = parseCard.getContentByTwitterId(tweet_Id)
+    // 发送
+    chrome.runtime.sendMessage({
+        actionType: "CONTENT_GET_TWEET_TXT", data: {
+            tweet_Id,
+            txt
+        }
+    })
+}

+ 1 - 1
src/view/iframe/treasure-hunt/components/btn.vue

@@ -61,7 +61,7 @@ const refresh = () => {
 
         state.init(() => {
             state.inviteInit()
-            state.inviteList()
+            state.inviteListRefresh()
         })
     }
 }

+ 11 - 11
src/view/iframe/treasure-hunt/components/invite-friends.vue

@@ -37,7 +37,7 @@ state.log_invite_btn_show = {
     redPacketType: Report.redPacketType.treasure,
     shareLinkId: state.invite_code,
     myShareLinkId: state.detail.inviteCopyUrl,
-    currentInvitedNum: state.detail.inviteCount,
+    currentInvitedNum: state.inviteCount,
     postId: state.postId
 }
 
@@ -48,7 +48,7 @@ state.log_invite_btn_click = {
     redPacketType: Report.redPacketType.treasure,
     shareLinkId: state.invite_code,
     myShareLinkId: state.detail.inviteCopyUrl,
-    currentInvitedNum: state.detail.inviteCount,
+    currentInvitedNum: state.inviteCount,
     postId: state.postId
 }
 state.log_invite_copy_btn_click = {
@@ -58,7 +58,7 @@ state.log_invite_copy_btn_click = {
     redPacketType: Report.redPacketType.treasure,
     shareLinkId: state.invite_code,
     myShareLinkId: state.detail.inviteCopyUrl,
-    currentInvitedNum: state.detail.inviteCount,
+    currentInvitedNum: state.inviteCount,
     postId: state.postId
 }
 onMounted(() => {
@@ -110,16 +110,16 @@ const clickShare = (item) => {
         url: item.redirectPath
     });
     let strArr = item.treasureInviteUrl.split('/');
-    let channelName = window.atob(strArr[strArr.length-1]);
+    let channelName = window.atob(strArr[strArr.length - 1]);
     Report.reportLog({
-      businessType: Report.businessType.buttonClick,
-      pageSource: Report.pageSource.inviteFriendsPage,
-      objectType: Report.objectType.channelButton,
-      shareLinkId: state.invite_code,
-      myShareLinkId: state.detail.inviteCopyUrl,
-      currentInvitedNum: state.detail.inviteCount,
+        businessType: Report.businessType.buttonClick,
+        pageSource: Report.pageSource.inviteFriendsPage,
+        objectType: Report.objectType.channelButton,
+        shareLinkId: state.invite_code,
+        myShareLinkId: state.detail.inviteCopyUrl,
+        currentInvitedNum: state.inviteCount,
     }, {
-      'channel-name': channelName
+        'channel-name': channelName
     });
 }
 

+ 54 - 25
src/view/iframe/treasure-hunt/components/invite-list.vue

@@ -23,7 +23,7 @@
 </template>
 <script setup>
 import VBtn from '@/view/iframe/treasure-hunt/components/btn.vue'
-import { inviteList } from '@/http/treasure'
+import { inviteList, inviteListRefresh } from '@/http/treasure'
 import { inject, onMounted } from 'vue'
 import Report from "@/log-center/log"
 
@@ -41,7 +41,7 @@ state.log_invite_btn_click = {
     redPacketType: Report.redPacketType.treasure,
     shareLinkId: state.invite_code,
     myShareLinkId: state.detail.inviteCopyUrl,
-    currentInvitedNum: state.detail.inviteCount,
+    currentInvitedNum: state.inviteCount,
     postId: state.postId
 }
 
@@ -51,7 +51,7 @@ state.log_invite_list_show = {
     redPacketType: Report.redPacketType.treasure,
     shareLinkId: state.invite_code,
     myShareLinkId: state.detail.inviteCopyUrl,
-    currentInvitedNum: state.detail.inviteCount,
+    currentInvitedNum: state.inviteCount,
     postId: state.postId
 }
 
@@ -71,46 +71,75 @@ function handleScroll(e) {
     e = e.target
     if ((e.clientHeight + e.scrollTop) / e.scrollHeight > .8) {
         list_end = true
-        if (state.invited_list.length == page_num * page_size) {
-            page_num++
-        }
-        list()
+        inviteListScroll()
     }
 }
 
 const list = () => {
-    state.inviteList()
+    inviteListScroll()
 }
 
-// 滚动和初始化
-let inviteListScroll = () => {
+// 刷新时调用
+state.inviteListRefresh = () => {
+    let last_timestamp = 0
+    if (state.invited_list.length > 0) {
+        last_timestamp = state.invited_list[0].last_timestamp
+    }
 
+    inviteListRefresh({
+        params: {
+            postId: state.postId,
+            lastTimestamp: last_timestamp,
+        }
+    }).then((res) => {
+        if (res.code == 0) {
+            handleCommon(res.data)
+        }
+    })
 }
 
-// 刷新时调用
-let inviteListRefresh = () => {
+const handleCommon = (data) => {
+    state.inviteCount = data.inviteCount
+    if (state.inviteCount > 0) {
+        state.tabs[1].txt = `invited(${state.inviteCount})`
+    }
+    if (data.inviteUsers.length > 0) {
+        data.inviteUsers.forEach(item => {
+            if (state.invited_list.filter((item2) => { return item2.userInfo.uid == item.userInfo.uid }).length == 0) {
+                state.invited_list.push(item)
+            }
+        })
+
+        state.invited_list.sort((a, b) => {
+            return a.lastTimestamp - b.lastTimestamp
+        })
 
+        list_end = false
+    } else {
+        list_end = false
+    }
 }
 
-state.inviteList = () => {
+// 滚动和初始化
+let inviteListScroll = () => {
+    // state.invited_list
+    let last_timestamp = 0
+    let len = state.invited_list.length
+    if (len > 0) {
+        last_timestamp = state.invited_list[len - 1].lastTimestamp
+    }
+
     inviteList({
         params: {
             inviteCode: state.invite_code,
-            postId: state.postId
+            postId: state.postId,
+            lastTimestamp: last_timestamp,
+            pageSize: page_size
         }
-
     }).then((res) => {
         if (res.code == 0) {
-            if (res.data.length > 0) {
-                res.data.forEach(item => {
-                    if (state.invited_list.filter((item2) => { return item2.userInfo.uid == item.userInfo.uid }).length == 0) {
-                        state.invited_list.push(item)
-                    }
-                })
-                list_end = false
-            } else {
-                list_end = false
-            }
+
+            handleCommon(res.data)
         }
     })
 }

+ 10 - 5
src/view/iframe/treasure-hunt/cover.vue

@@ -221,8 +221,10 @@ const startBtn = () => {
                 url: pageUrl,
             })
             let text = res.data.rePostTweetContent
-            // 一键三连
+
+            // 做任务
             chrome.tabs.getCurrent((tab) => {
+                // 一键三连
                 chrome.tabs.sendMessage(tab.id, {
                     actionType: "IFRAME_TWITTER_API_DO_TASK",
                     task_data: {
@@ -232,11 +234,14 @@ const startBtn = () => {
                     task_type: 'tasks',
                     tasks: state.tasks,
                 });
-            })
-
-            // double like            
-            // state.detail.srcContentId
+                // double like
+                chrome.tabs.sendMessage(tab.id, {
+                    actionType: "IFRAME_TWITTER_API_DO_TASK", task_data: {
+                        tweet_Id: state.detail.srcContentId
+                    }, task_type: 'like'
+                })
 
+            })
         } else {
             state.init()
         }

+ 24 - 9
src/view/iframe/treasure-hunt/index.vue

@@ -11,7 +11,7 @@ import VCover from '@/view/iframe/treasure-hunt/cover.vue'
 import VInvite from '@/view/iframe/treasure-hunt/invite.vue'
 import VResult from '@/view/iframe/treasure-hunt/result.vue'
 import { inviteDetail, treasureDetail, treasureOpen } from '@/http/treasure.js'
-import { reSetBindTwtterId, reSetBindRepost } from '@/http/help.js'
+import { reSetBindTwtterId, reSetBindPostContent, reSetBindRepost } from '@/http/help.js'
 import { getQueryString } from '@/uilts/help'
 import { getChromeStorage, sendChromeTabMessage } from '@/uilts/chromeExtension.js'
 import VToast from '@/view/iframe/treasure-hunt/components/toast.vue'
@@ -77,7 +77,6 @@ state.init = (callback) => {
             }
         }).then((res) => {
             if (res.code == 0) {
-
                 handleCommon(res, callback)
                 // 绑定repostSrcContentId
                 if (!res.data.repostSrcContentId) {
@@ -98,6 +97,15 @@ state.init = (callback) => {
         }).then((res) => {
             if (res.code == 0) {
                 handleCommon(res, callback)
+                // 原始链接绑定post content
+                if (!res.data.postSrcContent) {
+                    sendChromeTabMessage({
+                        actionType: "GET_CONTENT_BY_TWITTER_ID",
+                        data: {
+                            tweet_Id: state.tweetId
+                        }
+                    })
+                }
             }
         })
     }
@@ -111,7 +119,7 @@ const reportOpenBoxLog = () => {
             redPacketType: Report.redPacketType.treasure,
             shareLinkId: state.invite_code,
             myShareLinkId: state.detail.inviteCopyUrl,
-            currentInvitedNum: state.detail.inviteCount,
+            currentInvitedNum: state.inviteCount,
             postId: state.postId
         });
         state.open_box.showed = false
@@ -124,7 +132,7 @@ const reportOpenBoxLog = () => {
             redPacketType: Report.redPacketType.treasure,
             shareLinkId: state.invite_code,
             myShareLinkId: state.detail.inviteCopyUrl,
-            currentInvitedNum: state.detail.inviteCount,
+            currentInvitedNum: state.inviteCount,
             postId: state.postId
         });
         state.open_box.clicked = false
@@ -191,7 +199,7 @@ state.treasureOpen = () => {
 
             state.init(() => {
                 state.inviteInit()
-                state.inviteList()
+                state.inviteListRefresh()
             })
         } else {
             switch (String(res.code)) {
@@ -218,7 +226,7 @@ state.treasureOpen = () => {
 
             state.init(() => {
                 state.inviteInit()
-                state.inviteList()
+                state.inviteListRefresh()
             })
         }
     }).catch(() => {
@@ -238,12 +246,11 @@ const handleStatus = (callback) => {
     //  显示结束页面
 
     let { status, joinStatus } = state.detail || {}
-    state.open_btn.txt = 'Start'
     // 如果 夺宝状态 = 未开始
     if (status == 0) {
-        state.page = '封面页'
-
+        // 未做处理
     }
+
     // 如果 夺宝状态 = 进行中
     else if (status == 1) {
         // 如果 夺宝参与状态 = 未参与夺宝
@@ -274,6 +281,14 @@ const handleStatus = (callback) => {
 function onRuntimeMsg() {
     chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
         switch (req.actionType) {
+            case 'CONTENT_GET_TWEET_TXT':
+                if (req.data.tweet_Id == state.tweetId) {
+                    reSetBindPostContent({
+                        postId: state.postId || '',
+                        postSrcContent: req.data.txt,
+                    })
+                }
+                break
             case 'CONTENT_API_GET_TWEET_USER_INFO_RES':
                 let twitterFans = 0;
                 let { user } = req.data || {};

+ 9 - 12
src/view/iframe/treasure-hunt/invite.vue

@@ -61,7 +61,7 @@ state.log_invite_show = {
     redPacketType: Report.redPacketType.treasure,
     shareLinkId: state.invite_code,
     myShareLinkId: state.detail.inviteCopyUrl,
-    currentInvitedNum: state.detail.inviteCount,
+    currentInvitedNum: state.inviteCount,
     postId: state.postId
 }
 
@@ -88,21 +88,18 @@ state.boxs = []
 let line_full = ref(null)
 onMounted(() => {
     state.inviteInit()
-    setInterval(() => {
-        state.init(() => {
-            state.inviteInit()
-            state.inviteList()
-        })
-    }, 30000)
+    // setInterval(() => {
+    // state.init(() => {
+    //     state.inviteInit()
+    //     state.inviteListRefresh()
+    // })
+    // }, 30000)
 })
 
 const clickItem = (item) => {
     window.open(`https://twitter.com/${item.userInfo.nickName}`)
 }
 state.inviteInit = () => {
-    if (state.detail.inviteCount > 0) {
-        state.tabs[1].txt = `invited(${state.detail.inviteCount})`
-    }
     state.boxs = []
     state.detail.treasureRecords.forEach((item, index) => {
         if (item.openStatus == 0) {
@@ -157,8 +154,8 @@ const setLineFull = (box_num = 0, finishNeedInviteCount = 0, successInviteCount
         line_width = (successInviteCount / finishNeedInviteCount) * 55
     } else if (box_num == 1) {
         if (line_width == 55) {
-            // 第二个宝箱起点是92,终点是155
-            line_width = 92
+            // 第二个宝箱起点88,终点是155
+            line_width = 88
             line_width = (successInviteCount / finishNeedInviteCount) * (155 - line_width) + line_width
         }
     } else if (box_num == 2) {