浏览代码

[edit][偶现banner渲染不出来]

zhangwei 2 年之前
父节点
当前提交
7345553d78
共有 2 个文件被更改,包括 30 次插入16 次删除
  1. 16 12
      src/logic/content/twitter.js
  2. 14 4
      src/view/iframe/group-card/card.vue

+ 16 - 12
src/logic/content/twitter.js

@@ -24,7 +24,12 @@ let systemInfo = {
 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')
 
@@ -784,6 +789,7 @@ function initParseCard() {
                     onChangePageMain(inTwitterNode)
                     changeQueueNum(1)
                 }
+                twitterPinLogin()
                 showNFTGroupIcon()
                 if (queue_num <= 0) {
                     return
@@ -821,7 +827,7 @@ export function init() {
     }
     inited = true
     console.log('init')
-
+    twitterPinLogin()
     getDiscordAuthCode();
     appendPopupPage();
 
@@ -836,7 +842,7 @@ export function init() {
     if (where) {
         return
     }
-    twitterPinLogin();
+    
     if (window.location.host.includes('twitter.com')) {
         showNFTCard()
         showNFTGroupIcon()
@@ -1425,9 +1431,9 @@ const initGroupTip = () => {
         let iframe_banner = document.querySelector('#denet_group_banner')
         if (iframe_banner) {
             if (twitterAccount != getQueryStringByUrl(iframe_banner.src, 'twitterAccount')) {
-                iframe_banner.style.visibility = 'hidden'
-                iframe_banner.style.height = '0px'
-                iframe_banner.src = chrome.runtime.getURL(`/iframe/group-card.html?twitterAccount=${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
         }
@@ -1435,14 +1441,13 @@ const initGroupTip = () => {
             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; visibility:hidden; width:100%; height:0px;'
-
+            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.querySelector('iframe')) {
-                dom.parentNode.insertBefore(iframe, dom)
-                // .children[0].appendChild(iframe)
+                // dom.parentNode.insertBefore(iframe, dom)
+                dom.parentNode.children[0].appendChild(iframe)
             }
 
         } catch (error) {
@@ -1453,8 +1458,7 @@ const initGroupTip = () => {
 
 export const showGroupTip = () => {
     let dom_denet_group_banner = document.querySelector('#denet_group_banner')
-    dom_denet_group_banner.style.visibility = 'visible';
-    dom_denet_group_banner.style.height = '100px';
+    dom_denet_group_banner.style.display = 'block';
     groupBtnStyleChange();
 }
 

+ 14 - 4
src/view/iframe/group-card/card.vue

@@ -119,11 +119,11 @@ const init = (callback) => {
                 // state.show2 = 'join'
                 callback && callback()
             }
+            sendMessageToContent({
+                actionType: 'IFRAME_GROUP_BANNER_GROUP_INFO',
+                data: res.data || {}
+            })
         }
-        sendMessageToContent({
-            actionType: 'IFRAME_GROUP_BANNER_GROUP_INFO',
-            data: res.data || {}
-        })
     })
 }
 
@@ -152,6 +152,16 @@ chrome.storage.onChanged.addListener(changes => {
     }
 })
 
+window.addEventListener("message", function (event) {
+    if (event.data) {
+        switch (event.data.actionType) {
+            case 'SHOW_BANNER':
+                state.twitterAccount = event.data.twitterAccount
+                init()
+        }
+    }
+});
+
 
 const sendMessageToContent = (params) => {
     let { actionType, data } = params || {};