|
@@ -1,12 +1,12 @@
|
|
|
-import { getChromeStorage, setChromeStorage, LANDING_PAGE } from '@/uilts/chromeExtension.js'
|
|
|
+import { getChromeStorage, setChromeStorage } from '@/uilts/chromeExtension.js'
|
|
|
import { throttle } from '@/uilts/help'
|
|
|
-import { getTtwitterRequestToken, twitterLogin, httpTwitterShortUrl } from '../server/twitter.js'
|
|
|
import { srcPublishSuccess } from '@/http/publishApi'
|
|
|
import Report from "@/log-center/log"
|
|
|
|
|
|
+
|
|
|
let dom = {};
|
|
|
|
|
|
-export function contentTwitterPinLogin(port) {
|
|
|
+function twitterPinLogin(port) {
|
|
|
if (window.location.href == 'https://api.twitter.com/oauth/authorize') {
|
|
|
let code = document.querySelector('code')
|
|
|
|
|
@@ -16,100 +16,13 @@ export function contentTwitterPinLogin(port) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-let authToken = ''
|
|
|
-export function backTwitterPinLoginToken() {
|
|
|
- // 1.判断是否登陆了
|
|
|
- getChromeStorage('userInfo', (res) => {
|
|
|
- // 没有登陆
|
|
|
- if (!res) {
|
|
|
- getTtwitterRequestToken().then((res) => {
|
|
|
- authToken = res.data.authToken
|
|
|
- chrome.tabs.create({
|
|
|
- url: `https://api.twitter.com/oauth/authorize?oauth_token=${res.data.authToken}`
|
|
|
- })
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-export function backTwitterPinLoginCode(code) {
|
|
|
- // 关闭code页面
|
|
|
- chrome.tabs.query({}, (tab) => {
|
|
|
- for (let i in tab) {
|
|
|
- console.log(tab[i])
|
|
|
- if (tab[i].url == 'https://api.twitter.com/oauth/authorize') {
|
|
|
- chrome.tabs.remove(tab[i].id)
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- chrome.cookies.getAll(LANDING_PAGE, (e = []) => {
|
|
|
- let _str = '[]'
|
|
|
- if (e.length > 0) {
|
|
|
- _str = e[0].value
|
|
|
- }
|
|
|
- let _arr = JSON.parse(decodeURIComponent(_str))
|
|
|
- let receivedIds = []
|
|
|
- if (_arr.length > 0) {
|
|
|
- for (let i in _arr) {
|
|
|
- receivedIds.push(_arr[i].receivedId)
|
|
|
- }
|
|
|
- }
|
|
|
- // 发送请求
|
|
|
- // token,code
|
|
|
- twitterLogin(authToken, code, receivedIds).then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- setChromeStorage({ userInfo: JSON.stringify(res.data) })
|
|
|
- chrome.cookies.remove(LANDING_PAGE)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- )
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-export function backHttpTwitterShortUrl(url) {
|
|
|
- return new Promise(function (resolve, reject) {
|
|
|
- httpTwitterShortUrl(url).then(res => {
|
|
|
- let _str_arr = res.match(/denetme.net\/([\s\S]*?)"/) || []
|
|
|
- let _post_id = _str_arr[1] || ''
|
|
|
- console.log('_str_arr_post_id', _post_id)
|
|
|
- if (!_post_id) {
|
|
|
- return
|
|
|
- }
|
|
|
- // 解析
|
|
|
- let _obj = {
|
|
|
- url,
|
|
|
- post_id: _post_id
|
|
|
- // tweet_id
|
|
|
- }
|
|
|
- getChromeStorage('sortLink', item => {
|
|
|
- if (item) {
|
|
|
- for (let i in item) {
|
|
|
- if (item[i].url == _obj.url) {
|
|
|
- item[i] = _obj
|
|
|
- }
|
|
|
- // else{
|
|
|
- // delete item[i].tweet_id
|
|
|
- // }
|
|
|
- }
|
|
|
- setChromeStorage({ sortLink: JSON.stringify(item) })
|
|
|
- } else {
|
|
|
- setChromeStorage({ sortLink: JSON.stringify([_obj]) })
|
|
|
- }
|
|
|
- resolve({
|
|
|
- post_id: _post_id
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
|
|
|
-}
|
|
|
|
|
|
/**
|
|
|
* 渲染要插入的dom,初始化逻辑
|
|
|
* @param port
|
|
|
*/
|
|
|
-export function renderDom(port) {
|
|
|
+function renderDom(port) {
|
|
|
if (window.location.href.indexOf('https://twitter.com') > -1) {
|
|
|
_createBtnDom(port);
|
|
|
onWindowResize();
|
|
@@ -162,7 +75,7 @@ export function showPinTips() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-export function addPinedPop() {
|
|
|
+function addPinedPop() {
|
|
|
let domPop = document.getElementById('de-pin-pop');
|
|
|
|
|
|
if (domPop) {
|
|
@@ -787,7 +700,7 @@ function replaceDOMRedPacket(_type, _dom, postId, tweetId) {
|
|
|
// observer.observe(targetNode, config);
|
|
|
// }
|
|
|
|
|
|
-export function setIframeRedPacket(port) {
|
|
|
+function setIframeRedPacket(port) {
|
|
|
// let elment = document.documentElement
|
|
|
|
|
|
if (window.location.href.includes('twitter.com)')) {
|
|
@@ -807,3 +720,44 @@ export function setIframeRedPacket(port) {
|
|
|
// }
|
|
|
// }, 1000);
|
|
|
}
|
|
|
+
|
|
|
+export function initExecuteScript(changes) {
|
|
|
+ if (changes.executeScript) {
|
|
|
+ let item = JSON.parse(changes.executeScript.newValue)
|
|
|
+ if (item.executeScript) {
|
|
|
+ init()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+export function init(port) {
|
|
|
+ if (window.location.href.indexOf('twitter.com') < 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ twitterPinLogin(port);
|
|
|
+ renderDom(port);
|
|
|
+ setIframeRedPacket(port);
|
|
|
+
|
|
|
+ getChromeStorage("popupShowPublishDialog", (res) => {
|
|
|
+ console.log("popupShowPublishDialog", res);
|
|
|
+ if (res && res.show) {
|
|
|
+ setTimeout(() => {
|
|
|
+ showTwitterPublishDialogHandler({
|
|
|
+ srcContent: res.srcContent,
|
|
|
+ postId: res.postId
|
|
|
+ });
|
|
|
+ }, 1500);
|
|
|
+ chrome.storage.local.remove("popupShowPublishDialog");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ getChromeStorage("userSettings", (res) => {
|
|
|
+ addPinedPop();
|
|
|
+ if (res && !res.isOnToolbar) {
|
|
|
+ setTimeout(() => {
|
|
|
+ showPinTips();
|
|
|
+ chrome.storage.local.remove("userSettings");
|
|
|
+ }, 800);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|