|
@@ -1,13 +1,35 @@
|
|
|
import { getChromeStorage, setChromeStorage } from '@/uilts/chromeExtension.js'
|
|
|
-import { throttle, getQueryString, getCookie, nextTick } from '@/uilts/help'
|
|
|
+import { throttle, getQueryString, getCookie, nextTick, getQueryStringByUrl } from '@/uilts/help'
|
|
|
import { discordAuthRedirectUri } from '@/http/configAPI'
|
|
|
import { reportSrcPublishEvent } from '@/http/publishApi'
|
|
|
import Report from "@/log-center/log"
|
|
|
import { fetchAddFinishEvent } from '@/logic/background/fetch/facebook';
|
|
|
+import { showNFTGroupIcon, hideNFTGroupList, checkUserJoinGroup, elemAddEventListener, addJoinedGroupList } from '@/logic/content/nft';
|
|
|
+import { getTwitterNftGroupInfo } from '@/http/nft'
|
|
|
+import { jumpTwitterDetailByAlert, showEditTweet } from '@/logic/content/help/twitter.js'
|
|
|
+import { clearPostContent } from '@/logic/content/nft.js'
|
|
|
|
|
|
let dom = {};
|
|
|
|
|
|
+let tweetAccountBindGroupInfo = {
|
|
|
+ isBind: false,
|
|
|
+ groupInfo: null,
|
|
|
+ isInit: false
|
|
|
+}
|
|
|
+
|
|
|
+let systemInfo = {
|
|
|
+ theme: 'light'
|
|
|
+}
|
|
|
+
|
|
|
+let fixProfileTabAutoTimer = null;
|
|
|
+
|
|
|
+
|
|
|
+let pin_login = false
|
|
|
function twitterPinLogin() {
|
|
|
+ if(pin_login){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ pin_login = true
|
|
|
if (window.location.href == 'https://api.twitter.com/oauth/authorize') {
|
|
|
let code = document.querySelector('code')
|
|
|
|
|
@@ -177,7 +199,7 @@ function getUserInfo(cb) {
|
|
|
}
|
|
|
|
|
|
// 绑定推文id所需参数
|
|
|
-let bindTwitterArt = {
|
|
|
+export let bindTwitterArt = {
|
|
|
needBind: false,
|
|
|
postId: '',
|
|
|
isBindIng: false
|
|
@@ -313,7 +335,7 @@ function _addDeNetBtn() {
|
|
|
let innerDeIcon = document.getElementById('de-btn1');
|
|
|
if (!innerDeIcon) {
|
|
|
let dialogScheduleBtn = _getScheduleDom(false);
|
|
|
- _addDeNetEditBtn(dialogScheduleBtn, dom.deBtn1);
|
|
|
+ dom && dom.deBtn1 && _addDeNetEditBtn(dialogScheduleBtn, dom.deBtn1);
|
|
|
}
|
|
|
}, 800)
|
|
|
}
|
|
@@ -367,7 +389,12 @@ function addPublishTipsIframe(params = {}) {
|
|
|
|
|
|
let iframe = document.createElement('iframe');
|
|
|
iframe.id = 'de-publish-tips'
|
|
|
- iframe.src = chrome.runtime.getURL('/iframe/publish-tips.html');
|
|
|
+ if (params.type == 'nft') {
|
|
|
+ iframe.src = chrome.runtime.getURL('/iframe/publish-tips.html?type="nft"');
|
|
|
+ } else {
|
|
|
+ iframe.src = chrome.runtime.getURL('/iframe/publish-tips.html');
|
|
|
+ }
|
|
|
+
|
|
|
iframe.style.cssText = `border: medium none; width:270px;height:500px;position: fixed; right: ${right}px; top: 5%;z-index: -1`
|
|
|
let iframeContent = document.getElementById('de-publish-tips');
|
|
|
if (!iframeContent) {
|
|
@@ -416,7 +443,7 @@ function _deNetBtnClick() {
|
|
|
if (loadIcon) {
|
|
|
return;
|
|
|
}
|
|
|
- dom.deBtn.insertBefore(dom.loadingImg, dom.deBtn.querySelector('span'));
|
|
|
+ dom && dom.deBtn && dom.deBtn.insertBefore(dom.loadingImg, dom.deBtn.querySelector('span'));
|
|
|
setTimeout(() => {
|
|
|
dom.loadingImg.style.transform = 'rotate(1080deg)'
|
|
|
});
|
|
@@ -436,7 +463,7 @@ function _deNetBtnClick() {
|
|
|
* @private
|
|
|
*/
|
|
|
let isSetContent = false;
|
|
|
-const _setPublishContent = throttle(function (content, time = 1000) {
|
|
|
+export const _setPublishContent = throttle(function (content, time = 1000) {
|
|
|
if (!isSetContent) {
|
|
|
isSetContent = true;
|
|
|
let inputEle = document.querySelector('div[contenteditable="true"]');
|
|
@@ -541,7 +568,7 @@ function addSliderNavDeBtn(isSmall = false) {
|
|
|
let bigDom = document.querySelector('a[href="/compose/tweet"]').parentNode.parentNode;
|
|
|
let deBtn = document.getElementById('de-btn');
|
|
|
if (bigDom && !deBtn) {
|
|
|
- bigDom.appendChild(dom.deBtn);
|
|
|
+ dom && dom.deBtn && bigDom.appendChild(dom.deBtn);
|
|
|
Report.reportLog({
|
|
|
pageSource: Report.pageSource.mainPage,
|
|
|
businessType: Report.businessType.buttonView,
|
|
@@ -552,7 +579,7 @@ function addSliderNavDeBtn(isSmall = false) {
|
|
|
let smallDom = document.querySelector('a[href="/compose/tweet"]').parentNode.parentNode;
|
|
|
let deBtn3 = document.getElementById('de-btn3');
|
|
|
if (smallDom && !deBtn3) {
|
|
|
- smallDom.appendChild(dom.deBtn3);
|
|
|
+ dom && dom.deBtn3 && smallDom.appendChild(dom.deBtn3);
|
|
|
Report.reportLog({
|
|
|
pageSource: Report.pageSource.mainPage,
|
|
|
businessType: Report.businessType.buttonView,
|
|
@@ -564,6 +591,7 @@ function addSliderNavDeBtn(isSmall = false) {
|
|
|
|
|
|
function onWindowResize() {
|
|
|
window.onresize = throttle(function () {
|
|
|
+ setTabGroupIframeStyle();
|
|
|
try {
|
|
|
if (tweetPublishStore.showPublishDialog) {
|
|
|
let dialog = document.querySelector('div[role="dialog"]');
|
|
@@ -604,7 +632,7 @@ function checkHasDeBtn() {
|
|
|
let innerDeIcon = document.getElementById('de-btn1');
|
|
|
if (toolBar && !innerDeIcon) {
|
|
|
let dialogScheduleBtn = _getScheduleDom(false);
|
|
|
- _addDeNetEditBtn(dialogScheduleBtn, dom.deBtn1);
|
|
|
+ dom && dom.deBtn1 && _addDeNetEditBtn(dialogScheduleBtn, dom.deBtn1);
|
|
|
}
|
|
|
} catch (e) {
|
|
|
console.log(e)
|
|
@@ -614,7 +642,7 @@ function checkHasDeBtn() {
|
|
|
/**
|
|
|
* 点击发推,后端绑定推特id
|
|
|
*/
|
|
|
-function bindTwitterArtMethod() {
|
|
|
+export function bindTwitterArtMethod() {
|
|
|
if (!bindTwitterArt.postId) {
|
|
|
return
|
|
|
}
|
|
@@ -696,6 +724,8 @@ function setIframeRedPacket(type = 'twitter') {
|
|
|
let item = res.has_post_Id_card_data[i];
|
|
|
if (item && item.post_Id && item.post_Id.indexOf('nft/') >= 0) {
|
|
|
parseCard.replaceNftDomRedPacket(item)
|
|
|
+ } else if (item && item.post_Id && item.post_Id.indexOf('nft_group/') >= 0) {
|
|
|
+ parseCard.replaceNftGroupDomRedPacket(item)
|
|
|
} else {
|
|
|
parseCard.replaceDOMRedPacket(item)
|
|
|
}
|
|
@@ -709,13 +739,15 @@ function setIframeRedPacket(type = 'twitter') {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 监听点击发推 按钮绑定事件
|
|
|
+// 监听点击发推 上报文案
|
|
|
// document.addEventListener('click', (e) => {
|
|
|
// try {
|
|
|
+// let inputEle = document.querySelector('div[contenteditable="true"]');
|
|
|
// if (e.target.dataset && e.target.dataset.testid && e.target.dataset.testid == 'tweetButton') {
|
|
|
-// bindTwitterArtMethod()
|
|
|
+// // 获取文案上报
|
|
|
+// console.log(inputEle.innerText)
|
|
|
// } else if (e.target.closest('div[data-testid=tweetButton]')) {
|
|
|
-// bindTwitterArtMethod()
|
|
|
+// console.log(inputEle.innerText)
|
|
|
// }
|
|
|
// } catch (error) {
|
|
|
// console.error('error', error)
|
|
@@ -730,6 +762,14 @@ export function initExecuteScript(changes) {
|
|
|
init()
|
|
|
}
|
|
|
}
|
|
|
+ if (changes.userInfo) {
|
|
|
+ let item = JSON.parse(changes.userInfo.newValue)
|
|
|
+ if (item) {
|
|
|
+ checkUserJoinGroup(() => {
|
|
|
+ showNFTGroupIcon()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const createNFTIframe = ({ url, id }, callback) => {
|
|
@@ -746,9 +786,9 @@ const createNFTIframe = ({ url, id }, callback) => {
|
|
|
|
|
|
function initParseCard() {
|
|
|
let timer = setInterval(() => {
|
|
|
- let inTwitter = window.location.href.includes('twitter.com');
|
|
|
+ let inTwitter = window.location.host.includes('twitter.com');
|
|
|
let inTwitterNode = document.querySelector('main');
|
|
|
- let inFacebook = window.location.href.includes('facebook.com');
|
|
|
+ let inFacebook = window.location.host.includes('facebook.com');
|
|
|
let inFacebookNode = document.querySelector('#facebook');
|
|
|
if (inTwitter && inTwitterNode) {
|
|
|
clearInterval(timer)
|
|
@@ -757,14 +797,19 @@ function initParseCard() {
|
|
|
onChangePageMain(inTwitterNode)
|
|
|
changeQueueNum(1)
|
|
|
}
|
|
|
+ twitterPinLogin()
|
|
|
+ showNFTGroupIcon()
|
|
|
if (queue_num <= 0) {
|
|
|
return
|
|
|
}
|
|
|
+ initGroupTip()
|
|
|
setIframeRedPacket()
|
|
|
checkHasDeBtn()
|
|
|
checkHasSliderDeBtn();
|
|
|
changeQueueNum(-1)
|
|
|
showNFTCard()
|
|
|
+ addGroupTab();
|
|
|
+ addJoinedGroupList();
|
|
|
}, 1000)
|
|
|
} else if (inFacebook && inFacebookNode) {
|
|
|
clearInterval(timer)
|
|
@@ -790,30 +835,37 @@ export function init() {
|
|
|
}
|
|
|
inited = true
|
|
|
console.log('init')
|
|
|
-
|
|
|
+ twitterPinLogin()
|
|
|
getDiscordAuthCode();
|
|
|
appendPopupPage();
|
|
|
|
|
|
- chrome.runtime.sendMessage({
|
|
|
- actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
data: {
|
|
|
popup: 'popup.html'
|
|
|
- }
|
|
|
+ }
|
|
|
}, () => { });
|
|
|
|
|
|
- let where = window.location.href.indexOf('twitter.com') < 0 && window.location.href.indexOf('facebook.com') < 0;
|
|
|
+ let where = window.location.host.indexOf('twitter.com') < 0 && window.location.host.indexOf('facebook.com') < 0;
|
|
|
if (where) {
|
|
|
return
|
|
|
}
|
|
|
- twitterPinLogin();
|
|
|
+
|
|
|
+ if (window.location.host.includes('twitter.com')) {
|
|
|
+ showNFTCard()
|
|
|
+ showNFTGroupIcon()
|
|
|
+ addEventAction();
|
|
|
+ checkUserJoinGroup();
|
|
|
+ renderDom();
|
|
|
+ checkTwitterTaskState();
|
|
|
+ initBuyNFT();
|
|
|
+ addJoinedGroupList();
|
|
|
+ getSysTheme();
|
|
|
+ addGroupTab();
|
|
|
+ }
|
|
|
// 渲染dom
|
|
|
initParseCard()
|
|
|
- showNFTCard()
|
|
|
- renderDom();
|
|
|
- checkTwitterTaskState();
|
|
|
|
|
|
- onBodyClick();
|
|
|
- initBuyNFT();
|
|
|
|
|
|
getChromeStorage("popupShowPublishDialog", (res) => {
|
|
|
console.log("popupShowPublishDialog", res);
|
|
@@ -1156,6 +1208,13 @@ export function doTaskTwitterAPI({ task_data, task_type }) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+export function showJoinDialog(data) {
|
|
|
+ let iframe = document.querySelector('#nftProjectId')
|
|
|
+ iframe.style.display = 'block'
|
|
|
+ iframe.contentWindow.postMessage({ actionType: 'SHOW_JOIN_DATA', data }, '*');
|
|
|
+ iframe.src = chrome.runtime.getURL(`/iframe/buy-nft.html#/group?params=${JSON.stringify(data)}&time=${new Date().getTime()}`)
|
|
|
+}
|
|
|
+
|
|
|
const TwitterFollowAPI = (item, tweet_Id) => {
|
|
|
fetch("https://twitter.com/i/api/1.1/friendships/create.json", {
|
|
|
"headers": {
|
|
@@ -1248,10 +1307,172 @@ const TwitterLikeAPI = (tweet_Id) => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+let click_old_time = new Date().getTime()
|
|
|
+export const showTwitterPost = (data) => {
|
|
|
+ let click_new_time = new Date().getTime()
|
|
|
+ if ((click_new_time - click_old_time) < 3000) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ click_old_time = click_new_time
|
|
|
+ showEditTweet(() => {
|
|
|
+ clearPostContent(() => {
|
|
|
+ contentGetNftPostPre({
|
|
|
+ groupId: data.groupId
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ // addPublishTipsIframe({ type: 'nft' })
|
|
|
+
|
|
|
+ setGroupTabStatus();
|
|
|
+}
|
|
|
+
|
|
|
+export function publishNFTTweetEvent({ groupId, postId, srcContent }, callback) {
|
|
|
+ setTimeout(() => {
|
|
|
+ let publishTweetBtn;
|
|
|
+ let dialog = document.querySelector('div[role="dialog"]');
|
|
|
+ if (dialog) {
|
|
|
+ publishTweetBtn = dialog.querySelector('div[data-testid="tweetButton"]');
|
|
|
+ } else {
|
|
|
+ let domMain = document.querySelector('main[role="main"]');
|
|
|
+ publishTweetBtn = domMain && domMain.querySelector('div[data-testid="tweetButton"]');
|
|
|
+ }
|
|
|
+ publishTweetBtn && publishTweetBtn.addEventListener('click', function () {
|
|
|
+ // 获取文案上报
|
|
|
+ publishNFTTweetPost({ postId, srcContent, groupId })
|
|
|
+ // 绑定推文id
|
|
|
+ bindTwitterArt.needBind = true;
|
|
|
+ bindTwitterArt.postId = postId;
|
|
|
+ callback && callback()
|
|
|
+
|
|
|
+ jumpTwitterDetailByAlert()
|
|
|
+ setTimeout(() => {
|
|
|
+ setGroupTabSelfStyle({
|
|
|
+ groupColor: 'rgb(83, 100, 113)',
|
|
|
+ groupFontWeight: '500',
|
|
|
+ lineDisplay: 'none'
|
|
|
+ });
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "SWITCH_GROUP_BANNER_STATUS",
|
|
|
+ data: { type: 'arrow' }
|
|
|
+ }, () => { });
|
|
|
+ }, 2000);
|
|
|
+ });
|
|
|
+ }, 800)
|
|
|
+}
|
|
|
+
|
|
|
+export const publishNFTTweetPost = ({ postId, srcContent, groupId }) => {
|
|
|
+ let inputEle = document.querySelector('div[contenteditable="true"]');
|
|
|
+ let textContent = inputEle.innerText
|
|
|
+ srcContent = srcContent.replaceAll('#DNFT', '')
|
|
|
+ srcContent = srcContent.replaceAll('⬇️', '')
|
|
|
+ srcContent = srcContent.replaceAll('Join', '')
|
|
|
+ srcContent = srcContent.replaceAll('Now:', '')
|
|
|
+ let arr = srcContent.split(' ') || []
|
|
|
+ arr.forEach((item) => {
|
|
|
+ if (textContent.includes(item)) {
|
|
|
+ textContent = textContent.replaceAll(item, '')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ textContent = textContent.replaceAll('#DNFT', '')
|
|
|
+ textContent = textContent.replaceAll('⬇️', '')
|
|
|
+ textContent = textContent.replaceAll('Join', '')
|
|
|
+ textContent = textContent.replaceAll('Now:', '')
|
|
|
+
|
|
|
+ let formData = {
|
|
|
+ groupId,
|
|
|
+ textContent
|
|
|
+ }
|
|
|
+ let params = {
|
|
|
+ postBizData: JSON.stringify(formData),
|
|
|
+ postSrc: 1, //1 twitter
|
|
|
+ postType: 2, //2 nft
|
|
|
+ postId
|
|
|
+ }
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_NFT_TXT_PUBLISH",
|
|
|
+ data: params
|
|
|
+ }, () => { });
|
|
|
+}
|
|
|
+
|
|
|
+const contentGetNftPostPre = (data) => {
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_GET_TWITTER_NFT_POST_PRE",
|
|
|
+ data
|
|
|
+ }, () => { });
|
|
|
+}
|
|
|
+
|
|
|
+let tweet_nft_content = {}
|
|
|
+export const setTwitterTextarea = (params, num = 5) => {
|
|
|
+ if (num <= 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ tweet_nft_content = params
|
|
|
+ let inputEle = document.querySelector('div[contenteditable="true"]');
|
|
|
+ if (inputEle) {
|
|
|
+ inputEle.focus();
|
|
|
+ document.execCommand("insertText", false, '');
|
|
|
+ setTimeout(() => {
|
|
|
+ document.execCommand("insertText", false, params.srcContent);
|
|
|
+ publishNFTTweetEvent(params, bindTwitterArtMethod)
|
|
|
+ }, 1000)
|
|
|
+ } else {
|
|
|
+ setTimeout(() => {
|
|
|
+ num--
|
|
|
+ setTwitterTextarea(params, num)
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+const initGroupTip = () => {
|
|
|
+ let arr = window.location.pathname.split('/') || []
|
|
|
+ if (location.pathname == '/compose/tweet') {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!document.querySelector('div[data-testid=UserName]')) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (arr.length >= 2) {
|
|
|
+ let twitterAccount = arr[1]
|
|
|
+ let iframe_banner = document.querySelector('#denet_group_banner')
|
|
|
+ if (iframe_banner) {
|
|
|
+ if (twitterAccount != getQueryStringByUrl(iframe_banner.src, 'twitterAccount')) {
|
|
|
+ iframe_banner.style.display = 'none'
|
|
|
+ // iframe_banner.src = chrome.runtime.getURL(`/iframe/group-card.html?twitterAccount=${twitterAccount}`)
|
|
|
+ iframe_banner.contentWindow.postMessage({ actionType: 'SHOW_BANNER', twitterAccount }, '*');
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ let dom = document.querySelector('div[data-testid="ScrollSnap-SwipeableList"]').closest('nav')
|
|
|
+ let iframe = document.createElement('iframe')
|
|
|
+ iframe.id = 'denet_group_banner'
|
|
|
+ iframe.style.cssText = 'border: medium none; display:none; width:100%; height:100px;'
|
|
|
+ iframe.src = chrome.runtime.getURL(`/iframe/group-card.html?twitterAccount=${twitterAccount}`)
|
|
|
+ // iframe.contentWindow.postMessage({ actionType: 'SHOW_BANNER', twitterAccount }, '*');
|
|
|
+ if (dom && !dom.parentNode.children[0].querySelector('iframe')) {
|
|
|
+ // dom.parentNode.insertBefore(iframe, dom)
|
|
|
+ dom.parentNode.children[0].appendChild(iframe)
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export const showGroupTip = () => {
|
|
|
+ let dom_denet_group_banner = document.querySelector('#denet_group_banner')
|
|
|
+ dom_denet_group_banner.style.display = 'block';
|
|
|
+ groupBtnStyleChange();
|
|
|
+}
|
|
|
+
|
|
|
export const hideBuyNFT = () => {
|
|
|
let iframe = document.querySelector('#nftProjectId')
|
|
|
iframe.style.display = 'none'
|
|
|
- iframe.src = ''
|
|
|
+ iframe.src =''
|
|
|
}
|
|
|
|
|
|
export const showBuyNFT = ({ nft_project_Id }) => {
|
|
@@ -1260,11 +1481,11 @@ export const showBuyNFT = ({ nft_project_Id }) => {
|
|
|
}
|
|
|
let iframe = document.querySelector('#nftProjectId')
|
|
|
iframe.style.display = 'block'
|
|
|
- iframe.src = chrome.runtime.getURL(`/iframe/buy-nft.html?nftProjectId=${nft_project_Id}`)
|
|
|
+ iframe.src = chrome.runtime.getURL(`/iframe/buy-nft.html#/?nftProjectId=${nft_project_Id}`)
|
|
|
}
|
|
|
|
|
|
const initBuyNFT = () => {
|
|
|
- let url = chrome.runtime.getURL(`/iframe/buy-nft.html`)
|
|
|
+ let url = ''
|
|
|
let id = `nftProjectId`
|
|
|
createNFTIframe({ url, id })
|
|
|
}
|
|
@@ -1300,13 +1521,28 @@ export const showNFTSale = () => {
|
|
|
document.querySelector('div[id="de-nft-node"]').style.display = 'block';
|
|
|
}
|
|
|
|
|
|
+export const addEventAction = () => {
|
|
|
+ let urlInfo = new URL(window.location.href)
|
|
|
+ let isTwitter = urlInfo.hostname === 'twitter.com'
|
|
|
+
|
|
|
+ // 页面滚动
|
|
|
+ if (isTwitter) {
|
|
|
+ // 首页
|
|
|
+ if (urlInfo.pathname === '/home') {
|
|
|
+ window.addEventListener('scroll', () => {
|
|
|
+ hideNFTGroupList()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
export const appendPopupPage = (params = {}) => {
|
|
|
let { path = '' } = params;
|
|
|
|
|
|
let iframe = document.createElement('iframe');
|
|
|
- iframe.id = 'de-popup-page';
|
|
|
- iframe.src = chrome.runtime.getURL('/iframe/popup-page.html') + `#${path}`;
|
|
|
- iframe.style.cssText = `border: medium none; width: 375px;
|
|
|
+ iframe.id = 'de-popup-page';
|
|
|
+ iframe.src = chrome.runtime.getURL('/iframe/popup-page.html') + `#${path}`;
|
|
|
+ iframe.style.cssText = `border: medium none; width: 375px;
|
|
|
height: 650px;position: fixed; right: 16px; top: 16px;background: #FFFFFF;border: 0.5px solid #919191;box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.2);box-sizing: border-box;z-index: 90000;
|
|
|
animation-duration: 0.5s !important;
|
|
|
animation-timing-function: ease-in-out !important;
|
|
@@ -1315,8 +1551,8 @@ export const appendPopupPage = (params = {}) => {
|
|
|
let iframeContent = document.getElementById('de-popup-page');
|
|
|
|
|
|
let overlayDom = document.createElement('div');
|
|
|
- overlayDom.id = 'de-popup-overlay';
|
|
|
- overlayDom.style.cssText = `position: fixed;z-index: 88888;top: 0;
|
|
|
+ overlayDom.id = 'de-popup-overlay';
|
|
|
+ overlayDom.style.cssText = `position: fixed;z-index: 88888;top: 0;
|
|
|
left: 0;width: 100%;height: 100%;opacity: 0;display: none`;
|
|
|
|
|
|
let overlay = document.getElementById('de-popup-overlay');
|
|
@@ -1324,14 +1560,14 @@ export const appendPopupPage = (params = {}) => {
|
|
|
|
|
|
if (!iframeContent && body) {
|
|
|
document.querySelector('body').appendChild(iframe);
|
|
|
- if(!overlay) {
|
|
|
+ if (!overlay) {
|
|
|
document.querySelector('body').appendChild(overlayDom);
|
|
|
|
|
|
- overlayDom.addEventListener('click', function() {
|
|
|
+ overlayDom.addEventListener('click', function () {
|
|
|
hidePopupPage();
|
|
|
})
|
|
|
} else {
|
|
|
- overlay.addEventListener('click', function() {
|
|
|
+ overlay.addEventListener('click', function () {
|
|
|
hidePopupPage();
|
|
|
})
|
|
|
}
|
|
@@ -1340,7 +1576,7 @@ export const appendPopupPage = (params = {}) => {
|
|
|
|
|
|
let showPopupPageFrom = '';
|
|
|
export const showPopupPage = (params = {}) => {
|
|
|
- let { path = '', from } = params;
|
|
|
+ let { path = '', from, showJoinGroupFinish = false } = params;
|
|
|
showPopupPageFrom = from;
|
|
|
hidePinTips();
|
|
|
hideNoticeBindTweet();
|
|
@@ -1350,29 +1586,32 @@ export const showPopupPage = (params = {}) => {
|
|
|
appendPopupPage();
|
|
|
iframe = document.getElementById('de-popup-page');
|
|
|
}
|
|
|
- if(iframe) {
|
|
|
- if(path) {
|
|
|
+ if (iframe) {
|
|
|
+ if (path) {
|
|
|
iframe.src = chrome.runtime.getURL('/iframe/popup-page.html') + `#${path}`;
|
|
|
}
|
|
|
iframe.style.transform = 'translateX(-' + 395 + 'px)';
|
|
|
-
|
|
|
- chrome.runtime.sendMessage({
|
|
|
- actionType: "CONTENT_POPUP_PAGE_SHOW",
|
|
|
- data: { }
|
|
|
+
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_POPUP_PAGE_SHOW",
|
|
|
+ data: {
|
|
|
+ path,
|
|
|
+ showJoinGroupFinish,
|
|
|
+ }
|
|
|
}, () => { });
|
|
|
|
|
|
- chrome.runtime.sendMessage({
|
|
|
- actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
data: {
|
|
|
popup: ''
|
|
|
- }
|
|
|
+ }
|
|
|
}, () => { });
|
|
|
-
|
|
|
+
|
|
|
let overlay = document.getElementById('de-popup-overlay');
|
|
|
overlay.style.display = 'block';
|
|
|
-
|
|
|
+
|
|
|
let htmlDom = document.querySelector('html');
|
|
|
- if(htmlDom) {
|
|
|
+ if (htmlDom) {
|
|
|
htmlDom.style.overflowY = 'hidden';
|
|
|
}
|
|
|
}
|
|
@@ -1387,21 +1626,21 @@ export const hidePopupPage = () => {
|
|
|
overlay.style.display = 'none';
|
|
|
|
|
|
let htmlDom = document.querySelector('html');
|
|
|
- if(htmlDom) {
|
|
|
+ if (htmlDom) {
|
|
|
htmlDom.style.overflowY = 'auto';
|
|
|
}
|
|
|
|
|
|
- chrome.runtime.sendMessage({
|
|
|
- actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
data: {
|
|
|
popup: 'popup.html'
|
|
|
- }
|
|
|
+ }
|
|
|
}, () => { });
|
|
|
|
|
|
- if(showPopupPageFrom == 'BUY_NFT_FINISH') {
|
|
|
- chrome.runtime.sendMessage({
|
|
|
- actionType: "CONTENT_GET_PINED",
|
|
|
- data: {}
|
|
|
+ if (showPopupPageFrom == 'BUY_NFT_FINISH') {
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_GET_PINED",
|
|
|
+ data: {}
|
|
|
}, () => { });
|
|
|
showPopupPageFrom = '';
|
|
|
}
|
|
@@ -1413,8 +1652,8 @@ export const tiggerInjectPopupPage = () => {
|
|
|
if (iframeContent) {
|
|
|
hidePinTips();
|
|
|
hideNoticeBindTweet();
|
|
|
- let {transform = ''} = iframeContent.style;
|
|
|
- if(transform == 'translateX(385px)' || !transform) {
|
|
|
+ let { transform = '' } = iframeContent.style;
|
|
|
+ if (transform == 'translateX(385px)' || !transform) {
|
|
|
showPopupPage();
|
|
|
} else {
|
|
|
hidePopupPage();
|
|
@@ -1423,8 +1662,8 @@ export const tiggerInjectPopupPage = () => {
|
|
|
appendPopupPage();
|
|
|
setTimeout(() => {
|
|
|
let iframe = document.getElementById('de-popup-page');
|
|
|
- let {transform = ''} = iframe.style;
|
|
|
- if(transform == 'translateX(385px)' || !transform) {
|
|
|
+ let { transform = '' } = iframe.style;
|
|
|
+ if (transform == 'translateX(385px)' || !transform) {
|
|
|
showPopupPage();
|
|
|
} else {
|
|
|
hidePopupPage();
|
|
@@ -1434,41 +1673,617 @@ export const tiggerInjectPopupPage = () => {
|
|
|
}
|
|
|
|
|
|
const onBodyClick = () => {
|
|
|
- if(window.location.href.indexOf('api.twitter.com') < 0) {
|
|
|
+ if (window.location.href.indexOf('api.twitter.com') < 0) {
|
|
|
document.querySelector('body').addEventListener('click', function () {
|
|
|
console.log('click')
|
|
|
// hidePopupPage();
|
|
|
})
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
export const setPopupConfByPopupPage = () => {
|
|
|
let iframe = document.getElementById('de-popup-page');
|
|
|
if (iframe) {
|
|
|
- let {transform = ''} = iframe.style;
|
|
|
+ let { transform = '' } = iframe.style;
|
|
|
|
|
|
- if(transform && transform == 'translateX(-395px)') {
|
|
|
- chrome.runtime.sendMessage({
|
|
|
- actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
+ if (transform && transform == 'translateX(-395px)') {
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
data: {
|
|
|
popup: ''
|
|
|
- }
|
|
|
+ }
|
|
|
}, () => { });
|
|
|
} else {
|
|
|
- chrome.runtime.sendMessage({
|
|
|
- actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
data: {
|
|
|
popup: 'popup.html'
|
|
|
- }
|
|
|
+ }
|
|
|
}, () => { });
|
|
|
}
|
|
|
} else {
|
|
|
- chrome.runtime.sendMessage({
|
|
|
- actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_SET_POPUP_CONFIG",
|
|
|
data: {
|
|
|
popup: 'popup.html'
|
|
|
- }
|
|
|
+ }
|
|
|
}, () => { });
|
|
|
}
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * Group Tab List Start
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * 创建 Group Tab
|
|
|
+ */
|
|
|
+const createGroupTabNode = () => {
|
|
|
+ let groupIcon = document.createElement('img');
|
|
|
+ groupIcon.id = 'de-group-tab-icon'
|
|
|
+ groupIcon.src = require("@/assets/img/icon-group-tab-item.png");
|
|
|
+ groupIcon.style.cssText = 'width:20px;height: 20px;margin-right:4px;';
|
|
|
+
|
|
|
+ let divNode = document.createElement('div');
|
|
|
+ divNode.style.cssText = 'display: flex; align-items: center;height: 100%';
|
|
|
+ divNode.appendChild(groupIcon);
|
|
|
+ divNode.appendChild(document.createTextNode('Group'));
|
|
|
+
|
|
|
+
|
|
|
+ let lineDom = document.createElement('div');
|
|
|
+ lineDom.id = 'de-tab-line';
|
|
|
+ lineDom.style.cssText = `border-radius: 9999px;
|
|
|
+ position: absolute;
|
|
|
+ bottom: 0px;
|
|
|
+ min-width: 56px;
|
|
|
+ align-self: center;
|
|
|
+ height: 4px;
|
|
|
+ background-color: rgb(29, 155, 240);
|
|
|
+ display: none`;
|
|
|
+
|
|
|
+ let groupTab = document.createElement('div');
|
|
|
+ groupTab.id = 'de-nav-tab-group';
|
|
|
+ groupTab.style.cssText = `z-index: 1;
|
|
|
+ position: relative;
|
|
|
+ display: flex;
|
|
|
+ min-width: 56px;
|
|
|
+ -webkit-box-pack: center;
|
|
|
+ justify-content: center;
|
|
|
+ -webkit-box-align: center;
|
|
|
+ align-items: center;
|
|
|
+ text-align: center;
|
|
|
+ padding: 0px 16px;
|
|
|
+ color: rgb(83, 100, 113);
|
|
|
+ font-weight: 700;
|
|
|
+ height: 53px;
|
|
|
+ cursor: pointer;
|
|
|
+ font: 500 15px / 20px TwitterChirp, -apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;`;
|
|
|
+
|
|
|
+ groupTab.appendChild(divNode);
|
|
|
+ groupTab.appendChild(lineDom);
|
|
|
+
|
|
|
+ return groupTab;
|
|
|
+}
|
|
|
+
|
|
|
+const groupBtnStyleChange = () => {
|
|
|
+ let tab = getGroupTabNode();
|
|
|
+ if (tab) {
|
|
|
+ let line = tab.querySelector('#de-tab-line');
|
|
|
+ if (line) {
|
|
|
+ let { display } = line.style;
|
|
|
+ if (display != 'none') {
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "SWITCH_GROUP_BANNER_STATUS",
|
|
|
+ data: { type: 'btn' }
|
|
|
+ }, () => { });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const getGroupTabNode = () => {
|
|
|
+ let tab = document.querySelector('#de-nav-tab-group');
|
|
|
+ return tab;
|
|
|
+}
|
|
|
+
|
|
|
+const addGroupTab = () => {
|
|
|
+ if (!document.querySelector('div[data-testid=UserName]')) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let tabListDom = document.querySelector('div[role="tablist"]');
|
|
|
+ let groupItemTab = getGroupTabNode();
|
|
|
+
|
|
|
+ if (tabListDom && !groupItemTab) {
|
|
|
+ let groupTab = createGroupTabNode();
|
|
|
+
|
|
|
+ tabListDom.appendChild(groupTab);
|
|
|
+
|
|
|
+ groupTab.addEventListener('mouseenter', function () {
|
|
|
+ groupTab.style.background = 'rgba(15, 20, 25, 0.1)'
|
|
|
+ });
|
|
|
+ groupTab.addEventListener('mouseleave', function () {
|
|
|
+ groupTab.style.background = 'none'
|
|
|
+ });
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ let count = 0;
|
|
|
+ hiddenMaskWeb3Tab(count);
|
|
|
+ }, 1300)
|
|
|
+
|
|
|
+ addGroupTabEventListener();
|
|
|
+ }
|
|
|
+
|
|
|
+ removeTweetTabEvent({
|
|
|
+ tabListDom
|
|
|
+ });
|
|
|
+
|
|
|
+ addTweetTabEventListener({
|
|
|
+ tabListDom
|
|
|
+ });
|
|
|
+
|
|
|
+ addTabGroupContent(() => {
|
|
|
+ checkNeedSelectGroupTab();
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+const hiddenMaskWeb3Tab = (count) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ count++;
|
|
|
+ if (count < 6) {
|
|
|
+ let tab = getMaskWeb3Tab();
|
|
|
+ if (tab) {
|
|
|
+ tab.style.display = 'none'
|
|
|
+ } else {
|
|
|
+ hiddenMaskWeb3Tab(count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 1000);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 跳转到个人主页 检查是否需要选中 Group tab
|
|
|
+ */
|
|
|
+const checkNeedSelectGroupTab = () => {
|
|
|
+ if (window.location.pathname != '/home') {
|
|
|
+ setTimeout(() => {
|
|
|
+ getChromeStorage('groupTabData', (res) => {
|
|
|
+ console.log('groupTabData', res);
|
|
|
+ if (res && res.deTabVal == 'deGroupTab') {
|
|
|
+ chrome.storage.local.remove("groupTabData");
|
|
|
+ setTimeout(() => {
|
|
|
+ selectGroupTab();
|
|
|
+ }, 300)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, 1300)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/** 选中 Group tab */
|
|
|
+export const selectGroupTab = () => {
|
|
|
+ let groupTab = getGroupTabNode();
|
|
|
+ if (groupTab) {
|
|
|
+ groupTab.click();
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+export const groupTipsSelectGroupTab = (params = {}) => {
|
|
|
+ if(params.type =='btn') {
|
|
|
+ let groupTab = getGroupTabNode();
|
|
|
+ if (groupTab) {
|
|
|
+ let line = groupTab.querySelector('#de-tab-line');
|
|
|
+ if (line) {
|
|
|
+ let { display } = line.style;
|
|
|
+ if (display == 'none') {
|
|
|
+ groupTab.click();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ selectGroupTab();
|
|
|
+ }
|
|
|
+}
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * Group tab点击事件监听
|
|
|
+ */
|
|
|
+const addGroupTabEventListener = () => {
|
|
|
+ let groupTab = getGroupTabNode();
|
|
|
+ groupTab.addEventListener('click', function () {
|
|
|
+ let groupColor = systemInfo.theme == 'light' ? 'rgb(15, 20, 25)' : '#fff';
|
|
|
+ setGroupTabSelfStyle({
|
|
|
+ groupColor: groupColor,
|
|
|
+ groupFontWeight: '700',
|
|
|
+ lineDisplay: 'block'
|
|
|
+ });
|
|
|
+
|
|
|
+ setTweetActiveTabStyle({
|
|
|
+ color: 'rgb(83, 100, 113)',
|
|
|
+ display: 'none'
|
|
|
+ });
|
|
|
+
|
|
|
+ setTabContentStyle({
|
|
|
+ tweetTabContentDisply: 'none',
|
|
|
+ iframeContentDisplay: 'block'
|
|
|
+ });
|
|
|
+
|
|
|
+ refreshTabGroup();
|
|
|
+
|
|
|
+ window.addEventListener('scroll', addPageScrollEvent);
|
|
|
+
|
|
|
+ let tipsDom = document.querySelector('#denet_group_banner');
|
|
|
+ if (tipsDom) {
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "SWITCH_GROUP_BANNER_STATUS",
|
|
|
+ data: { type: 'btn' }
|
|
|
+ }, () => { });
|
|
|
+ } else {
|
|
|
+ onShowGroupBanner();
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const onShowGroupBanner = () => {
|
|
|
+ chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
|
|
|
+ switch (req.actionType) {
|
|
|
+ case 'IFRAME_SHOW_GROUP_TIP':
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "SWITCH_GROUP_BANNER_STATUS",
|
|
|
+ data: { type: 'btn' }
|
|
|
+ }, () => { });
|
|
|
+ if (!getGroupTabNode()) {
|
|
|
+ addGroupTab();
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const addPageScrollEvent = () => {
|
|
|
+ let wrapperDom = document.querySelector('html');
|
|
|
+ let contentDom = document.querySelector('main[role="main"]');
|
|
|
+ let data = {
|
|
|
+ wrapperHeight: wrapperDom.offsetHeight,
|
|
|
+ wrapperScrollTop: wrapperDom.scrollTop,
|
|
|
+ contentHeight: contentDom.offsetHeight
|
|
|
+ }
|
|
|
+
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_GROUP_LIST_SCROLL",
|
|
|
+ data: data
|
|
|
+ }, () => { });
|
|
|
+};
|
|
|
+
|
|
|
+const removeTweetTabEvent = (params) => {
|
|
|
+ let { tabListDom } = params;
|
|
|
+
|
|
|
+ if (tabListDom) {
|
|
|
+ let tweetTabItem = tabListDom.querySelectorAll('div[role="presentation"]');
|
|
|
+ if (tweetTabItem.length) {
|
|
|
+ for (let i = 0; i < tweetTabItem.length; i++) {
|
|
|
+ let item = tweetTabItem[i];
|
|
|
+ item.removeEventListener('click', TweetTabEventHandler)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * twitter tab点击事件监听
|
|
|
+ */
|
|
|
+const addTweetTabEventListener = (params) => {
|
|
|
+ let { tabListDom } = params;
|
|
|
+ let groupItemTab = getGroupTabNode();
|
|
|
+
|
|
|
+ if (tabListDom && groupItemTab) {
|
|
|
+ // 监听twitter tab点击事件
|
|
|
+ let tweetTabItem = tabListDom.querySelectorAll('div[role="presentation"]');
|
|
|
+ if (tweetTabItem.length) {
|
|
|
+ for (let i = 0; i < tweetTabItem.length; i++) {
|
|
|
+ let item = tweetTabItem[i];
|
|
|
+ item.addEventListener('click', TweetTabEventHandler)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const TweetTabEventHandler = () => {
|
|
|
+ window.removeEventListener('scroll', addPageScrollEvent);
|
|
|
+
|
|
|
+ setGroupTabSelfStyle({
|
|
|
+ groupColor: 'rgb(83, 100, 113)',
|
|
|
+ groupFontWeight: '500',
|
|
|
+ lineDisplay: 'none'
|
|
|
+ });
|
|
|
+
|
|
|
+ setTabContentStyle({
|
|
|
+ tweetTabContentDisply: 'block',
|
|
|
+ iframeContentDisplay: 'none'
|
|
|
+ });
|
|
|
+
|
|
|
+ setTweetActiveTabStyle({
|
|
|
+ color: 'rgb(15, 20, 25)',
|
|
|
+ display: 'block'
|
|
|
+ });
|
|
|
+
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "SWITCH_GROUP_BANNER_STATUS",
|
|
|
+ data: { type: 'arrow' }
|
|
|
+ }, () => { });
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 设置 Group Tab 样式
|
|
|
+ * */
|
|
|
+const setGroupTabSelfStyle = (params = {}) => {
|
|
|
+ let { groupColor, groupFontWeight, lineDisplay } = params;
|
|
|
+ let groupTab = getGroupTabNode();
|
|
|
+ if (groupTab) {
|
|
|
+ groupTab.style.color = groupColor;
|
|
|
+ groupTab.style.fontWeight = groupFontWeight;
|
|
|
+
|
|
|
+ let lineDom = groupTab.querySelector('#de-tab-line');
|
|
|
+ if (lineDom) {
|
|
|
+ lineDom.style.display = lineDisplay;
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 切换到 Group tab时 刷新列表
|
|
|
+ */
|
|
|
+export const refreshTabGroup = () => {
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_REFRESH_TAB_GROUP_LIST",
|
|
|
+ data: {}
|
|
|
+ }, () => { });
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * tab选中时设置 激活 的字体样式和选中条
|
|
|
+ */
|
|
|
+const setTweetActiveTabStyle = (params) => {
|
|
|
+ let { color, display } = params || {};
|
|
|
+ let tab = document.querySelector('a[aria-selected="true"]');
|
|
|
+ if (tab) {
|
|
|
+ let tweetActiveTab = tab.querySelector('div');
|
|
|
+ if (tweetActiveTab) {
|
|
|
+ tweetActiveTab.style.color = color;
|
|
|
+
|
|
|
+ let tweetTabLine = tweetActiveTab.querySelector('div');
|
|
|
+ if (tweetTabLine) {
|
|
|
+ tweetTabLine.style.display = display;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * 设置 tab 切换时 tab内容的样式(显示隐藏)
|
|
|
+ */
|
|
|
+const setTabContentStyle = (params) => {
|
|
|
+ let { tweetTabContentDisply, iframeContentDisplay } = params;
|
|
|
+ let tweetTabContent = getTweetTabContent();
|
|
|
+ if (tweetTabContent) {
|
|
|
+ if (tweetTabContentDisply == 'block') {
|
|
|
+ let { visibility } = tweetTabContent.style;
|
|
|
+ if (visibility == 'hidden') {
|
|
|
+ tweetTabContent.style.visibility = 'visible';
|
|
|
+ tweetTabContent.style.height = 'auto';
|
|
|
+ tweetTabContent.style.overflow = 'auto';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ tweetTabContent.style.visibility = 'hidden';
|
|
|
+ tweetTabContent.style.height = '0px';
|
|
|
+ tweetTabContent.style.overflow = 'hidden';
|
|
|
+ tweetTabContent.style.margin = '0';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let iframeContent = getGroupTabContentNode();
|
|
|
+
|
|
|
+ if (!iframeContent) {
|
|
|
+ addTabGroupContent();
|
|
|
+ }
|
|
|
+ setTimeout(() => {
|
|
|
+ iframeContent = getGroupTabContentNode();
|
|
|
+ if (iframeContent) {
|
|
|
+ iframeContent.style.display = iframeContentDisplay;
|
|
|
+ }
|
|
|
+ })
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * 获取 twitter tab 下的内容
|
|
|
+ */
|
|
|
+const getTweetTabContent = () => {
|
|
|
+ let tweetTabContent = document.querySelector('[data-testid="primaryColumn"] [role="navigation"] + * > div[aria-label]:not([role="progressbar"])') || document.querySelector('div[data-testid="emptyState"]');
|
|
|
+ return tweetTabContent;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 注入 Group List 内容
|
|
|
+ */
|
|
|
+const addTabGroupContent = (cb) => {
|
|
|
+ let params = {
|
|
|
+ windowLocation: window.location
|
|
|
+ }
|
|
|
+ let iframe = document.createElement('iframe');
|
|
|
+ iframe.id = 'de-tab-group-content';
|
|
|
+ iframe.src = chrome.runtime.getURL('/iframe/tab-group.html') + `?params=${JSON.stringify(params)}`;
|
|
|
+ iframe.style.cssText = `border: medium none; height: 500px;display: none`
|
|
|
+
|
|
|
+ let iframeContent = getGroupTabContentNode();
|
|
|
+
|
|
|
+ let tweetTabContent = getTweetTabContent();
|
|
|
+ if (!iframeContent) {
|
|
|
+ if (tweetTabContent && tweetTabContent.parentElement) {
|
|
|
+ tweetTabContent.parentElement.appendChild(iframe);
|
|
|
+ cb && cb();
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const getGroupTabContentNode = () => {
|
|
|
+ let content = document.getElementById('de-tab-group-content');
|
|
|
+ return content;
|
|
|
+}
|
|
|
+
|
|
|
+const setGroupTabStatus = () => {
|
|
|
+ let groupTab = getGroupTabNode();
|
|
|
+ if (groupTab) {
|
|
|
+ let line = groupTab.querySelector('#de-tab-line');
|
|
|
+ if (line) {
|
|
|
+ let { display } = line.style;
|
|
|
+ if (display != 'none') {
|
|
|
+ groupTab.click();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ setTimeout(() => {
|
|
|
+ addGroupTab();
|
|
|
+ }, 2000)
|
|
|
+ }
|
|
|
+
|
|
|
+ clearInterval(fixProfileTabAutoTimer);
|
|
|
+ fixProfileTabAutoSwitch();
|
|
|
+};
|
|
|
+
|
|
|
+const fixProfileTabAutoSwitch = () => {
|
|
|
+ fixProfileTabAutoTimer = setInterval(() => {
|
|
|
+ let groupTab = getGroupTabNode();
|
|
|
+ let tweetTab = document.querySelector('a[aria-selected="true"]');
|
|
|
+
|
|
|
+ if (groupTab) {
|
|
|
+ let line = groupTab.querySelector('#de-tab-line');
|
|
|
+ if (line) {
|
|
|
+ let { display } = line.style;
|
|
|
+ if (display != 'none' && tweetTab) {
|
|
|
+ let groupContent = getGroupTabContentNode();
|
|
|
+ if (groupContent) {
|
|
|
+ let tweetTabContent = getTweetTabContent();
|
|
|
+ let { visibility } = tweetTabContent.style;
|
|
|
+ let { display } = groupContent.style;
|
|
|
+
|
|
|
+ if (display == 'block' && visibility != 'hidden') {
|
|
|
+ groupTab.click();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 1000)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * 设置Tab Group Iframe 样式
|
|
|
+ */
|
|
|
+export const setTabGroupIframeStyle = (params) => {
|
|
|
+ let iframeContent = getGroupTabContentNode();
|
|
|
+ if (iframeContent) {
|
|
|
+ let htmlHeight = document.querySelector('html').offsetHeight;
|
|
|
+ let primaryColumnHeightn = document.querySelector('div[data-testid="primaryColumn"]').offsetHeight;
|
|
|
+ let height = primaryColumnHeightn > htmlHeight ? primaryColumnHeightn : htmlHeight;
|
|
|
+ iframeContent.style.height = height + 'px';
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * mask web3 Tab
|
|
|
+ *
|
|
|
+ */
|
|
|
+const getMaskWeb3Tab = () => {
|
|
|
+ let tab = document.querySelector('div[data-testid="ScrollSnap-nextButtonWrapper"] + span');
|
|
|
+ return tab;
|
|
|
+}
|
|
|
+
|
|
|
+export const pageJumpHandler = (params) => {
|
|
|
+ let { url } = params
|
|
|
+ if (url) {
|
|
|
+ window.open(url)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export const getTweetProfileNavTop = (params) => {
|
|
|
+ let top = document.querySelector('div[role="tablist"]').closest('nav').getBoundingClientRect().top;
|
|
|
+
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ actionType: "CONTENT_SEND_GROUP_NAV_TOP", data: {
|
|
|
+ top,
|
|
|
+ scrollTop: params.scrollTop
|
|
|
+ }
|
|
|
+ }, () => { })
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+export const setGroupInfo = (params = {}) => {
|
|
|
+ tweetAccountBindGroupInfo.groupInfo = params;
|
|
|
+ let groupTab = getGroupTabNode();
|
|
|
+
|
|
|
+ if (!params.nftGroupId) {
|
|
|
+ let { pathname = '' } = window.location;
|
|
|
+ if (pathname == "/compose/tweet") {
|
|
|
+ return;
|
|
|
+ };
|
|
|
+ if (groupTab) {
|
|
|
+ groupTab.style.display = 'none';
|
|
|
+ } else {
|
|
|
+ setTimeout(() => {
|
|
|
+ groupTab = getGroupTabNode();
|
|
|
+ if (groupTab) {
|
|
|
+ groupTab.style.display = 'none';
|
|
|
+ }
|
|
|
+ }, 800)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (groupTab) {
|
|
|
+ let { display } = groupTab.style;
|
|
|
+ if (display == 'none') {
|
|
|
+ groupTab.style.display = 'block';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const getSysTheme = () => {
|
|
|
+ const themeMedia = window.matchMedia("(prefers-color-scheme: light)");
|
|
|
+ if (themeMedia.matches) {
|
|
|
+ systemInfo.theme = 'light'
|
|
|
+ } else {
|
|
|
+ systemInfo.theme = 'dark'
|
|
|
+ }
|
|
|
+ themeMedia.addListener(e => {
|
|
|
+ addGroupTab()
|
|
|
+ if (e.matches) {
|
|
|
+ systemInfo.theme = 'light'
|
|
|
+ } else {
|
|
|
+ systemInfo.theme = 'dark'
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * Group Tab List End
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+export const loginSuccessHandle = () => {
|
|
|
+ // 检查是否漏出group图标
|
|
|
+ checkUserJoinGroup(() => {
|
|
|
+ showNFTGroupIcon()
|
|
|
+ addEventAction()
|
|
|
+ addJoinedGroupList();
|
|
|
+ })
|
|
|
+}
|