|
@@ -88,7 +88,7 @@ export function renderDom(port) {
|
|
|
*/
|
|
|
export function showGiveDialogHandler(userInfo) {
|
|
|
let iframe = document.getElementById('iframe-content');
|
|
|
- if(iframe) {
|
|
|
+ if (iframe) {
|
|
|
iframe.contentWindow.postMessage({ actionType: 'CONTENT_SHOW_GIVE_DIALOG', userInfo }, '*');
|
|
|
} else {
|
|
|
_addIframe();
|
|
@@ -291,7 +291,7 @@ function _deNetBtnClick(port) {
|
|
|
showGiveDialogHandler(res);
|
|
|
} else {
|
|
|
let loadIcon = document.getElementById('de-btn-loading');
|
|
|
- if(loadIcon) {
|
|
|
+ if (loadIcon) {
|
|
|
return;
|
|
|
}
|
|
|
dom.deBtn.insertBefore(dom.loadingImg, dom.deBtn.querySelector('span'));
|
|
@@ -372,8 +372,8 @@ function _createBtnDom(port) {
|
|
|
dom.loadingImg = loadingImg;
|
|
|
}
|
|
|
|
|
|
-function addSliderNavDeBtn (isSmall = false) {
|
|
|
- if(!isSmall) {
|
|
|
+function addSliderNavDeBtn(isSmall = false) {
|
|
|
+ if (!isSmall) {
|
|
|
let bigDom = document.querySelector('header[role="banner"]').querySelector('.r-1habvwh');
|
|
|
if (bigDom) {
|
|
|
bigDom.appendChild(dom.deBtn);
|
|
@@ -386,10 +386,10 @@ function addSliderNavDeBtn (isSmall = false) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function onWindowResize () {
|
|
|
- window.onresize = throttle(function() {
|
|
|
+function onWindowResize() {
|
|
|
+ window.onresize = throttle(function () {
|
|
|
try {
|
|
|
- if(window.innerWidth < 1270) {
|
|
|
+ if (window.innerWidth < 1270) {
|
|
|
let bigBtn = document.querySelector('#de-btn');
|
|
|
bigBtn && bigBtn.remove();
|
|
|
setTimeout(() => {
|
|
@@ -408,7 +408,7 @@ function onWindowResize () {
|
|
|
}, 800)
|
|
|
}
|
|
|
|
|
|
-function checkHasDeBtn () {
|
|
|
+function checkHasDeBtn() {
|
|
|
setInterval(() => {
|
|
|
try {
|
|
|
let toolBar = document.querySelector('div[data-testid="toolBar"]');
|
|
@@ -417,49 +417,29 @@ function checkHasDeBtn () {
|
|
|
let dialogScheduleBtn = _getScheduleDom(false);
|
|
|
_addDeNetEditBtn(dialogScheduleBtn, dom.deBtn1);
|
|
|
}
|
|
|
- } catch(e) {
|
|
|
+ } catch (e) {
|
|
|
console.log(e)
|
|
|
}
|
|
|
}, 1000)
|
|
|
}
|
|
|
|
|
|
function parseDOMRedPacket() {
|
|
|
- // let _dom = null
|
|
|
- // let denet_arr = document.querySelector('article[data-testid=tweet]').querySelectorAll('a')
|
|
|
- // let _dom = null
|
|
|
- // for (let i in denet_arr) {
|
|
|
- // if (denet_arr[i].innerText == '#DeNet') {
|
|
|
- // _dom = denet_arr[i].parentNode.parentNode.parentNode.parentNode.children[1]
|
|
|
- // // 是否有有红包秘文
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // //
|
|
|
- // denet_arr = document.querySelector('section').querySelectorAll('a')
|
|
|
- // for (let i in denet_arr) {
|
|
|
- // if (denet_arr[i].innerText == '#DeNet') {
|
|
|
- // _dom = denet_arr[i].parentNode
|
|
|
- // // 是否有有红包秘文
|
|
|
- // }
|
|
|
- // }
|
|
|
- // return _dom
|
|
|
+ let _dom = null
|
|
|
let arr = document.querySelectorAll('a') || []
|
|
|
|
|
|
- arr.forEach((item) => {
|
|
|
- if (item.innerText == '#DeNet') {
|
|
|
- if (item.parentNode && item.parentNode.parentNode && item.parentNode.parentNode.innerText.length > 5) {
|
|
|
- let _postId = item.parentNode.parentNode.innerText || ''
|
|
|
- _postId = _postId.match(/###([\s\S]*?)###/)[1];
|
|
|
- let _dom = item.parentNode.parentNode.parentNode.parentNode.parentNode
|
|
|
- let _tweetId = _dom.children[0].querySelector('a[dir="auto"]').getAttribute('href').split('/status/')[1];
|
|
|
- replaceDOMRedPacket(_dom.children[1], _postId,_tweetId)
|
|
|
- }
|
|
|
-
|
|
|
+ for (let i in arr) {
|
|
|
+ if (arr[i].innerText == '#DeNet') {
|
|
|
+ let _article = arr[i].closest('article')
|
|
|
+ let _postId = _article.querySelector('[lang]').innerText
|
|
|
+ _postId = _postId.match(/###([\s\S]*?)###/)[1]
|
|
|
+ _dom = _article.querySelector('[aria-labelledby]')
|
|
|
+ let _tweetId = _article.querySelector('a[aria-label]').getAttribute('href').split('/status/')[1]
|
|
|
+ replaceDOMRedPacket(_dom, _postId, _tweetId)
|
|
|
}
|
|
|
- })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function replaceDOMRedPacket(_dom, postId,tweetId) {
|
|
|
+function replaceDOMRedPacket(_dom, postId, tweetId) {
|
|
|
if (!_dom || _dom.querySelector('iframe')) {
|
|
|
return
|
|
|
}
|
|
@@ -480,9 +460,11 @@ function replaceDOMRedPacket(_dom, postId,tweetId) {
|
|
|
export function setIframeRedPacket() {
|
|
|
// let elment = document.documentElement
|
|
|
|
|
|
- // if(window.location.href != 'https://twitter.com/home'){
|
|
|
- // return
|
|
|
- // }
|
|
|
+ if(window.location.href.includes('https://twitter.com)')){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // const observer = new MutationObserver(callback);
|
|
|
+
|
|
|
parseDOMRedPacket()
|
|
|
// let _current_top = 0
|
|
|
setInterval(() => {
|