|
@@ -89,7 +89,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();
|
|
@@ -112,24 +112,7 @@ export function hideIframeHandler() {
|
|
|
export function showTwitterPublishDialogHandler(publishRes) {
|
|
|
dom.tweetBtn.click();
|
|
|
_setPublishContent(publishRes.srcContent);
|
|
|
- _publishTweetEvent(publishRes.postId, (twitterArtId) => {
|
|
|
- if (twitterArtId) {
|
|
|
- getUserInfo((userInfo) => {
|
|
|
- if (userInfo) {
|
|
|
- srcPublishSuccess({
|
|
|
- baseInfo: {
|
|
|
- token: userInfo.accessToken
|
|
|
- },
|
|
|
- params: {
|
|
|
- postId: publishRes.postId,
|
|
|
- srcContentId: twitterArtId
|
|
|
- }
|
|
|
- }).then(() => {
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- });
|
|
|
+ _publishTweetEvent(publishRes.postId);
|
|
|
}
|
|
|
|
|
|
function getUserInfo(cb) {
|
|
@@ -138,6 +121,12 @@ function getUserInfo(cb) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+let bindTwitterArt = {
|
|
|
+ needBind: false,
|
|
|
+ postId: '',
|
|
|
+ isBindIng: false
|
|
|
+};
|
|
|
|
|
|
* 监听dialog内点击原生发布按钮事件
|
|
|
* @private
|
|
@@ -146,11 +135,14 @@ function _publishTweetEvent(contentStr, cb) {
|
|
|
setTimeout(() => {
|
|
|
let publishTweetBtn = document.querySelector('div[role="dialog"]').querySelector('div[data-testid="tweetButton"]');
|
|
|
publishTweetBtn.addEventListener('click', function () {
|
|
|
- setTimeout(() => {
|
|
|
- _getTwitterArtId(contentStr, (twitterArtId) => {
|
|
|
- cb && cb(twitterArtId)
|
|
|
- });
|
|
|
- }, 1500)
|
|
|
+ bindTwitterArt.needBind = true;
|
|
|
+ bindTwitterArt.postId = contentStr;
|
|
|
+ isSetContent = false;
|
|
|
+
|
|
|
+
|
|
|
+ cb && cb()
|
|
|
+
|
|
|
+
|
|
|
});
|
|
|
}, 800)
|
|
|
}
|
|
@@ -251,7 +243,8 @@ function _addIframe() {
|
|
|
* @returns {string}
|
|
|
* @private
|
|
|
*/
|
|
|
-function _getTwitterArtId(contentStr, cb) {
|
|
|
+
|
|
|
+
|
|
|
let id = '';
|
|
|
|
|
|
let timer = setInterval(() => {
|
|
@@ -276,6 +269,7 @@ function _getTwitterArtId(contentStr, cb) {
|
|
|
}
|
|
|
}, 1000);
|
|
|
}
|
|
|
+*/
|
|
|
|
|
|
|
|
|
* 点击deNet按钮处理
|
|
@@ -293,7 +287,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'));
|
|
@@ -310,11 +304,16 @@ function _deNetBtnClick(port) {
|
|
|
* @param content
|
|
|
* @private
|
|
|
*/
|
|
|
+let isSetContent = false;
|
|
|
function _setPublishContent(content) {
|
|
|
setTimeout(() => {
|
|
|
|
|
|
-
|
|
|
- document.execCommand("insertText", false, content);
|
|
|
+
|
|
|
+ if(!isSetContent) {
|
|
|
+ isSetContent = true;
|
|
|
+ document.execCommand("insertText", false, content);
|
|
|
+ }
|
|
|
+
|
|
|
}, 1000);
|
|
|
}
|
|
|
|
|
@@ -375,8 +374,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);
|
|
@@ -389,10 +388,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(() => {
|
|
@@ -411,7 +410,7 @@ function onWindowResize () {
|
|
|
}, 800)
|
|
|
}
|
|
|
|
|
|
-function checkHasDeBtn () {
|
|
|
+function checkHasDeBtn() {
|
|
|
setInterval(() => {
|
|
|
try {
|
|
|
let toolBar = document.querySelector('div[data-testid="toolBar"]');
|
|
@@ -420,49 +419,57 @@ function checkHasDeBtn () {
|
|
|
let dialogScheduleBtn = _getScheduleDom(false);
|
|
|
_addDeNetEditBtn(dialogScheduleBtn, dom.deBtn1);
|
|
|
}
|
|
|
- } catch(e) {
|
|
|
+ } catch (e) {
|
|
|
console.log(e)
|
|
|
}
|
|
|
}, 1000)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 根据postID绑定推文id
|
|
|
+ */
|
|
|
+ function bindTwitterArtMethod({postId, twitterId}) {
|
|
|
+ let regex = new RegExp(bindTwitterArt.postId);
|
|
|
+ if (regex.test(postId)) {
|
|
|
+ if (twitterId && bindTwitterArt.needBind && !bindTwitterArt.isBindIng) {
|
|
|
+ bindTwitterArt.isBindIng = true;
|
|
|
+ srcPublishSuccess({
|
|
|
+ params: {
|
|
|
+ postId: postId,
|
|
|
+ srcContentId: twitterId
|
|
|
+ }
|
|
|
+ }).then((res) => {
|
|
|
+ if(res.code == 0) {
|
|
|
+ bindTwitterArt.needBind = false;
|
|
|
+ bindTwitterArt.postId = '';
|
|
|
+ bindTwitterArt.isBindIng = false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
function parseDOMRedPacket() {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ 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]
|
|
|
+
|
|
|
+ if(bindTwitterArt.needBind) {
|
|
|
+ bindTwitterArtMethod({postId: _postId, twitterId: _tweetId});
|
|
|
}
|
|
|
-
|
|
|
+ replaceDOMRedPacket(_dom, _postId, _tweetId)
|
|
|
}
|
|
|
- })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function replaceDOMRedPacket(_dom, postId,tweetId) {
|
|
|
+function replaceDOMRedPacket(_dom, postId, tweetId) {
|
|
|
if (!_dom || _dom.querySelector('iframe')) {
|
|
|
return
|
|
|
}
|
|
@@ -483,9 +490,11 @@ function replaceDOMRedPacket(_dom, postId,tweetId) {
|
|
|
export function setIframeRedPacket() {
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ if(window.location.href.includes('https://twitter.com)')){
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
parseDOMRedPacket()
|
|
|
|
|
|
setInterval(() => {
|