|
@@ -545,16 +545,26 @@ function parseDOMRedPacket() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+function getTwitterIdByDOM(dom) {
|
|
|
|
+ let _twitter_id = ''
|
|
|
|
+ for (let i in dom) {
|
|
|
|
+ if (dom[i].href.indexOf('/status/') > 0) {
|
|
|
|
+ _twitter_id = dom[i].href.split('/status/')[1] || ''
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return _twitter_id
|
|
|
|
+}
|
|
|
|
|
|
let parse_dom = {}
|
|
let parse_dom = {}
|
|
|
|
|
|
async function parseDOMRedPacketByShortUrl(port) {
|
|
async function parseDOMRedPacketByShortUrl(port) {
|
|
- // let _new_time = new Date().getTime()
|
|
|
|
- // if ((_new_time - change_time) > 1000) {
|
|
|
|
- // change_time = _new_time
|
|
|
|
- // } else {
|
|
|
|
- // return
|
|
|
|
- // }
|
|
|
|
|
|
+ let _new_time = new Date().getTime()
|
|
|
|
+ if ((_new_time - change_time) > 1000) {
|
|
|
|
+ change_time = _new_time
|
|
|
|
+ } else {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
// 为了减少声明变量次数
|
|
// 为了减少声明变量次数
|
|
parse_dom.dom = null
|
|
parse_dom.dom = null
|
|
parse_dom.txt_area = null
|
|
parse_dom.txt_area = null
|
|
@@ -578,16 +588,11 @@ async function parseDOMRedPacketByShortUrl(port) {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
parse_dom.short_url = getTwitterShortUrl(parse_dom.article)
|
|
parse_dom.short_url = getTwitterShortUrl(parse_dom.article)
|
|
- parse_dom.a_tweetId = parse_dom.article.querySelector('a[aria-label]')
|
|
|
|
- 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.tweetId = getTwitterIdByDOM(parse_dom.article.querySelectorAll('a'))
|
|
parse_dom.postId = await handleShortUrl(port, parse_dom.short_url)
|
|
parse_dom.postId = await handleShortUrl(port, parse_dom.short_url)
|
|
- console.log('_postId', parse_dom.postId)
|
|
|
|
- console.log('short_url', parse_dom.short_url)
|
|
|
|
|
|
|
|
// 获取到postId了
|
|
// 获取到postId了
|
|
- if (parse_dom.postId) {
|
|
|
|
|
|
+ if (parse_dom.postId && parse_dom.tweetId) {
|
|
console.log('bindTwitterArt.postId', bindTwitterArt.postId)
|
|
console.log('bindTwitterArt.postId', bindTwitterArt.postId)
|
|
console.log('parse_dom.postId', parse_dom.postId)
|
|
console.log('parse_dom.postId', parse_dom.postId)
|
|
if (bindTwitterArt.needBind) {
|
|
if (bindTwitterArt.needBind) {
|
|
@@ -697,17 +702,17 @@ 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 callback = (mutationsList, observer) => {
|
|
|
|
-// setTimeout(() => {
|
|
|
|
-// parseDOMRedPacketByShortUrl(port)
|
|
|
|
-// }, 2000)
|
|
|
|
-// }
|
|
|
|
-// const observer = new MutationObserver(callback);
|
|
|
|
-// observer.observe(targetNode, config);
|
|
|
|
-// }
|
|
|
|
|
|
+let change_time = new Date().getTime()
|
|
|
|
+function onChangePageMain(port, targetNode) {
|
|
|
|
+ const config = { attributes: true, childList: true, subtree: true };
|
|
|
|
+ const callback = (mutationsList, observer) => {
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ parseDOMRedPacketByShortUrl(port)
|
|
|
|
+ }, 1500)
|
|
|
|
+ }
|
|
|
|
+ const observer = new MutationObserver(callback);
|
|
|
|
+ observer.observe(targetNode, config);
|
|
|
|
+}
|
|
|
|
|
|
function setIframeRedPacket(port) {
|
|
function setIframeRedPacket(port) {
|
|
// let elment = document.documentElement
|
|
// let elment = document.documentElement
|
|
@@ -715,19 +720,19 @@ function setIframeRedPacket(port) {
|
|
if (window.location.href.includes('twitter.com)')) {
|
|
if (window.location.href.includes('twitter.com)')) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- setInterval(() => {
|
|
|
|
- parseDOMRedPacketByShortUrl(port)
|
|
|
|
- }, 1000)
|
|
|
|
|
|
+ // setInterval(() => {
|
|
|
|
+ // parseDOMRedPacketByShortUrl(port)
|
|
|
|
+ // }, 1000)
|
|
|
|
|
|
|
|
|
|
- // let targetNode = null
|
|
|
|
- // let timer = setInterval(() => {
|
|
|
|
- // targetNode = document.querySelector('main')
|
|
|
|
- // if (targetNode) {
|
|
|
|
- // clearInterval(timer)
|
|
|
|
- // onChangePageMain(port, targetNode)
|
|
|
|
- // }
|
|
|
|
- // }, 1000);
|
|
|
|
|
|
+ let targetNode = null
|
|
|
|
+ let timer = setInterval(() => {
|
|
|
|
+ targetNode = document.querySelector('main')
|
|
|
|
+ if (targetNode) {
|
|
|
|
+ clearInterval(timer)
|
|
|
|
+ onChangePageMain(port, targetNode)
|
|
|
|
+ }
|
|
|
|
+ }, 1000);
|
|
}
|
|
}
|
|
|
|
|
|
export function initExecuteScript(changes) {
|
|
export function initExecuteScript(changes) {
|