|
@@ -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);
|