瀏覽代碼

fix redpack show

jihuaqiang 2 年之前
父節點
當前提交
951553139e

+ 8 - 2
src/entry/background.js

@@ -21,7 +21,8 @@ import {
     getTwitterNftPostPre,
     nftTxtPublish,
     getSysMessage,
-    checkShowPublishDialog
+    checkShowPublishDialog,
+    openUrlInNewWindowBG
 } from "@/logic/background/twitter";
 import Report from "@/log-center/log"
 import { PingPong, httpNetWork, httpContentToBack } from "@/logic/background/help";
@@ -250,7 +251,12 @@ const newOnMessageMethod = (req, sender, sendResponse) => {
         case 'CONTENT_TO_BACK_TEST':
             chromeMessageCenter.sendToContent(sender, { info, data: '123' })
             break;
-
+        case 'POPUP_LOGIN':
+            twitterPinLoginToken();
+            break;
+        case 'OPEN_URL_IN_NEW_WINDOW_BG':
+            openUrlInNewWindowBG({ info, data });
+            break;
         default:
             break;
     }

+ 33 - 5
src/entry/content.js

@@ -40,7 +40,13 @@ import {
     showPublishDialog,
     getTweetUserFollowStatus,
     sendContentByTwitterID,
-    getExtensionStorgeDataForIframe
+    getExtensionStorgeDataForIframe,
+    setExtensionStorgeDataForIframe,
+    sendLoginSuccessToAllIframe,
+    sendIframeLoginToBackground,
+    openUrlInNewWindow,
+    sendAllFacebookShareSuccess,
+    sendUserSettingMessageToAllIframe
 } from "@/logic/content/twitter.js";
 import denet from '@/denet'
 import { httpBackToContentCallBack } from '@/uilts/chromeExtension.js'
@@ -95,7 +101,7 @@ window.onmessage = (res) => {
                 showTwitterPublishDialogHandler(res.data.publishRes);
                 break;
             case "IFRAME_RED_PACKET_REPLY_CLICK":
-                replyHandle(res.data.data || {});
+                replyHandle(res.data || {});
                 break;
             case "IFRAME_RED_PACKET_SHOW_BIND_TWEET_NOTICE":
                 noticeBindTweet(res.data.data || {});
@@ -104,10 +110,10 @@ window.onmessage = (res) => {
                 hideNoticeBindTweet();
                 break;
             case "IFRAME_RED_PACKET_GET_TWEET_AUTHOR":
-                getTweetAuthorByDom(res.data.data || {});
+                getTweetAuthorByDom(res.data || {});
                 break;
             case "IFRAME_RED_PACKET_CHECK_FACEBOOK_REPLY":
-                facebookReplyTweet(res.data.data || {});
+                facebookReplyTweet(res.data || {});
                 break;
             case "IFRAME_RED_PACKET_ON_TWEET_REPLY_CLICK":
                 onTweetReplyClick(res.data.data || {});
@@ -130,6 +136,9 @@ window.onmessage = (res) => {
             case 'IFRAME_GET_EXTENSION_STORGE_DATA':
                 getExtensionStorgeDataForIframe(res.data);
                 break;
+            case 'IFRAME_SET_EXTENSION_STORGE_DATA':
+                setExtensionStorgeDataForIframe(res.data);
+                break;
             case 'IFRAME_DO_TASK_CREATE_TWEET':
                 doTask.TwitterApiCreateTweet({ info, data })
                 break
@@ -143,7 +152,17 @@ window.onmessage = (res) => {
                 console.log('IFRAME_TWITTER_API_DO_TASK...',res.data)
                 doTaskTwitterAPI(res.data)
                 break
-            
+            case 'IFRAME_API_GET_TWEET_USER_INFO_REQ':
+                // 从runtime 迁移
+                TwitterApiUserByScreenName(res.data)
+                break;
+            case "POPUP_LOGIN":
+                // iframe请求登录,通过content转发至 background
+                sendIframeLoginToBackground();
+                break
+            case 'OPEN_URL_IN_NEW_WINDOW':
+                openUrlInNewWindow({info, data})
+                break
         }
     }
 };
@@ -257,9 +276,18 @@ const oldOnMessageMethod = (req, sender, sendResponse) => {
         case 'GET_CONTENT_BY_TWITTER_ID':
             sendContentByTwitterID(req.data.tweet_Id)
             break
+        case 'BACK_DISCORD_LOGIN_SUCCESS':
+            sendLoginSuccessToAllIframe()
+            break
         case 'TEST':
             console.log('TEST')
             break
+        case 'BG_FACEBOOK_SHARE_SUCCESS_BG':
+            sendAllFacebookShareSuccess(req.data)
+            break
+        case 'USER_SETTING_CONTENT':
+            sendUserSettingMessageToAllIframe(req.data)
+            break
     }
 }
 

+ 2 - 1
src/logic/background/facebook.js

@@ -1,5 +1,6 @@
 import { fetchAddFinishEvent } from '@/logic/background/fetch/facebook'
 import Report from "@/log-center/log"
+import contentMessageCenter from "@/uilts/messageCenter/content"
 
 /**
  * facebook分享成功逻辑
@@ -18,7 +19,7 @@ export function facebookShareSuccess(params, sender) {
               if (res.code == 0) {
                   setTimeout(() => {
                       sendActivetabMessage({
-                          actionType: 'BG_FACEBOOK_SHARE_SUCCESS',
+                          actionType: 'BG_FACEBOOK_SHARE_SUCCESS_BG',
                           data: data
                       });
                   })

+ 10 - 0
src/logic/background/twitter.js

@@ -741,3 +741,13 @@ const createTabShowGiveaway = (params) => {
         url: params.url,
     });
 }
+
+export const openUrlInNewWindowBG = ({ info, data }) => { 
+    chrome.windows.create(data, (window) => { 
+        saveDiscordAuthWindowId({
+            data: {
+                windowId: window.id
+            }
+        })
+    })
+}

+ 141 - 42
src/logic/content/twitter.js

@@ -10,7 +10,8 @@ import { jumpTwitterDetailByAlert, showEditTweet } from '@/logic/content/help/tw
 import { clearPostContent, setGroupIconStatus } from '@/logic/content/nft.js'
 import { toolBox } from '@/logic/content/ToolBox'
 import axios from 'axios';
-import messageCenter from '@/uilts/messageCenter/content';
+import contentMessageCenter from '@/uilts/messageCenter/content';
+import chromeMessageCenter from '@/uilts/messageCenter/chrome';
 import { PlayType } from '@/types';
 import { reSetBindPostContent } from '@/http/help.js';
 import { setDeviceInfo } from '@/logic/content/help/twitter';
@@ -795,6 +796,7 @@ export function bindTwitterArtMethod() {
 
 
 import parseCard from './ParseCard'
+import iframeMessageCenter from '../../uilts/messageCenter/iframe'
 
 // 检测dom改变
 // 获取短链接
@@ -1120,29 +1122,33 @@ function checkHasSliderDeBtn() {
     }
 }
 
-export function facebookReplyTweet(params) {
+export function facebookReplyTweet({ info, data }) {
     if (window.location.origin.indexOf('twitter.com')) {
         const urlParams = new URLSearchParams(window.location.search);
         const actionType = urlParams.get('actionType');
         let deReplyParams = urlParams.get('deReplyParams') || '{}';
         deReplyParams = JSON.parse(deReplyParams);
         if (actionType == 'denetFacebookToTwitterReply') {
-            if (params.postId == deReplyParams.postId) {
-                let iframe = document.getElementById(params.postId);
-                iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_FACEBOOK_REPLY', data: deReplyParams }, '*');
+            if (data.postId == deReplyParams.postId) {
+                contentMessageCenter.send({
+                    info,
+                    data: deReplyParams
+                })
+                // let iframe = document.getElementById(params.info.iframeId);
+                // iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_FACEBOOK_REPLY', data: deReplyParams }, '*');
             }
         }
     }
 }
 
-export function replyHandle(params) {
-    let iframe = window.parent.document.getElementById(params.postId);
+export function replyHandle({ info, data}) {
+    let iframe = window.parent.document.getElementById(data.postId);
     let replyBtn = iframe.parentNode.parentNode.querySelector('div[data-testid="reply"]') ||
         iframe.parentNode.parentNode.parentNode.querySelector('div[data-testid="reply"]');
     if (replyBtn) {
         replyBtn.click();
     }
-    onReplyDialogOpen(params, iframe);
+    onReplyDialogOpen(data, iframe);
 
     // 详情页推文底部评论处理
     let pathNameArr = window.location.pathname.split('/');
@@ -1158,9 +1164,16 @@ export function replyHandle(params) {
                 });
 
                 let eleList = tweetReply.parentNode.parentNode.parentNode.parentNode.parentNode.querySelectorAll('span[data-text="true"]');
-                reportReplyResult(eleList, params, () => {
+                reportReplyResult(eleList, data, () => {
+                    contentMessageCenter.send({
+                        info: {
+                            actionType: 'CONTENT_RED_PACKET_REPLY_RASK_FINSH',
+                            iframeId: info.iframeId
+                        },
+                        data: { postId: data.postId }
+                    })
                     // iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_REPLY_RASK_FINSH', data: {} }, '*');
-                    chrome.runtime.sendMessage({ actionType: "CONTENT_RED_PACKET_REPLY_RASK_FINSH", data: { postId: params.postId } }, () => { })
+                    // chrome.runtime.sendMessage({ actionType: "CONTENT_RED_PACKET_REPLY_RASK_FINSH", data: { postId: data.postId } }, () => { })
                 });
             })
         }
@@ -1389,8 +1402,8 @@ export function checkTwitterTaskState() {
     }, 1000)
 }
 
-export function getTweetAuthorByDom(params) {
-    let iframe = document.getElementById(params.postId);
+export function getTweetAuthorByDom({ info, data}) {
+    let iframe = document.getElementById(info.iframeId);
     if (!iframe) {
         return;
     }
@@ -1406,7 +1419,11 @@ export function getTweetAuthorByDom(params) {
         if (arr.length) {
             let fullName = arr[arr.length - 1];
             if (fullName) {
-                iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_GET_TWEET_AUTHOR', data: { fullName } }, '*');
+                contentMessageCenter.send({
+                    info,
+                    data: {fullName}
+                })
+                // iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_GET_TWEET_AUTHOR', data: { fullName } }, '*');
             }
         }
     }
@@ -1415,10 +1432,10 @@ export function doTaskTwitterAPI({ info, data }) {
     const { task_data, task_type, tasks } = data
     switch (task_type) {
         case 'like':
-            TwitterLikeAPI(task_data.tweet_Id)
+            TwitterLikeAPI(task_data.tweet_Id, info)
             break
         case 'retweet':
-            TwitterRetweetAPI(task_data.tweet_Id)
+            TwitterRetweetAPI(task_data.tweet_Id, info)
             break
         case 'follow':
             task_data.follow_data.forEach((item) => {
@@ -1506,6 +1523,7 @@ const TwitterFriendshipsUpdate = (params) => {
 }
 
 const TwitterFollowAPI = (item, tweet_Id, info) => {
+    console.log('TwitterFollowAPI', item, tweet_Id, info)
     fetch("https://twitter.com/i/api/1.1/friendships/create.json", {
         "headers": {
             "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
@@ -1529,11 +1547,8 @@ const TwitterFollowAPI = (item, tweet_Id, info) => {
             follow_name: item.name
         }
         TwitterFriendshipsUpdate({ id: item.twitterUserId, name: item.name })
-        messageCenter.send({
-            info: {
-                actionType: "DO_TASK",
-                iframeId: info.iframeId
-            },
+       contentMessageCenter.send({
+            info,
             data: {
                 do_type: 'api', tweet_Id, task_type: 'follow', task_data, task_done: true
             }
@@ -1541,11 +1556,8 @@ const TwitterFollowAPI = (item, tweet_Id, info) => {
         // chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'follow', task_data, task_done: true }, () => { })
     }).catch(() => {
         console.log('DO_TASK3')
-        messageCenter.send({
-            info: {
-                actionType: "DO_TASK",
-                iframeId: info.iframeId
-            },
+       contentMessageCenter.send({
+            info,
             data: {
                 do_type: 'api', tweet_Id, task_type: 'follow', task_data, task_done: false
             }
@@ -1555,7 +1567,7 @@ const TwitterFollowAPI = (item, tweet_Id, info) => {
 }
 
 
-const TwitterRetweetAPI = (tweet_Id) => {
+const TwitterRetweetAPI = (tweet_Id, info) => {
     fetch("https://twitter.com/i/api/graphql/ojPdsZsimiJrUGLR1sjUtA/CreateRetweet", {
         "headers": {
             "accept": "*/*",
@@ -1580,14 +1592,26 @@ const TwitterRetweetAPI = (tweet_Id) => {
         "mode": "cors",
         "credentials": "include"
     }).then(() => {
-        chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: true }, () => { })
+       contentMessageCenter.send({
+            info,
+            data: {
+                do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: true
+            }
+        })
+        // chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: true }, () => { })
     }).catch(() => {
         console.log('DO0_TASK4')
-        chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: false }, () => { })
+       contentMessageCenter.send({
+            info,
+            data: {
+                do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: true
+            }
+        })
+        // chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'retweet', task_data: '', task_done: false }, () => { })
     })
 }
 
-const TwitterLikeAPI = (tweet_Id) => {
+const TwitterLikeAPI = (tweet_Id, info) => {
     fetch("https://twitter.com/i/api/graphql/lI07N6Otwv1PhnEgXILM7A/FavoriteTweet", {
         "headers": {
             "accept": "*/*",
@@ -1612,10 +1636,22 @@ const TwitterLikeAPI = (tweet_Id) => {
         "mode": "cors",
         "credentials": "include"
     }).then(() => {
-        chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: true }, () => { })
+       contentMessageCenter.send({
+            info,
+            data: {
+                do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: true
+            }
+        })
+        // chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: true }, () => { })
     }).catch(() => {
         console.log('DO_TASK5')
-        chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: false }, () => { })
+       contentMessageCenter.send({
+            info,
+            data: {
+                do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: false
+            }
+        })
+        // chrome.runtime.sendMessage({ actionType: "DO_TASK", do_type: 'api', tweet_Id, task_type: 'like', task_data: '', task_done: false }, () => { })
     })
 }
 
@@ -1694,12 +1730,32 @@ const TwitterApiUserByScreenNameReq = (params) => {
 }
 
 
-export const TwitterApiUserByScreenName = (params, cb) => {
+export const TwitterApiUserByScreenName = ({info, data}) => {
     let { screen_name, tweetId = '', objectType = '', iframeId = '' } = params;
 
     TwitterApiUserByScreenNameReq({ screen_name }).then(function (response) {
+       contentMessageCenter.send({
+            info,
+            data: {
+                data: response.data.data || {},
+                tweetId,
+                objectType,
+                iframeId
+            }
+        })
+        // treasure 使用 runtime
         chrome.runtime.sendMessage({ actionType: "CONTENT_API_GET_TWEET_USER_INFO_RES", data: response.data.data || {}, tweetId, objectType, iframeId }, () => { })
     }).catch(function (err) {
+       contentMessageCenter.send({
+            info,
+            data: {
+                data: {},
+                tweetId,
+                objectType,
+                iframeId
+            }
+        })
+        // treasure 使用 runtime
         chrome.runtime.sendMessage({ actionType: "CONTENT_API_GET_TWEET_USER_INFO_RES", data: {}, tweetId, objectType, iframeId }, () => { })
     });
 }
@@ -2356,7 +2412,7 @@ const addPageScrollEvent = () => {
         contentHeight: contentDom.offsetHeight
     }
 
-    messageCenter.send({
+   contentMessageCenter.send({
         info: {
             iframeId: 'de-tab-group-content', actionType: 'CONTENT_GROUP_LIST_SCROLL'
         },
@@ -2447,7 +2503,7 @@ const setGroupTabSelfStyle = (params = {}) => {
  * 切换到 Group tab时 刷新列表
  */
 export const refreshTabGroup = () => {
-    messageCenter.send({
+   contentMessageCenter.send({
         info: {
             iframeId: 'de-tab-group-content', actionType: 'CONTENT_REFRESH_TAB_GROUP_LIST'
         }
@@ -2634,7 +2690,7 @@ export const pageJumpHandler = (params) => {
 export const getTweetProfileNavTop = (params) => {
     let top = document.querySelector('div[role="tablist"]').closest('nav').getBoundingClientRect().top;
 
-    messageCenter.send({
+   contentMessageCenter.send({
         info: {
             actionType: "CONTENT_SEND_GROUP_NAV_TOP"
         },
@@ -2683,18 +2739,18 @@ export const setGroupInfo = (params = {}) => {
 
 export const getExtensionStorgeDataForIframe = (req) => {
     const { info, data } = req
-    console.log('getExtensionStorgeDataForIframe', info, data);
     getChromeStorage(data.key).then((res) => {
-        messageCenter.send({
-            info: {
-                iframeId: info.iframeId,
-                actionType: info.messageId
-            },
+       contentMessageCenter.send({
+            info,
             data: res
         })
     });
 }
 
+export const setExtensionStorgeDataForIframe = ({ info, data}) => { 
+    setChromeStorage(data)
+}
+
 const getSysTheme = () => {
     const themeMedia = window.matchMedia("(prefers-color-scheme: light)");
     if (themeMedia.matches) {
@@ -2717,7 +2773,7 @@ const getSysTheme = () => {
 const sysThemeChange = () => {
     setTimeout(() => {
         let bgColor = document.querySelector('body').style.backgroundColor;
-        messageCenter.send({
+       contentMessageCenter.send({
             info: {
                 actionType: "CONTENT_SYS_THEME_CHANGE"
             },
@@ -2770,3 +2826,46 @@ export const sendContentByTwitterID = (tweet_Id) => {
         }
     })
 }
+
+export const sendLoginSuccessToAllIframe = () => { 
+    contentMessageCenter.sendAll({
+        info: {
+            actionType: "BACK_DISCORD_LOGIN_SUCCESS"
+        }
+    })
+}
+
+export const sendIframeLoginToBackground = () => { 
+    chromeMessageCenter.sendToSW({
+        info: {
+            actionType: "POPUP_LOGIN"
+        }
+    })
+}
+
+export const openUrlInNewWindow = ({ info, data }) => { 
+    chromeMessageCenter.sendToSW({
+        info: {
+            actionType: "OPEN_URL_IN_NEW_WINDOW_BG"
+        },
+        data
+    })
+}
+
+export const sendAllFacebookShareSuccess = (data) => { 
+    contentMessageCenter.sendAll({
+        info: {
+            actionType: "BG_FACEBOOK_SHARE_SUCCESS"
+        },
+        data
+    })
+}
+
+export const sendUserSettingMessageToAllIframe = (data) => { 
+    contentMessageCenter.sendAll({
+        info: {
+            actionType: "USER_SETTING"
+        },
+        data
+    })
+}

+ 8 - 7
src/view/popup/setting/index.vue

@@ -22,6 +22,7 @@
 import { onBeforeMount, ref } from "vue";
 import router from "@/router/popup.js";
 import { getSetting, putSetting } from "@/http/user";
+import chromeMessageCenter from "@/uilts/messageCenter/chrome"
 
 let noticeStatus = ref(true);
 let noticeShow = ref(false);
@@ -50,14 +51,14 @@ function change(checked) {
 }
 
 function noticeSetting() {
-    chrome.runtime.sendMessage({
-        actionType: "USER_SETTING",
-        data: {
-            status: noticeStatus.value
+    chrome.tabs.query({}, (tabs = []) => {
+        if (tabs.length) {
+            let tab = tabs.filter((item) => { return item.active == true })
+            if (tab.length) {
+                chrome.tabs.sendMessage(tab[0].id, { actionType: 'USER_SETTING_CONTENT', data: {status: noticeStatus.value} });
+            }
         }
-    }, (response) => {
-        console.log("res", response);
-    });
+    })
 }
 
 onBeforeMount(() => {

File diff suppressed because it is too large
+ 592 - 7
yarn.lock


Some files were not shown because too many files changed in this diff