|
@@ -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
|
|
|
+ })
|
|
|
+}
|