瀏覽代碼

Merge branch 'feature_220831_postmsg' into dev_1.1.7.3

wenliming 2 年之前
父節點
當前提交
f0311a8025

+ 20 - 1
src/entry/content.js

@@ -40,7 +40,8 @@ import {
     showPublishDialog,
     getTweetUserFollowStatus,
     sendContentByTwitterID,
-    getExtensionStorgeDataForIframe
+    getExtensionStorgeDataForIframe,
+    doTaskIframeTwitterAPI
 } from "@/logic/content/twitter.js";
 
 import { httpBackToContentCallBack } from '@/uilts/chromeExtension.js'
@@ -125,6 +126,24 @@ window.onmessage = (res) => {
                 // 接受数据,sendmessage
                 console.log('IFRAME_DO_TASK_CREATE_TWEET', res)
                 break
+            case 'IFRAME_API_GET_TWEET_USER_FOLLOW_STATUS':
+                getTweetUserFollowStatus(res.data);
+                break;
+            case 'IFRAME_TWITTER_API_DO_TASK':
+                doTaskIframeTwitterAPI(res.data);
+                break;
+            case 'IFRAME_API_GET_TWEET_USER_INFO_START':
+                let data = JSON.parse(res.data.data);
+
+                TwitterApiUserByScreenName({
+                  iframeId: res.data.iframeId,
+                  ...data
+                })
+                break;
+
+            case 'GET_CONTENT_BY_TWITTER_ID':
+              sendContentByTwitterID(res.data)
+              break
         }
     }
 };

+ 3 - 2
src/iframe/ach-cashier.js

@@ -2,5 +2,6 @@ import { createApp } from 'vue'
 import App from '@/view/iframe/ach-pay/cashier.vue'
 
 const app = createApp(App);
-
-app.mount('#app');
+import CoutomSentry from "@/uilts/sentry.js"
+CoutomSentry.initVue(app)
+app.mount('#app');

+ 2 - 1
src/iframe/tool-box-buy-nft.js

@@ -3,6 +3,7 @@ import App from '@/view/iframe/tool-box/buy-nft.vue'
 import AutoLog from '@/log-center/autoLog';
 
 const app = createApp(App);
-
+import CoutomSentry from "@/uilts/sentry.js"
+CoutomSentry.initVue(app)
 app.use(AutoLog);
 app.mount('#app');

+ 3 - 2
src/iframe/tool-box-guide.js

@@ -6,10 +6,11 @@ import "ant-design-vue/dist/antd.css"; // or 'ant-design-vue/dist/antd.less'
 import {message} from "ant-design-vue";
 
 const app = createApp(App);
-
+import CoutomSentry from "@/uilts/sentry.js"
+CoutomSentry.initVue(app)
 app.use(message);
 app.mount('#app');
 
 window.onload= () => {
     document.title = 'DeNet'
-}
+}

+ 3 - 1
src/iframe/tool-box.js

@@ -1,4 +1,6 @@
 import { createApp } from 'vue'
 import App from '@/view/iframe/tool-box/index.vue'
 const app = createApp(App);
-app.mount('#app');
+import CoutomSentry from "@/uilts/sentry.js"
+CoutomSentry.initVue(app)
+app.mount('#app');

+ 3 - 0
src/iframe/treasure-hunt.js

@@ -1,6 +1,9 @@
 import { createApp } from 'vue'
 import App from '@/view/iframe/test/index.vue'
 import AutoLog from '@/log-center/autoLog';
+import CoutomSentry from "@/uilts/sentry.js"
+
 const app = createApp(App);
+CoutomSentry.initVue(app)
 app.use(AutoLog)
 app.mount('#app');

+ 4 - 2
src/logic/content/ParseCard.js

@@ -345,8 +345,10 @@ class ParseCard {
     }
     createTreasureIframe(params = { page_type, tweet_Id, post_Id, invite_code, invite_channel }) {
         let _iframe = document.createElement('iframe')
-        _iframe.id = params.post_Id
-        _iframe.src = chromeExtensionUrl + ('iframe/treasure-hunt.html') + `?params=${JSON.stringify(params)}&iframeId=${guid()}`;
+        console.log('post_Id',params.post_Id)
+        let rid = guid();
+        _iframe.id = rid;
+        _iframe.src = chromeExtensionUrl + ('iframe/treasure-hunt.html') + `?params=${JSON.stringify(params)}&iframeId=${rid}`;
         _iframe.style.cssText = 'border:medium none; width:375px; min-height:580px; border: 1px solid #DCDCDC; border-radius: 20px;'
         return _iframe
     }

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

@@ -1070,7 +1070,7 @@ export function init() {
 }
 
 export const getTweetUserFollowStatus = (params) => {
-    let { tweetId, userList } = params.data;
+    let { tweetId, userList, iframeGUId, type } = JSON.parse(params.data);
     let promiseList = [];
     for (let i = 0; i < userList.length; i++) {
         promiseList[i] = TwitterApiUserByScreenNameReq({ screen_name: userList[i]['name'] });
@@ -1087,10 +1087,16 @@ export const getTweetUserFollowStatus = (params) => {
               }
           }
         }
+        messageCenter.send(params.iframeId, 'CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES', {
+          list, tweetId, type, iframeId: params.iframeId, iframeGUId
+        })
 
-        chrome.runtime.sendMessage({ actionType: 'CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES', data: list, tweetId, type: params.type, iframeId: params.iframeId }, () => { })
+        // chrome.runtime.sendMessage({ actionType: 'CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES', data: list, tweetId, type: params.type, iframeId: params.iframeId }, () => { })
     }).catch(err => {
-      chrome.runtime.sendMessage({ actionType: 'CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES', data: [], tweetId, type: params.type, iframeId: params.iframeId }, () => { })
+      messageCenter.send(params.iframeId, 'CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES', {
+        list: [], tweetId, type, iframeId: params.iframeId, iframeGUId
+      })
+      // chrome.runtime.sendMessage({ actionType: 'CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES', data: [], tweetId, type: params.type, iframeId: params.iframeId }, () => { })
     })
 }
 
@@ -1455,6 +1461,35 @@ export function doTaskTwitterAPI({ task_data, task_type, tasks, iframeId }) {
     }
 }
 
+export function doTaskIframeTwitterAPI(params) {
+  let {tweet_Id, tweet_text, task_type, tasks, iframeGUId} = JSON.parse(params.data);
+  if(task_type == 'tasks') {
+    tasks.forEach((item) => {
+        switch (String(item.type)) {
+            // 关注指定用户
+            case '1':
+                item.relatedUsers.forEach((item) => {
+                    if (item.name && item.twitterUserId) {
+                        TwitterFollowAPI(item, tweet_Id);
+                    }
+                })
+                break
+            // 点赞
+            case '2':
+                TwitterLikeAPI(tweet_Id)
+                break
+            // 推文发推
+            case '10':
+                // 发推
+                TwitterApiCreateTweet({ text: tweet_text, tweet_Id, iframeId: params.iframeId, iframeGUId, iframeMsg: true })
+                break
+        }
+    })
+  } else if(task_type == 'like') {
+    TwitterLikeAPI(tweet_Id)
+  }
+}
+
 export function showJoinDialog(data) {
     let iframe = document.querySelector('#nftProjectId')
     iframe.style.display = 'block'
@@ -1601,7 +1636,8 @@ const TwitterLikeAPI = (tweet_Id) => {
     })
 }
 
-const TwitterApiCreateTweet = ({ text, tweet_Id, iframeId }) => {
+const TwitterApiCreateTweet = ({ text, tweet_Id, iframeId,
+  iframeGUId, iframeMsg }) => {
     let data = {
         queryId: "hC1nuE-2d1NX5LYBuuAvtQ",
         features: {
@@ -1647,9 +1683,25 @@ const TwitterApiCreateTweet = ({ text, tweet_Id, iframeId }) => {
             "x-twitter-client-language": "en"
         },
     }).then(function (response) {
+      console.log(response)
+      let data = response.data;
+      if(iframeMsg) {
+        messageCenter.send(iframeId, 'CONTENT_CREATE_TWEET_FINISH', {
+          tweet_Id, iframeId, iframeGUId, response: data, done: true
+        })
+      } else {
         chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'createTweet1', task_data: '', task_done: '是', response, iframeId })
+      }
     }).catch(function (err) {
+      console.log('err --1', err)
+      if(iframeMsg) {
+        messageCenter.send(iframeId, 'CONTENT_CREATE_TWEET_FINISH', {
+          tweet_Id, iframeId, iframeGUId, done: false
+        })
+
+      } else {
         chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'createTweet1', task_data: '', task_done: '否', iframeId })
+      }
     });
 }
 
@@ -1677,12 +1729,25 @@ const TwitterApiUserByScreenNameReq = (params) => {
 
 
 export const TwitterApiUserByScreenName = (params, cb) => {
-    let { screen_name, tweetId = '', objectType = '', iframeId = '' } = params;
+    let { screen_name, tweetId = '', objectType = '', iframeId = '', iframeMsg = false, iframeGUId } = params;
 
     TwitterApiUserByScreenNameReq({ screen_name }).then(function (response) {
+      if(iframeMsg) {
+        messageCenter.send(iframeId, 'CONTENT_API_GET_TWEET_USER_INFO_END', {
+          iframeGUId, response: response.data.data || {}, objectType
+        })
+      } else {
         chrome.runtime.sendMessage({ actionType: "CONTENT_API_GET_TWEET_USER_INFO_RES", data: response.data.data || {}, tweetId, objectType, iframeId }, () => { })
+      }
+
     }).catch(function (err) {
+      if(iframeMsg) {
+        messageCenter.send(iframeId, 'CONTENT_API_GET_TWEET_USER_INFO_END', {
+          iframeGUId, response: {}, objectType
+        })
+      } else {
         chrome.runtime.sendMessage({ actionType: "CONTENT_API_GET_TWEET_USER_INFO_RES", data: {}, tweetId, objectType, iframeId }, () => { })
+      }
     });
 }
 
@@ -2719,14 +2784,18 @@ export const showPublishDialog = () => {
 }
 
 // 获取推文发送回去
-export const sendContentByTwitterID = (tweet_Id) => {
+export const sendContentByTwitterID = (params) => {
+  let {tweet_Id, iframeGUId} = JSON.parse(params.data);
     // 获取内容
-    let txt = parseCard.getContentByTwitterId(tweet_Id)
-    // 发送
-    chrome.runtime.sendMessage({
-        actionType: "CONTENT_GET_TWEET_TXT", data: {
-            tweet_Id,
-            txt
-        }
+    let txt = parseCard.getContentByTwitterId(tweet_Id);
+    messageCenter.send(params.iframeId, 'CONTENT_GET_TWEET_TXT', {
+      iframeGUId, tweet_Id, txt
     })
+    // 发送
+    // chrome.runtime.sendMessage({
+    //     actionType: "CONTENT_GET_TWEET_TXT", data: {
+    //         tweet_Id,
+    //         txt
+    //     }
+    // })
 }

+ 3 - 3
src/manifest.json

@@ -2,8 +2,8 @@
     "manifest_version": 3,
     "name": "DeNet",
     "description": "Growing more twitter followers with Denet",
-    "version": "1.1.7.2",
-    "denet_app_version_code": "22",
+    "version": "1.1.7.3",
+    "denet_app_version_code": "23",
     "background": {
         "service_worker": "/js/background.js"
     },
@@ -107,4 +107,4 @@
             ]
         }
     ]
-}
+}

+ 123 - 21
src/view/iframe/treasure-hunt/cover.vue

@@ -1,6 +1,6 @@
 <template>
     <!-- 封面页 -->
-    <div class="cover" v-show-log="state.log_show">
+    <div class="cover">
         <v-head :left-data="state.detail.postUserInfo || null"></v-head>
         <div class="waring" v-if="state.cover_status == '奖励已被领光'">
             <div>All treasures</div>
@@ -50,7 +50,7 @@
 
 </template>
 <script setup>
-import { inject } from 'vue'
+import { inject, onMounted } from 'vue'
 import VBtn from '@/view/iframe/treasure-hunt/components/btn.vue'
 import VHead from '@/view/iframe/treasure-hunt/components/head.vue'
 import ComponentZoom from "@/view/components/component-zoom.vue";
@@ -107,7 +107,7 @@ const toStart = (req) => {
             })
             state.start_task = res.data
             if (req.response) {
-                let repost_tweetId = req.response.data.data.create_tweet.tweet_results.result.rest_id
+                let repost_tweetId = req.response.data.create_tweet.tweet_results.result.rest_id
                 reSetBindRepost({
                     inviteCode: res.data.inviteCode,
                     tweetId: repost_tweetId
@@ -121,7 +121,7 @@ const toStart = (req) => {
         console.error(error)
     })
 }
-
+/**
 chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
     switch (req.actionType) {
         case 'DO_TASK':
@@ -229,7 +229,7 @@ chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
             break;
     }
 })
-
+ */
 const getFollowStatus = (arr = []) => {
     let list = [];
     let userInfoList = arr;
@@ -296,15 +296,26 @@ const logPreRepost = () => {
         })
     }
 
-    sendCurrentTabMessage({
-        actionType: "IFRAME_API_GET_TWEET_USER_FOLLOW_STATUS",
-        data: {
-            userList: names,
-            tweetId: state.tweetId
-        },
+    window.parent.postMessage({
+      actionType: "IFRAME_API_GET_TWEET_USER_FOLLOW_STATUS",
+      data: JSON.stringify({
+        userList: names,
+        tweetId: state.tweetId,
+        iframeGUId: state.iframeId,
         type: 'pre_repost',
-        iframeId: state.iframeId
-    })
+      }),
+      iframeId: state.iframeId
+    }, "*");
+
+    // sendCurrentTabMessage({
+    //     actionType: "IFRAME_API_GET_TWEET_USER_FOLLOW_STATUS",
+    //     data: {
+    //         userList: names,
+    //         tweetId: state.tweetId
+    //     },
+    //     type: 'pre_repost',
+    //     iframeId: state.iframeId
+    // })
     log_pre_repost.params = params
     log_pre_repost.names = names
 }
@@ -393,17 +404,108 @@ const getUsersFollowStatus = () => {
     let userList = state.follows;
 
     if (userList && userList.length) {
-        sendCurrentTabMessage({
-            actionType: "IFRAME_API_GET_TWEET_USER_FOLLOW_STATUS",
-            data: {
-                userList: userList,
-                tweetId: state.tweetId,
-            },
-            iframeId: state.iframeId
-        })
+        window.parent.postMessage({
+          actionType: "IFRAME_API_GET_TWEET_USER_FOLLOW_STATUS",
+          data: JSON.stringify({
+            userList: userList,
+            tweetId: state.tweetId,
+            iframeGUId: state.iframeId
+          }),
+          iframeId: state.iframeId
+        }, "*");
+    }
+}
+
+const onWindowMessage = () => {
+  window.onmessage = (res) => {
+    console.log('onWindowMessage', res);
+    if(res && res.data && res.data.actionType) {
+      let msgData = res.data.data;
+      if(msgData.iframeGUId == state.iframeId) {
+        switch (res.data.actionType) {
+          case "CONTENT_API_GET_TWEET_USER_INFO_END":
+            let twitterFans = 0;
+            let { user } = msgData.response || {};
+            if (user && user.result && user.result.legacy) {
+                let legacy = user.result.legacy;
+                twitterFans = legacy ? legacy.followers_count : 0;
+            }
+            if (msgData.objectType == Report.objectType.repostSuccess) {
+                Report.reportLog({
+                    objectType: Report.objectType.repostSuccess,
+                    twitterFans: twitterFans,
+                    redPacketType: Report.redPacketType.treasure,
+                    postId: state.postId,
+                    shareLinkId: state.invite_code,
+                });
+            };
+            break;
+          case "CONTENT_CREATE_TWEET_FINISH":
+            if(!msgData.done) {
+              state.toast.txt = 'Seems something went wrong, please try again'
+              state.toast.show = true
+              state.toast.has_icon = false
+              setTimeout(() => {
+                  state.toast.show = false
+              }, 2000)
+            } else {
+              toStart(msgData);
+                getChromeStorage('userInfo', (_userInfo) => {
+                  if (_userInfo) {
+                    window.parent.postMessage({
+                      actionType: "IFRAME_API_GET_TWEET_USER_INFO_START",
+                      data: JSON.stringify({
+                        screen_name: _userInfo.nickName,
+                        tweetId: state.tweetId,
+                        objectType: Report.objectType.repostSuccess,
+                        iframeGUId: state.iframeId,
+                        iframeMsg: true
+                      }),
+                      iframeId: state.iframeId
+                    }, "*");
+                  }
+                })
+            }
+
+            break;
+          case "CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES":
+              state.usersFollowStatusList = getFollowStatus(msgData.list);
+              // 上报埋点
+              // 做任务
+              // 一键三连
+              window.parent.postMessage({
+                actionType: "IFRAME_TWITTER_API_DO_TASK",
+                data: JSON.stringify({
+                  tweet_Id: state.tweetId,
+                  tweet_text: state.rePostTweetContent,
+                  task_type: 'tasks',
+                  tasks: state.tasks,
+                  iframeGUId: state.iframeId
+                }),
+                iframeId: state.iframeId
+              }, "*");
+
+              // double like
+              window.parent.postMessage({
+                actionType: "IFRAME_TWITTER_API_DO_TASK",
+                data: JSON.stringify({
+                  tweet_Id: state.detail.srcContentId,
+                  task_type: 'like',
+                  iframeGUId: state.iframeId
+                }),
+                iframeId: state.iframeId
+              }, "*");
+            break;
+        }
+      }
     }
+  }
 }
 
+onMounted(() => {
+  onWindowMessage();
+})
+
 </script>
 <style lang="scss" scoped>
 .cover {

+ 74 - 16
src/view/iframe/treasure-hunt/index.vue

@@ -62,9 +62,47 @@ onMounted(() => {
     state.page_type = params.page_type || ''
 
     state.init();
-    onRuntimeMsg();
+    // onRuntimeMsg();
+    onWindowMessage();
 })
 
+const onWindowMessage = () => {
+  window.onmessage = (res) => {
+    console.log('onWindowMessage', res);
+    if(res && res.data && res.data.actionType) {
+      let msgData = res.data.data;
+      if(msgData.iframeGUId == state.iframeId) {
+        switch (res.data.actionType) {
+          case "CONTENT_GET_TWEET_TXT":
+            if (msgData.tweet_Id == state.tweetId && !state.detail.postSrcContent) {
+              state.detail.postSrcContent = msgData.txt
+              reSetBindPostContent({
+                  postId: state.postId || '',
+                  postSrcContent: msgData.txt,
+              })
+            }
+            break;
+          case "CONTENT_API_GET_TWEET_USER_INFO_END":
+            let twitterFans = 0;
+            let { user } = msgData.response || {};
+            if (user && user.result && user.result.legacy) {
+                let legacy = user.result.legacy;
+                twitterFans = legacy ? legacy.followers_count : 0;
+            }
+            if (msgData.objectType == Report.objectType.tweetPostBinded) {
+                Report.reportLog({
+                  objectType: Report.objectType.tweetPostBinded,
+                  twitterFans: twitterFans,
+                  redPacketType: Report.redPacketType.treasure,
+                  postId: state.postId
+                });
+            }
+            break;
+        }
+      }
+    }
+  }
+}
 state.checkIsLogin = () => {
     return new Promise((resolve) => {
         getChromeStorage('userInfo', (_userInfo) => {
@@ -115,12 +153,21 @@ state.init = (callback) => {
                 handleCommon(res, callback)
                 // 原始链接绑定post content
                 if (!res.data.postSrcContent) {
-                    sendCurrentTabMessage({
-                        actionType: "GET_CONTENT_BY_TWITTER_ID",
-                        data: {
-                            tweet_Id: state.tweetId
-                        }
-                    })
+
+                    window.parent.postMessage({
+                      actionType: "GET_CONTENT_BY_TWITTER_ID",
+                      data: JSON.stringify({
+                        tweet_Id: state.tweetId,
+                        iframeGUId: state.iframeId,
+                      }),
+                      iframeId: state.iframeId
+                    }, "*");
+                    // sendCurrentTabMessage({
+                    //     actionType: "GET_CONTENT_BY_TWITTER_ID",
+                    //     data: {
+                    //         tweet_Id: state.tweetId
+                    //     }
+                    // })
                 }
             }
         })
@@ -174,15 +221,17 @@ const handleCommon = (res, callback) => {
             postId: state.postId || '',
             tweetId: state.tweetId || ''
         }, () => {
-            sendCurrentTabMessage({
-                actionType: "IFRAME_API_GET_TWEET_USER_INFO_REQ",
-                data: {
-                    screen_name: state.detail.postUserInfo.nickName,
-                    tweetId: state.tweetId,
-                    objectType: Report.objectType.tweetPostBinded,
-                    iframeId: state.iframeId
-                }
-            })
+            window.parent.postMessage({
+              actionType: "IFRAME_API_GET_TWEET_USER_INFO_START",
+              data: JSON.stringify({
+                screen_name: state.detail.postUserInfo.nickName,
+                tweetId: state.tweetId,
+                objectType: Report.objectType.tweetPostBinded,
+                iframeGUId: state.iframeId,
+                iframeMsg: true
+              }),
+              iframeId: state.iframeId
+            }, "*");
             state.init()
         })
     }
@@ -285,6 +334,15 @@ const handleStatus = (callback) => {
             state.open_btn.txt = 'Start'
             // state.cover_status = '无邀请人'
             // state.cover_status = '奖励已被领光'
+
+            Report.reportLog({
+              pageSource: Report.pageSource.pending_page,
+              businessType: Report.businessType.pageView,
+              postId: state.postId,
+              shareLinkId: state.invite_code,
+              currentInvitedNum: state.inviteCount,
+              redPacketType: Report.redPacketType.treasure
+            });
         }
         // 如果 夺宝参与状态 = 已参与夺宝
         else if (joinStatus == 1) {