Ver Fonte

[edit] 插件主体

wenliming há 2 anos atrás
pai
commit
c22dda6d92

+ 6 - 2
src/entry/background.js

@@ -17,7 +17,8 @@ import {
     getMessageInfo,
     injectExtensionPopup,
     setPopupConfig,
-    windwoLoadSetPopupPage
+    windwoLoadSetPopupPage,
+    setActionPopup
 } from "@/logic/background/twitter";
 
 import { PingPong } from "@/logic/background/help";
@@ -126,7 +127,10 @@ function onMessageMethod(req, sender, sendResponse) {
                 console.log('CONTENT_PONG')
                 break
             case 'CONTENT_WINDOW_LOADED_SET_POPUP_PAGE': 
-                windwoLoadSetPopupPage(req, sender);
+                // windwoLoadSetPopupPage(req, sender);
+                break;
+            case 'CONTENT_SET_POPUP_CONFIG':
+                setActionPopup(req, sender);
                 break;
         }
     }

+ 5 - 1
src/entry/content.js

@@ -23,7 +23,8 @@ import {
     showNFTSale,
     showBuyNFT,
     hideBuyNFT,
-    showPopupPage
+    showPopupPage,
+    setPopupConfByPopupPage
 } from "@/logic/content/twitter.js";
 
 import {
@@ -116,6 +117,9 @@ chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
         case 'IFRAME_TWITTER_HIDE_BUY_NFT':
             hideBuyNFT()
             break
+        case 'BG_SET_POPUP_CONFIG':
+            setPopupConfByPopupPage();
+            break
     }
 })
 

+ 7 - 0
src/entry/content_help.js

@@ -11,6 +11,13 @@ window.onload = () => {
     }, () => { });
 };
 
+chrome.runtime.sendMessage({ 
+    actionType: "CONTENT_SET_POPUP_CONFIG", 
+    data: {
+        popup: 'popup.html'
+    } 
+}, () => { });
+
 chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
     sendResponse('')
     switch (req.actionType) {

+ 37 - 5
src/logic/background/twitter.js

@@ -380,17 +380,28 @@ export const setPopupConfig = (activeInfo) => {
     }, (tabs) => {
         if(tabs.length) {
             let {pendingUrl = '', url = ''} = tabs[0];
-            if(pendingUrl.startsWith('chrome://') || url.startsWith('chrome://') || pendingUrl.startsWith('https://chrome.google.com') || url.startsWith('https://chrome.google.com')) {
-                chrome.action.setPopup({
-                    popup: 'popup.html',
-                },function() {
+            if(pendingUrl.startsWith('https://twitter.com') || url.startsWith('https://twitter.com')) {
+                sendActivetabMessage({
+                    actionType: 'BG_SET_POPUP_CONFIG'
                 });
             } else {
                 chrome.action.setPopup({
-                    popup: '',
+                    popup: 'popup.html',
                 },function() {
                 });
             }
+
+            // if(pendingUrl.startsWith('chrome://') || url.startsWith('chrome://') || pendingUrl.startsWith('https://chrome.google.com') || url.startsWith('https://chrome.google.com')) {
+            //     chrome.action.setPopup({
+            //         popup: 'popup.html',
+            //     },function() {
+            //     });
+            // } else {
+            //     chrome.action.setPopup({
+            //         popup: '',
+            //     },function() {
+            //     });
+            // }
         }
     })
 }
@@ -408,4 +419,25 @@ export const windwoLoadSetPopupPage = (data, sender) => {
         },function() {
         });
     }
+}
+
+export const setActionPopup = (data) => {
+    let {popup} = data.data || {};
+    if(popup) {
+        chrome.action.getPopup(
+            {},
+            function(result){
+                if(!result) {
+                    chrome.action.setPopup({
+                        popup,
+                    },function() {
+                    });
+                }
+        });
+    } else {
+        chrome.action.setPopup({
+            popup: '',
+        },function() {
+        });
+    }
 }

+ 54 - 1
src/logic/content/twitter.js

@@ -794,6 +794,13 @@ export function init() {
     getDiscordAuthCode();
     appendPopupPage();
 
+    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;
     if (where) {
         return
@@ -806,7 +813,7 @@ export function init() {
     checkTwitterTaskState();
 
     onBodyClick();
-    initBuyNFT()
+    initBuyNFT();
 
     getChromeStorage("popupShowPublishDialog", (res) => {
         console.log("popupShowPublishDialog", res);
@@ -1353,6 +1360,13 @@ export const showPopupPage = (params = {}) => {
             actionType: "CONTENT_POPUP_PAGE_SHOW", 
             data: { } 
         }, () => { });
+
+        chrome.runtime.sendMessage({ 
+            actionType: "CONTENT_SET_POPUP_CONFIG", 
+            data: {
+                popup: ''
+            } 
+        }, () => { });
     
         let overlay = document.getElementById('de-popup-overlay');
         overlay.style.display = 'block';
@@ -1376,6 +1390,14 @@ export const hidePopupPage = () => {
         if(htmlDom) {
             htmlDom.style.overflowY = 'auto';
         }
+
+        chrome.runtime.sendMessage({ 
+            actionType: "CONTENT_SET_POPUP_CONFIG", 
+            data: {
+                popup: 'popup.html'
+            } 
+        }, () => { });
+
         if(showPopupPageFrom == 'BUY_NFT_FINISH') {
             chrome.runtime.sendMessage({ 
                 actionType: "CONTENT_GET_PINED", 
@@ -1418,4 +1440,35 @@ const onBodyClick = () => {
             // hidePopupPage();
         })
     } 
+}
+
+
+export const setPopupConfByPopupPage = () => {
+    let iframe = document.getElementById('de-popup-page');
+    if (iframe) {
+        let {transform = ''} = iframe.style;
+
+        if(transform && transform == 'translateX(-395px)') {
+            chrome.runtime.sendMessage({ 
+                actionType: "CONTENT_SET_POPUP_CONFIG", 
+                data: {
+                    popup: ''
+                } 
+            }, () => { });
+        } else {
+            chrome.runtime.sendMessage({ 
+                actionType: "CONTENT_SET_POPUP_CONFIG", 
+                data: {
+                    popup: 'popup.html'
+                } 
+            }, () => { });
+        }
+    } else {
+        chrome.runtime.sendMessage({ 
+            actionType: "CONTENT_SET_POPUP_CONFIG", 
+            data: {
+                popup: 'popup.html'
+            } 
+        }, () => { });
+    }
 }

+ 1 - 0
src/manifest.json

@@ -13,6 +13,7 @@
         "128": "/logo/128.png"
     },
     "action": {
+        "default_popup": "popup.html"
     },
     "content_scripts": [
         {

+ 2 - 1
src/view/components/popup-transactions.vue

@@ -355,11 +355,12 @@ const listScroll = (e) => {
                     width: 34px;
                     height: 34px;
                     border-radius: 50%;
+                    margin-right: 4px;
                 }
 
                 .icon-give {
                     position: absolute;
-                    right: -4px;
+                    right: -2px;
                     top: 19px;
                 }
             }

+ 0 - 1
src/view/iframe/red-packet/red-packet.vue

@@ -1620,7 +1620,6 @@ function onWindowMessage() {
 function onPageVisbile() {
   document.addEventListener('visibilitychange', function () {
     let isHidden = document.hidden;
-    console.log('joinDiscordActionState', joinDiscordActionState);
     if (!isHidden) {
       checkJoinDiscord();
     }

+ 2 - 2
src/view/popup/tabbar-page/message/index.vue

@@ -501,8 +501,8 @@ onBeforeUnmount(() => {
             box-sizing: border-box;
 
             .icon-avatar {
-              width: 36px;
-              height: 36px;
+              width: 34px;
+              height: 34px;
               border-radius: 50%;
               margin-right: 8px;
             }

+ 1 - 1
src/view/popup/tabbar-page/nft/detail.vue

@@ -150,7 +150,7 @@ const clickToken = () => {
 }
 
 const clickNFTImg = () => {
-    window.open(NFTInfo.value.imagePath);
+    // window.open(NFTInfo.value.imagePath);
 };
 
 const getDetail = () => {