|
@@ -1,17 +1,18 @@
|
|
|
import { getChromeStorage, setChromeStorage } from '@/uilts/chromeExtension.js'
|
|
|
import { throttle } from '@/uilts/help'
|
|
|
-import { srcPublishSuccess } from '@/http/publishApi'
|
|
|
+import { reportSrcPublishEvent } from '@/http/publishApi'
|
|
|
import Report from "@/log-center/log"
|
|
|
|
|
|
|
|
|
let dom = {};
|
|
|
|
|
|
-function twitterPinLogin(port) {
|
|
|
+function twitterPinLogin() {
|
|
|
if (window.location.href == 'https://api.twitter.com/oauth/authorize') {
|
|
|
let code = document.querySelector('code')
|
|
|
|
|
|
if (code) {
|
|
|
- port.postMessage({ state: 'CONTENT_SEND_CODE', code: code.innerText })
|
|
|
+ chrome.runtime.sendMessage({ actionType: "CONTENT_SEND_CODE", code: code.innerText }, () => { })
|
|
|
+ // port.postMessage({ state: 'CONTENT_SEND_CODE', code: code.innerText })
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -22,9 +23,9 @@ function twitterPinLogin(port) {
|
|
|
* 渲染要插入的dom,初始化逻辑
|
|
|
* @param port
|
|
|
*/
|
|
|
-function renderDom(port) {
|
|
|
+function renderDom() {
|
|
|
if (window.location.href.indexOf('https://twitter.com') > -1) {
|
|
|
- _createBtnDom(port);
|
|
|
+ _createBtnDom();
|
|
|
onWindowResize();
|
|
|
checkHasDeBtn();
|
|
|
setTimeout(() => {
|
|
@@ -263,7 +264,7 @@ function _addIframe() {
|
|
|
* 点击deNet按钮处理
|
|
|
* @private
|
|
|
*/
|
|
|
-function _deNetBtnClick(port) {
|
|
|
+function _deNetBtnClick() {
|
|
|
getUserInfo((res) => {
|
|
|
if (res) {
|
|
|
if (window.location.pathname != '/home') {
|
|
@@ -286,7 +287,8 @@ function _deNetBtnClick(port) {
|
|
|
dom.loadingImg.style.transform = 'rotate(0deg)'
|
|
|
dom.deBtn.innerHTML = '<span>DeNet<span>';
|
|
|
}, 3000)
|
|
|
- port.postMessage({ state: 'CONTENT_TWITTER_LOGIN' })
|
|
|
+
|
|
|
+ chrome.runtime.sendMessage({ actionType: "CONTENT_TWITTER_LOGIN", data: '1' }, (res) => { console.log(res) })
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -314,7 +316,7 @@ function _setPublishContent(content) {
|
|
|
* @returns {{deBtn2: HTMLDivElement, deBtn1: HTMLDivElement, deBtn: HTMLSpanElement}}
|
|
|
* @private
|
|
|
*/
|
|
|
-function _createBtnDom(port) {
|
|
|
+function _createBtnDom() {
|
|
|
let loadingImg = document.createElement('img');
|
|
|
loadingImg.id = 'de-btn-loading'
|
|
|
loadingImg.src = require("@/assets/img/icon-btn-loading.png");
|
|
@@ -365,7 +367,7 @@ function _createBtnDom(port) {
|
|
|
businessType: Report.businessType.buttonClick,
|
|
|
objectType: Report.objectType.buttonMain
|
|
|
});
|
|
|
- _deNetBtnClick(port);
|
|
|
+ _deNetBtnClick();
|
|
|
})
|
|
|
deBtn1.addEventListener('click', () => {
|
|
|
Report.reportLog({
|
|
@@ -373,10 +375,10 @@ function _createBtnDom(port) {
|
|
|
businessType: Report.businessType.buttonClick,
|
|
|
objectType: Report.objectType.buttonSecond
|
|
|
});
|
|
|
- _deNetBtnClick(port);
|
|
|
+ _deNetBtnClick();
|
|
|
})
|
|
|
deBtn2.addEventListener('click', () => {
|
|
|
- _deNetBtnClick(port);
|
|
|
+ _deNetBtnClick();
|
|
|
})
|
|
|
deBtn3.addEventListener('click', () => {
|
|
|
Report.reportLog({
|
|
@@ -384,7 +386,7 @@ function _createBtnDom(port) {
|
|
|
businessType: Report.businessType.buttonClick,
|
|
|
objectType: Report.objectType.buttonMain
|
|
|
});
|
|
|
- _deNetBtnClick(port);
|
|
|
+ _deNetBtnClick();
|
|
|
})
|
|
|
dom.deBtn = deBtn;
|
|
|
dom.deBtn1 = deBtn1;
|
|
@@ -457,31 +459,32 @@ function checkHasDeBtn() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据postID绑定推文id
|
|
|
+ * 点击发推,后端绑定推特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) {
|
|
|
- Report.reportLog({
|
|
|
- objectType: Report.objectType.tweetPostBinded
|
|
|
- });
|
|
|
- bindTwitterArt.needBind = false;
|
|
|
- bindTwitterArt.postId = '';
|
|
|
- bindTwitterArt.isBindIng = false;
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+function bindTwitterArtMethod() {
|
|
|
+ if (!bindTwitterArt.postId) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (bindTwitterArt.needBind && !bindTwitterArt.isBindIng) {
|
|
|
+ bindTwitterArt.isBindIng = true;
|
|
|
+ reportSrcPublishEvent({
|
|
|
+ params: {
|
|
|
+ postId: bindTwitterArt.postId,
|
|
|
+ }
|
|
|
+ }).then((res) => {
|
|
|
+ if (res.code == 0) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.tweetPostBinded
|
|
|
+ });
|
|
|
+ bindTwitterArt.needBind = false;
|
|
|
+ bindTwitterArt.postId = '';
|
|
|
+ bindTwitterArt.isBindIng = false;
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
import parseCard from './ParseCard'
|
|
|
|
|
|
// 检测dom改变
|
|
@@ -495,95 +498,103 @@ import parseCard from './ParseCard'
|
|
|
|
|
|
|
|
|
|
|
|
-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')) {
|
|
|
- change_num++
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
+let queue_num = 1
|
|
|
|
|
|
+export const changeQueueNum = (num = 0) => {
|
|
|
+ queue_num = queue_num + num
|
|
|
+ if (queue_num > 5) {
|
|
|
+ queue_num = 5
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+let main_observer = null
|
|
|
+function onChangePageMain(targetNode) {
|
|
|
+ try {
|
|
|
+ const config = { attributes: false, childList: true, subtree: true };
|
|
|
+ const callback = (mutationsList, observer) => {
|
|
|
+ console.log('watch',mutationsList)
|
|
|
+ changeQueueNum(1)
|
|
|
+ }
|
|
|
+ main_observer = new MutationObserver(callback);
|
|
|
+ main_observer.observe(targetNode, config);
|
|
|
+ } catch (error) {
|
|
|
+ main_observer = null
|
|
|
}
|
|
|
- const observer = new MutationObserver(callback);
|
|
|
- observer.observe(targetNode, config);
|
|
|
}
|
|
|
|
|
|
// 1.监听main改变
|
|
|
// 2.监听卡片是否可见
|
|
|
// 3.如果可见了 去找
|
|
|
|
|
|
-function setIframeRedPacket(port) {
|
|
|
- // let elment = document.documentElement
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // let new_time = new Date().getTime()
|
|
|
- // console.log('new_time',new_time)
|
|
|
- // if (new_time - change_time < 1000) {
|
|
|
- // return
|
|
|
- // }
|
|
|
-
|
|
|
- // change_time = new_time
|
|
|
+function setIframeRedPacket() {
|
|
|
// 获取所有卡片参数
|
|
|
let card_json_data = parseCard.parseAllDeNetCardParmas()
|
|
|
// 过滤出可以请求的短链接
|
|
|
parseCard.getCardParmas(card_json_data).then((res) => {
|
|
|
- // debugger
|
|
|
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 })
|
|
|
+ chrome.runtime.sendMessage({ actionType: "CONTENT_TWITTER_SHORT_LINK", data: "", arr_url: res.need_net_short_url }, () => { })
|
|
|
}
|
|
|
- // card_json_data.length == res.has_post_Id_card_data.length ||
|
|
|
})
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+// 监听点击发推 按钮绑定事件
|
|
|
+document.addEventListener('click', (e) => {
|
|
|
+ try {
|
|
|
+ if (e.target.dataset && e.target.dataset.testid && e.target.dataset.testid == 'tweetButton') {
|
|
|
+ bindTwitterArtMethod()
|
|
|
+ } else if (e.target.closest('div[data-testid=tweetButton]')) {
|
|
|
+ bindTwitterArtMethod()
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('error', error)
|
|
|
+ }
|
|
|
+})
|
|
|
|
|
|
|
|
|
-export function initExecuteScript(port, changes) {
|
|
|
+export function initExecuteScript(changes) {
|
|
|
if (changes.executeScript) {
|
|
|
let item = JSON.parse(changes.executeScript.newValue)
|
|
|
if (item.executeScript) {
|
|
|
- init(port)
|
|
|
+ init()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-export function addChangeNum() {
|
|
|
- change_num++
|
|
|
-}
|
|
|
// 初始化
|
|
|
-export function init(port) {
|
|
|
+export function init() {
|
|
|
if (window.location.href.indexOf('twitter.com') < 0) {
|
|
|
return
|
|
|
}
|
|
|
- twitterPinLogin(port);
|
|
|
- renderDom(port);
|
|
|
+ twitterPinLogin();
|
|
|
+ // 渲染dom
|
|
|
let targetNode = null
|
|
|
let timer = setInterval(() => {
|
|
|
targetNode = document.querySelector('main')
|
|
|
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) {
|
|
|
+ if (!main_observer) {
|
|
|
+ onChangePageMain(targetNode)
|
|
|
+ changeQueueNum(1)
|
|
|
+ }
|
|
|
+ console.log('main_observer', main_observer)
|
|
|
+ console.log('queue_num', queue_num)
|
|
|
+ if (queue_num <= 0) {
|
|
|
return
|
|
|
}
|
|
|
- change_num = change_num - 1
|
|
|
- setIframeRedPacket(port)
|
|
|
+ setIframeRedPacket()
|
|
|
+ changeQueueNum(-1)
|
|
|
}, 1000)
|
|
|
}
|
|
|
}, 1000);
|
|
|
+ renderDom();
|
|
|
+
|
|
|
|
|
|
getChromeStorage("popupShowPublishDialog", (res) => {
|
|
|
console.log("popupShowPublishDialog", res);
|