|
@@ -495,16 +495,14 @@ import parseCard from './ParseCard'
|
|
|
|
|
|
|
|
|
|
|
|
-let change_time = new Date().getTime()
|
|
|
+let change_num = 0
|
|
|
function onChangePageMain(port, targetNode) {
|
|
|
const config = { attributes: false, childList: true, subtree: true };
|
|
|
let article = null
|
|
|
const callback = (mutationsList, observer) => {
|
|
|
for (let i in mutationsList) {
|
|
|
if (mutationsList[i].target && mutationsList[i].target.querySelector('article')) {
|
|
|
- setTimeout(()=>{
|
|
|
- setIframeRedPacket(port)
|
|
|
- },1000)
|
|
|
+ change_num++
|
|
|
break
|
|
|
}
|
|
|
}
|
|
@@ -521,36 +519,33 @@ function onChangePageMain(port, targetNode) {
|
|
|
function setIframeRedPacket(port) {
|
|
|
// let elment = document.documentElement
|
|
|
|
|
|
- if (window.location.href.includes('twitter.com)')) {
|
|
|
- return
|
|
|
- }
|
|
|
- let new_time = new Date().getTime()
|
|
|
- if(new_time - change_time < 1000){
|
|
|
- return
|
|
|
- }
|
|
|
- change_time = new_time
|
|
|
-
|
|
|
- let stop_time = 0
|
|
|
- let timer = setInterval(() => {
|
|
|
- stop_time++
|
|
|
- // 获取所有卡片参数
|
|
|
- let card_json_data = parseCard.parseAllDeNetCardParmas()
|
|
|
- // 过滤出可以请求的短链接
|
|
|
- parseCard.getCardParmas(card_json_data).then((res) => {
|
|
|
- for (let i in res.has_post_Id_card_data) {
|
|
|
- parseCard.replaceDOMRedPacket(res.has_post_Id_card_data[i])
|
|
|
- }
|
|
|
- if (res.need_net_short_url.length > 0) {
|
|
|
- // 请求短链接
|
|
|
- port.postMessage({ state: 'CONTENT_TWITTER_SHORT_LINK', arr_url: res.need_net_short_url })
|
|
|
- }
|
|
|
- if (card_json_data.length == res.has_post_Id_card_data.length || stop_time >= 5) {
|
|
|
- clearInterval(timer)
|
|
|
- }
|
|
|
- })
|
|
|
- }, 1000)
|
|
|
+
|
|
|
+
|
|
|
+ // let new_time = new Date().getTime()
|
|
|
+ // console.log('new_time',new_time)
|
|
|
+ // if (new_time - change_time < 1000) {
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+
|
|
|
+ // change_time = new_time
|
|
|
+ // 获取所有卡片参数
|
|
|
+ let card_json_data = parseCard.parseAllDeNetCardParmas()
|
|
|
+ // 过滤出可以请求的短链接
|
|
|
+ parseCard.getCardParmas(card_json_data).then((res) => {
|
|
|
+ for (let i in res.has_post_Id_card_data) {
|
|
|
+ parseCard.replaceDOMRedPacket(res.has_post_Id_card_data[i])
|
|
|
+ }
|
|
|
+ if (res.need_net_short_url.length > 0) {
|
|
|
+ // 请求短链接
|
|
|
+ port.postMessage({ state: 'CONTENT_TWITTER_SHORT_LINK', arr_url: res.need_net_short_url })
|
|
|
+ }
|
|
|
+ // card_json_data.length == res.has_post_Id_card_data.length ||
|
|
|
+ })
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
export function initExecuteScript(port, changes) {
|
|
|
if (changes.executeScript) {
|
|
|
let item = JSON.parse(changes.executeScript.newValue)
|
|
@@ -559,7 +554,9 @@ export function initExecuteScript(port, changes) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+export function addChangeNum() {
|
|
|
+ change_num++
|
|
|
+}
|
|
|
// 初始化
|
|
|
export function init(port) {
|
|
|
if (window.location.href.indexOf('twitter.com') < 0) {
|
|
@@ -573,6 +570,17 @@ export function init(port) {
|
|
|
if (targetNode) {
|
|
|
clearInterval(timer)
|
|
|
onChangePageMain(port, targetNode)
|
|
|
+ setInterval(() => {
|
|
|
+ if (window.location.href.includes('twitter.com)')) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log('change_num',change_num)
|
|
|
+ if (change_num <= 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ change_num = change_num - 1
|
|
|
+ setIframeRedPacket(port)
|
|
|
+ }, 1000)
|
|
|
}
|
|
|
}, 1000);
|
|
|
|