소스 검색

[edit] iframe msg

wenliming 2 년 전
부모
커밋
b4d752d695
3개의 변경된 파일56개의 추가작업 그리고 25개의 파일을 삭제
  1. 6 6
      src/entry/content.js
  2. 16 1
      src/logic/content/facebook.js
  3. 34 18
      src/logic/content/twitter.js

+ 6 - 6
src/entry/content.js

@@ -95,9 +95,6 @@ const oldOnMessageMethod = (res) => {
         case "IFRAME_SHOW_TWITTER_PUBLISH_DIALOG":
             showTwitterPublishDialogHandler(res.data.publishRes);
             break;
-        case "IFRAME_RED_PACKET_REPLY_CLICK":
-            replyHandle(res.data.data || {});
-            break;
         case "IFRAME_RED_PACKET_SHOW_BIND_TWEET_NOTICE":
             noticeBindTweet(res.data.data || {});
             break;
@@ -128,9 +125,6 @@ const oldOnMessageMethod = (res) => {
         case 'IFRAME_PAGE_JUMP':
             pageJumpHandler(res.data.data);
             break;
-        case 'IFRAME_GET_EXTENSION_STORGE_DATA':
-            getExtensionStorgeDataForIframe(res.data.data);
-            break;
 
         case 'IFRAME_API_GET_TWEET_USER_FOLLOW_STATUS':
             getTweetUserFollowStatus(res.data);
@@ -189,6 +183,12 @@ const newOnMessageMethod = (res) => {
         case 'IFRAME_SET_EXTENSION_STORGE_DATA':
             setExtensionStorgeDataForIframe(res.data);
             break;
+        case 'IFRAME_GET_EXTENSION_STORGE_DATA':
+            getExtensionStorgeDataForIframe(res.data);
+            break;
+        case "IFRAME_RED_PACKET_REPLY_CLICK":
+            replyHandle(res.data);
+            break;
     }
 }
 

+ 16 - 1
src/logic/content/facebook.js

@@ -1,5 +1,6 @@
 import { faceShareRedirectUrl } from '@/http/configAPI'
 import { getChromeStorage } from '@/uilts/chromeExtension.js'
+import { fetchAddFinishEvent } from '@/logic/background/fetch/facebook';
 
 let tempData = {
     isSetContent: false
@@ -63,7 +64,21 @@ function shareCallback() {
         let params = JSON.parse(urlParams.get('params'));
         if (params) {
             chrome.storage.local.remove("shareFacebookData");
-            chrome.runtime.sendMessage({ actionType: "CONTENT_FACEBOOK_SHARE_SUCCESS", data: params })
+            if(!params.bizType) {
+              fetchAddFinishEvent({
+                eventType: params.type,
+                luckdropId: params.taskLuckdropId
+              }).then(res => {
+                window.close();
+                if (res.code == 0) {
+                }
+              }).catch((error) => {
+                window.close();
+                console.log('catch', error)
+              })
+            }
+
+            // chrome.runtime.sendMessage({ actionType: "CONTENT_FACEBOOK_SHARE_SUCCESS", data: params })
         }
     }
 }

+ 34 - 18
src/logic/content/twitter.js

@@ -1104,7 +1104,7 @@ export const getTweetUserFollowStatus = (params) => {
                 }
             }
         }
-        messageCenter.send({
+        contentMessageCenter.send({
             info: {
                 iframeId: params.iframeId,
                 actionType: 'CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES'
@@ -1116,7 +1116,7 @@ export const getTweetUserFollowStatus = (params) => {
 
         // chrome.runtime.sendMessage({ actionType: 'CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES', data: list, tweetId, type: params.type, iframeId: params.iframeId }, () => { })
     }).catch(err => {
-        messageCenter.send({
+        contentMessageCenter.send({
             info: {
                 iframeId: params.iframeId,
                 actionType: 'CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES'
@@ -1174,8 +1174,8 @@ export function facebookReplyTweet({ info, data }) {
     }
 }
 
-export function replyHandle(params) {
-    let iframe = window.parent.document.getElementById(params.iframeId);
+export function replyHandle({ info, data}) {
+    let iframe = window.parent.document.getElementById(data.iframeId);
     let replyBtn = iframe.parentNode.parentNode.querySelector('div[data-testid="reply"]') ||
         iframe.parentNode.parentNode.parentNode.querySelector('div[data-testid="reply"]');
     if (replyBtn) {
@@ -1197,8 +1197,16 @@ export function replyHandle(params) {
                 });
 
                 let eleList = tweetReply.parentNode.parentNode.parentNode.parentNode.parentNode.querySelectorAll('span[data-text="true"]');
-                reportReplyResult(eleList, params, () => {
-                    iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_REPLY_RASK_FINSH', data: { postId: params.postId } }, '*');
+                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: { postId: params.postId } }, '*');
                     // chrome.runtime.sendMessage({ actionType: "CONTENT_RED_PACKET_REPLY_RASK_FINSH", data: { postId: params.postId } }, () => { })
                 });
             })
@@ -1255,7 +1263,15 @@ function onReplyDialogOpen(params, iframe) {
                 let eleList = dialog.querySelector('div[contenteditable="true"]').querySelectorAll('span[data-text="true"]');
                 reportReplyResult(eleList, params, () => {
                     // 上報完成
-                    iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_REPLY_RASK_FINSH', data: { postId: params.postId } }, '*');
+                    contentMessageCenter.send({
+                      info: {
+                          actionType: 'CONTENT_RED_PACKET_REPLY_RASK_FINSH',
+                          iframeId: params.iframeId
+                      },
+                      data: { postId: params.postId }
+                    })
+
+                    // iframe.contentWindow.postMessage({ actionType: 'CONTENT_RED_PACKET_REPLY_RASK_FINSH', data: { postId: params.postId } }, '*');
                     // chrome.runtime.sendMessage({ actionType: "CONTENT_RED_PACKET_REPLY_RASK_FINSH", data: { postId: params.postId } }, () => { })
                 })
             });
@@ -1766,7 +1782,7 @@ const TwitterApiCreateTweet = ({ text, tweet_Id, iframeId,
         console.log(response)
         let data = response.data;
         if (iframeMsg) {
-            messageCenter.send({
+            contentMessageCenter.send({
                 info: {
                     iframeId,
                     actionType: 'CONTENT_CREATE_TWEET_FINISH'
@@ -1781,7 +1797,7 @@ const TwitterApiCreateTweet = ({ text, tweet_Id, iframeId,
     }).catch(function (err) {
         console.log('err --1', err)
         if (iframeMsg) {
-            messageCenter.send({
+            contentMessageCenter.send({
                 info: {
                     iframeId,
                     actionType: 'CONTENT_CREATE_TWEET_FINISH'
@@ -1825,7 +1841,7 @@ export const TwitterApiUserByScreenName = (params, cb) => {
 
     TwitterApiUserByScreenNameReq({ screen_name }).then(function (response) {
         if (iframeMsg) {
-            messageCenter.send({
+            contentMessageCenter.send({
                 info: {
                     iframeId,
                     actionType: 'CONTENT_API_GET_TWEET_USER_INFO_END'
@@ -1840,7 +1856,7 @@ export const TwitterApiUserByScreenName = (params, cb) => {
 
     }).catch(function (err) {
         if (iframeMsg) {
-            messageCenter.send({
+            contentMessageCenter.send({
                 info: {
                     iframeId,
                     actionType: 'CONTENT_API_GET_TWEET_USER_INFO_END'
@@ -2843,7 +2859,7 @@ export const getExtensionStorgeDataForIframe = (req) => {
     });
 }
 
-export const setExtensionStorgeDataForIframe = ({ info, data}) => { 
+export const setExtensionStorgeDataForIframe = ({ info, data}) => {
     setChromeStorage(data)
 }
 
@@ -2915,7 +2931,7 @@ export const sendContentByTwitterID = (params) => {
     let { tweet_Id, iframeGUId } = JSON.parse(params.data);
     // 获取内容
     let txt = parseCard.getContentByTwitterId(tweet_Id);
-    messageCenter.send({
+    contentMessageCenter.send({
       info: {
           iframeId: params.iframeId,
           actionType: 'CONTENT_GET_TWEET_TXT'
@@ -2933,7 +2949,7 @@ export const sendContentByTwitterID = (params) => {
     // })
 }
 
-export const sendLoginSuccessToAllIframe = () => { 
+export const sendLoginSuccessToAllIframe = () => {
     contentMessageCenter.sendAll({
         info: {
             actionType: "BACK_DISCORD_LOGIN_SUCCESS"
@@ -2941,7 +2957,7 @@ export const sendLoginSuccessToAllIframe = () => {
     })
 }
 
-export const sendIframeLoginToBackground = () => { 
+export const sendIframeLoginToBackground = () => {
     chromeMessageCenter.sendToSW({
         info: {
             actionType: "POPUP_LOGIN"
@@ -2949,7 +2965,7 @@ export const sendIframeLoginToBackground = () => {
     })
 }
 
-export const openUrlInNewWindow = ({ info, data }) => { 
+export const openUrlInNewWindow = ({ info, data }) => {
     chromeMessageCenter.sendToSW({
         info: {
             actionType: "OPEN_URL_IN_NEW_WINDOW_BG"
@@ -2958,7 +2974,7 @@ export const openUrlInNewWindow = ({ info, data }) => {
     })
 }
 
-export const sendAllFacebookShareSuccess = (data) => { 
+export const sendAllFacebookShareSuccess = (data) => {
     contentMessageCenter.sendAll({
         info: {
             actionType: "BG_FACEBOOK_SHARE_SUCCESS"
@@ -2967,7 +2983,7 @@ export const sendAllFacebookShareSuccess = (data) => {
     })
 }
 
-export const sendUserSettingMessageToAllIframe = (data) => { 
+export const sendUserSettingMessageToAllIframe = (data) => {
     contentMessageCenter.sendAll({
         info: {
             actionType: "USER_SETTING"