Ver Fonte

[edit][postid_bing]

zhangwei há 3 anos atrás
pai
commit
bfc37105b2
3 ficheiros alterados com 23 adições e 34 exclusões
  1. 5 5
      src/entry/background.js
  2. 7 20
      src/entry/content.js
  3. 11 9
      src/logic/twitter.js

+ 5 - 5
src/entry/background.js

@@ -108,11 +108,11 @@ chrome.runtime.onConnect.addListener(function (port) {
                 break;
             case "CONTENT_TWITTER_SHORT_LINK":
                 backHttpTwitterShortUrl(res.url).then((item) => {
-                    port.postMessage({
-                        state: "BACK_TWITTER_SHORT_LINK",
-                        post_id: item.post_id,
-                        tweet_id: res.tweet_id
-                    });
+                    // port.postMessage({
+                    //     state: "BACK_TWITTER_SHORT_LINK",
+                    //     post_id: item.post_id,
+                    //     tweet_id: res.tweet_id
+                    // });
                 })
                 break
         }

+ 7 - 20
src/entry/content.js

@@ -12,8 +12,6 @@ import {
     setIframeRedPacket,
     showPinTips,
     addPinedPop,
-    bindTwitterArt,
-    bindTwitterArtMethod,
 } from "../logic/twitter.js";
 
 import { getChromeStorage } from "@/uilts/chromeExtension";
@@ -23,13 +21,13 @@ port.onMessage.addListener(function (res) {
         case "BACK_TWITTER_LOGIN_SUCCESS":
             showGiveDialogHandler();
             break;
-        case "BACK_TWITTER_SHORT_LINK":
-            console.log('BACK_TWITTER_SHORT_LINK', res)
-            console.log('needBind', bindTwitterArt.needBind)
-            if (bindTwitterArt.needBind) {
-                bindTwitterArtMethod({ postId: res.post_id, twitterId: res.tweet_id });
-            }
-            break
+        // case "BACK_TWITTER_SHORT_LINK":
+        //     console.log('BACK_TWITTER_SHORT_LINK', res)
+        //     console.log('needBind', bindTwitterArt.needBind)
+        //     if (bindTwitterArt.needBind) {
+        //         bindTwitterArtMethod({ postId: res.post_id, twitterId: res.tweet_id });
+        //     }
+        //     break
     }
 });
 
@@ -40,14 +38,6 @@ chrome.storage.onChanged.addListener(changes => {
             init()
         }
     }
-    // if (bindTwitterArt.needBind) {
-    //     let item = JSON.parse(changes.sortLink.newValue)
-    //     for (let i in item) {
-    //         if (item[i].tweet_id) {
-    //             bindTwitterArtMethod({ postId: item[i].post_id, twitterId: item[i].tweet_id });
-    //         }
-    //     }
-    // }
 })
 
 window.onload = () => {
@@ -107,8 +97,5 @@ chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
         case 'BG_SHOW_PIN_TIPS':
             showPinTips()
             break;
-        // case 'BACK_TWITTER_SHORT_LINK':
-        //     console.log('BACK_TWITTER_SHORT_LINK')
-        //     break
     }
 })

+ 11 - 9
src/logic/twitter.js

@@ -69,7 +69,6 @@ export function backTwitterPinLoginCode(code) {
 
 export function backHttpTwitterShortUrl(url) {
     return new Promise(function (resolve, reject) {
-        console.log('请求一次短链接')
         httpTwitterShortUrl(url).then(res => {
             let _str_arr = res.match(/denetme.net\/([\s\S]*?)"/) || []
             let _post_id = _str_arr[1] || ''
@@ -209,7 +208,7 @@ function getUserInfo(cb) {
 }
 
 // 绑定推文id所需参数
-export let bindTwitterArt = {
+let bindTwitterArt = {
     needBind: false,
     postId: '',
     isBindIng: false
@@ -562,7 +561,7 @@ function checkHasDeBtn() {
 /**
  * 根据postID绑定推文id
  */
-export function bindTwitterArtMethod({ postId, twitterId }) {
+function bindTwitterArtMethod({ postId, twitterId }) {
     let regex = new RegExp(bindTwitterArt.postId);
     if (regex.test(postId)) {
         if (twitterId && bindTwitterArt.needBind && !bindTwitterArt.isBindIng) {
@@ -652,10 +651,13 @@ async function parseDOMRedPacketByShortUrl(port) {
             if (parse_dom.a_tweetId && parse_dom.a_tweetId.getAttribute('href')) {
                 parse_dom.tweetId = parse_dom.a_tweetId.getAttribute('href').split('/status/')[1] || ''
             }
-            parse_dom.postId = await handleShortUrl(port, parse_dom.short_url, parse_dom.tweetId)
+            parse_dom.postId = await handleShortUrl(port, parse_dom.short_url)
             console.log('_postId', parse_dom.postId)
             // 获取到postId了
             if (parse_dom.postId) {
+                if (bindTwitterArt.needBind) {
+                    bindTwitterArtMethod({ postId: parse_dom.postId, twitterId: parse_dom.tweetId });
+                }
                 if (parse_dom.dom) {
                     parse_dom.type = 'card'
                 } else {
@@ -690,7 +692,7 @@ function getTwitterShortUrl(_article) {
     return url
 }
 // 处理短链接
-async function handleShortUrl(port, url, tweet_id) {
+async function handleShortUrl(port, url) {
     let post_id = ''
     // 校验本地是否存在
     let sort_link_data = await getChromeStorage('sortLink') || ''
@@ -710,14 +712,14 @@ async function handleShortUrl(port, url, tweet_id) {
                         }
                     }
                     setChromeStorage({ sortLink: JSON.stringify(sort_link_data) })
-                    port.postMessage({ state: 'CONTENT_TWITTER_SHORT_LINK', url, tweet_id })
+                    port.postMessage({ state: 'CONTENT_TWITTER_SHORT_LINK', url })
                 }
             }
         } else {
             // 本地没有值
             sort_link_data.push({ url, post_id: '', time: new Date().getTime() })
             setChromeStorage({ sortLink: JSON.stringify(sort_link_data) })
-            port.postMessage({ state: 'CONTENT_TWITTER_SHORT_LINK', url, tweet_id })
+            port.postMessage({ state: 'CONTENT_TWITTER_SHORT_LINK', url })
         }
         // 校验存储大小
         let new_item = checkShortUrlArraySize(sort_link_data)
@@ -726,7 +728,7 @@ async function handleShortUrl(port, url, tweet_id) {
         }
     } else {
         setChromeStorage({ sortLink: JSON.stringify([{ url, post_id: '', time: new Date().getTime() }]) })
-        port.postMessage({ state: 'CONTENT_TWITTER_SHORT_LINK', url, tweet_id })
+        port.postMessage({ state: 'CONTENT_TWITTER_SHORT_LINK', url })
     }
     return post_id
 }
@@ -766,7 +768,7 @@ function onChangePageMain(port, targetNode) {
     const callback = (mutationsList, observer) => {
         setTimeout(()=>{
             parseDOMRedPacketByShortUrl(port)
-        },1500)
+        },2000)
     }
     const observer = new MutationObserver(callback);
     observer.observe(targetNode, config);