소스 검색

[edit][time]

zhangwei 3 년 전
부모
커밋
78646407cd
2개의 변경된 파일11개의 추가작업 그리고 9개의 파일을 삭제
  1. 1 1
      src/entry/content.js
  2. 10 8
      src/logic/content/twitter.js

+ 1 - 1
src/entry/content.js

@@ -23,7 +23,7 @@ port.onMessage.addListener(function (res) {
 });
 
 chrome.storage.onChanged.addListener(changes => {
-    initExecuteScript(changes)
+    initExecuteScript(port,changes)
 })
 
 window.onload = () => {

+ 10 - 8
src/logic/content/twitter.js

@@ -586,9 +586,9 @@ async function parseDOMRedPacketByShortUrl(port) {
             if (parse_dom.postId && parse_dom.tweetId) {
                 console.log('bindTwitterArt.postId', bindTwitterArt.postId)
                 console.log('parse_dom.postId', parse_dom.postId)
-                if (bindTwitterArt.needBind) {
-                    bindTwitterArtMethod({ postId: parse_dom.postId, twitterId: parse_dom.tweetId });
-                }
+                // if (bindTwitterArt.needBind) {
+                //     bindTwitterArtMethod({ postId: parse_dom.postId, twitterId: parse_dom.tweetId });
+                // }
                 if (parse_dom.dom) {
                     parse_dom.type = 'card'
                 } else {
@@ -636,10 +636,11 @@ async function handleShortUrl(port, url) {
             } else {
                 // 防止多次请求,校验timeout时间
                 let _new_time = new Date().getTime()
-                if (_new_time - _item[0].time > 5000) {
+                if (_new_time - _item[0].time > 1000) {
                     for (let i in sort_link_data) {
                         if (sort_link_data[i].url == url) {
                             sort_link_data[i].time = _new_time
+                            break
                         }
                     }
                     setChromeStorage({ sortLink: JSON.stringify(sort_link_data) })
@@ -695,11 +696,12 @@ function replaceDOMRedPacket(_type, _dom, postId, tweetId) {
 
 let change_time = new Date().getTime()
 function onChangePageMain(port, targetNode) {
-    const config = { attributes: true, childList: true, subtree: true };
+    const config = { attributes: false, childList: true, subtree: true };
     const callback = (mutationsList, observer) => {
+        parseDOMRedPacketByShortUrl(port)
         setTimeout(() => {
             parseDOMRedPacketByShortUrl(port)
-        }, 1500)
+        }, 1100)
     }
     const observer = new MutationObserver(callback);
     observer.observe(targetNode, config);
@@ -726,11 +728,11 @@ function setIframeRedPacket(port) {
     }, 1000);
 }
 
-export function initExecuteScript(changes) {
+export function initExecuteScript(port,changes) {
     if (changes.executeScript) {
         let item = JSON.parse(changes.executeScript.newValue)
         if (item.executeScript) {
-            init()
+            init(port)
         }
     }
 }