瀏覽代碼

[edit][优化安装后打开新标签页]

zhangwei 2 年之前
父節點
當前提交
e6f0475538
共有 1 個文件被更改,包括 62 次插入46 次删除
  1. 62 46
      src/logic/background/twitter.js

+ 62 - 46
src/logic/background/twitter.js

@@ -248,63 +248,79 @@ function sendActivetabMessage(message = {}) {
 /**
  * 安装后打开新标签页
  */
+
 export function onInstalledCreateTab() {
+    // 落地页参数
     let cookiesParams = {
-        name: 'pickup_info',
+        name: 'jump_info',
         url: pageUrl
     }
     getChromeCookie(cookiesParams, (res) => {
-        let { postNickName, srcContentId } = res;
-        if (res && postNickName && srcContentId) {
-            let url = `https://twitter.com/${postNickName}/status/${srcContentId}`
-            chrome.tabs.create({
-                url
-            });
-            removeChromeCookie(cookiesParams)
-        } else {
-            let nftParams = {
-                name: 'nft_info',
-                url: pageUrl
-            }
-            getChromeCookie(nftParams, (res) => {
-                let { twitterAccount, nftProjectId } = res;
-                if (res && twitterAccount && nftProjectId) {
-                    let url = `https://twitter.com/${twitterAccount}`
+        // jump_info
+        if (!res || !res.jump_type) {
+            return
+        }
+        switch (String(res.jump_type)) {
+            // 普通红包
+            case 'red_packet':
+                if (res && res.postNickName && res.srcContentId) {
+                    let url = `https://twitter.com/${res.postNickName}/status/${res.srcContentId}`
                     chrome.tabs.create({
                         url
                     });
-                    removeChromeCookie(nftParams)
-                } else {
-                    let nftGroupParams = {
-                        name: 'nft_group_info',
-                        url: pageUrl
-                    }
-                    getChromeCookie(nftGroupParams, (res) => {
-                        let { twitterAccount } = res;
-                        if (res && twitterAccount) {
-                            // setChromeStorage({ groupTabData: JSON.stringify({
-                            //     deTabVal: 'deGroupTab'
-                            // })})
-                            chrome.storage.local.set({
-                                groupTabData: JSON.stringify({
-                                    deTabVal: 'deGroupTab'
-                                })
-                            }, (res) => {
-                                let url = `https://twitter.com/${twitterAccount}`
-                                chrome.tabs.create({
-                                    url
-                                });
-                            })
-                            removeChromeCookie(nftGroupParams)
-                        } else {
-                            chrome.tabs.create({
-                                url: "https://twitter.com",
-                            });
-                        }
+                }
+                break
+            // 抽奖红包
+            case 'luck_draw':
+                if (res && res.postNickName && res.srcContentId) {
+                    let url = `https://twitter.com/${res.postNickName}/status/${res.srcContentId}`
+                    chrome.tabs.create({
+                        url
+                    });
+                }
+                break
+            // NFT
+            case 'ntf_info':
+                if (res && res.twitterAccount && res.nftProjectId) {
+                    let url = `https://twitter.com/${res.twitterAccount}`
+                    chrome.tabs.create({
+                        url
+                    });
+                }
+                break
+            // NFT 组
+            case 'nft_group_info':
+                if (res && res.twitterAccount) {
+                    // setChromeStorage({ groupTabData: JSON.stringify({
+                    //     deTabVal: 'deGroupTab'
+                    // })})
+                    chrome.storage.local.set({
+                        groupTabData: JSON.stringify({
+                            deTabVal: 'deGroupTab'
+                        })
+                    }, (res) => {
+                        let url = `https://twitter.com/${res.twitterAccount}`
+                        chrome.tabs.create({
+                            url
+                        });
                     })
                 }
-            })
+                break
+            // toolbox
+            case 'tool_box':
+                if (res && res.postNickName && res.srcContentId) {
+                    let url = `https://twitter.com/${res.postNickName}/status/${res.srcContentId}`
+                    chrome.tabs.create({
+                        url
+                    });
+                }
+                break
+            default:
+                chrome.tabs.create({
+                    url: "https://twitter.com",
+                });
         }
+        removeChromeCookie(cookiesParams)
     })
 }