|
@@ -9,52 +9,66 @@ let consumerKey = ''
|
|
|
let tab_flag = true
|
|
|
|
|
|
const isHasTabByUrl = (url, callback) => {
|
|
|
- let item
|
|
|
- chrome.tabs.query({}, (tab) => {
|
|
|
- for (let i in tab) {
|
|
|
- if (tab[i].url.indexOf(url) >= 0) {
|
|
|
- item = tab[i]
|
|
|
- break
|
|
|
+ try {
|
|
|
+ let item
|
|
|
+ chrome.tabs.query({}, (tab) => {
|
|
|
+ for (let i in tab) {
|
|
|
+ if (tab[i].url.indexOf(url) >= 0) {
|
|
|
+ item = tab[i]
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- callback(item)
|
|
|
- })
|
|
|
+ callback(item)
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'isHasTabByUrl',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export function twitterPinLoginToken() {
|
|
|
- // 1.判断是否登陆了
|
|
|
- getChromeStorage('userInfo', (res) => {
|
|
|
- // 没有登陆
|
|
|
- if (!res) {
|
|
|
- if (tab_flag == false) {
|
|
|
- return
|
|
|
- }
|
|
|
- tab_flag = false
|
|
|
- fetchTtwitterRequestToken().then((res) => {
|
|
|
- tab_flag = true
|
|
|
- if (res.code == 0) {
|
|
|
- authToken = res.data.authToken
|
|
|
- consumerKey = res.data.consumerKey
|
|
|
- isHasTabByUrl('https://api.twitter.com/oauth/authorize?oauth_token', (tab) => {
|
|
|
- if (!tab) {
|
|
|
- chrome.tabs.create({
|
|
|
- url: `https://api.twitter.com/oauth/authorize?oauth_token=${res.data.authToken}`
|
|
|
- })
|
|
|
- } else {
|
|
|
- chrome.tabs.highlight({ windowId: tab.windowId, tabs: tab.index })
|
|
|
- }
|
|
|
- })
|
|
|
+ try {
|
|
|
+ // 1.判断是否登陆了
|
|
|
+ getChromeStorage('userInfo', (res) => {
|
|
|
+ // 没有登陆
|
|
|
+ if (!res) {
|
|
|
+ if (tab_flag == false) {
|
|
|
+ return
|
|
|
}
|
|
|
- }).catch(() => {
|
|
|
- tab_flag = true
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
+ tab_flag = false
|
|
|
+ fetchTtwitterRequestToken().then((res) => {
|
|
|
+ tab_flag = true
|
|
|
+ if (res.code == 0) {
|
|
|
+ authToken = res.data.authToken
|
|
|
+ consumerKey = res.data.consumerKey
|
|
|
+ isHasTabByUrl('https://api.twitter.com/oauth/authorize?oauth_token', (tab) => {
|
|
|
+ if (!tab) {
|
|
|
+ chrome.tabs.create({
|
|
|
+ url: `https://api.twitter.com/oauth/authorize?oauth_token=${res.data.authToken}`
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ chrome.tabs.highlight({ windowId: tab.windowId, tabs: tab.index })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }).catch(() => {
|
|
|
+ tab_flag = true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'twitterPinLoginToken',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export function twitterPinLoginCode(sender, code) {
|
|
|
- // actionType:{}
|
|
|
-
|
|
|
// port.postMessage({
|
|
|
// state: "BACK_TWITTER_LOGIN_SUCCESS",
|
|
|
// });
|
|
@@ -67,39 +81,45 @@ export function twitterPinLoginCode(sender, code) {
|
|
|
// }
|
|
|
// }
|
|
|
// })
|
|
|
- chrome.tabs.sendMessage(sender.tab.id, { actionType: 'BACK_TWITTER_LOGIN_SUCCESS' }, (res) => { console.log(res) });
|
|
|
- chrome.tabs.remove(sender.tab.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)
|
|
|
+ try {
|
|
|
+ chrome.tabs.sendMessage(sender.tab.id, { actionType: 'BACK_TWITTER_LOGIN_SUCCESS' }, (res) => { console.log(res) });
|
|
|
+ chrome.tabs.remove(sender.tab.id)
|
|
|
+ chrome.cookies.getAll(LANDING_PAGE, (e = []) => {
|
|
|
+ let _str = '[]'
|
|
|
+ if (e.length > 0) {
|
|
|
+ _str = e[0].value
|
|
|
}
|
|
|
- }
|
|
|
- // 发送请求
|
|
|
- // token,code
|
|
|
- fetchTwitterLogin(authToken, consumerKey, code, receivedIds).then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- setChromeStorage({ userInfo: JSON.stringify(res.data) })
|
|
|
- setChromeCookie(WEBSITE_USER_INFO, res.data)
|
|
|
+ let _arr = JSON.parse(decodeURIComponent(_str))
|
|
|
+ let receivedIds = []
|
|
|
+ if (_arr.length > 0) {
|
|
|
+ for (let i in _arr) {
|
|
|
+ receivedIds.push(_arr[i].receivedId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 发送请求
|
|
|
+ // token,code
|
|
|
+ fetchTwitterLogin(authToken, consumerKey, code, receivedIds).then(res => {
|
|
|
+ if (res.code == 0) {
|
|
|
+ setChromeStorage({ userInfo: JSON.stringify(res.data) })
|
|
|
+ setChromeCookie(WEBSITE_USER_INFO, res.data)
|
|
|
|
|
|
- sendActivetabMessage({
|
|
|
- actionType: 'BG_LOGIN_SET_USERINFO_CB'
|
|
|
- });
|
|
|
+ sendActivetabMessage({
|
|
|
+ actionType: 'BG_LOGIN_SET_USERINFO_CB'
|
|
|
+ });
|
|
|
|
|
|
- // 获取全局消息数据
|
|
|
- setMessageCount()
|
|
|
- chrome.cookies.remove(LANDING_PAGE)
|
|
|
- }
|
|
|
+ // 获取全局消息数据
|
|
|
+ setMessageCount()
|
|
|
+ chrome.cookies.remove(LANDING_PAGE)
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'twitterPinLoginCode',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
let discordAuthWindowId = '';
|
|
@@ -109,23 +129,31 @@ export function saveDiscordAuthWindowId(params) {
|
|
|
}
|
|
|
|
|
|
export function discordLoginCode({ code }, sender) {
|
|
|
- console.log('sender', sender)
|
|
|
- let { windowId, id } = sender.tab || {};
|
|
|
- chrome.tabs.remove(id);
|
|
|
-
|
|
|
- // 发送请求
|
|
|
- getDiscordUserInfo({
|
|
|
- authCode: code,
|
|
|
- redirectUrl: discordAuthRedirectUri
|
|
|
- }).then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- setTimeout(() => {
|
|
|
- sendActivetabMessage({
|
|
|
- actionType: 'BACK_DISCORD_LOGIN_SUCCESS'
|
|
|
- });
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
+ try {
|
|
|
+ console.log('sender', sender)
|
|
|
+ let { windowId, id } = sender.tab || {};
|
|
|
+ chrome.tabs.remove(id);
|
|
|
+
|
|
|
+ // 发送请求
|
|
|
+ getDiscordUserInfo({
|
|
|
+ authCode: code,
|
|
|
+ redirectUrl: discordAuthRedirectUri
|
|
|
+ }).then(res => {
|
|
|
+ if (res.code == 0) {
|
|
|
+ setTimeout(() => {
|
|
|
+ sendActivetabMessage({
|
|
|
+ actionType: 'BACK_DISCORD_LOGIN_SUCCESS'
|
|
|
+ });
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'discordLoginCode',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
// if(windowId) {
|
|
|
// chrome.windows.remove(
|
|
@@ -138,86 +166,110 @@ export function discordLoginCode({ code }, sender) {
|
|
|
}
|
|
|
|
|
|
export function twitterShortUrl(sender, url) {
|
|
|
- fetchTwitterShortUrl(url).then(res => {
|
|
|
- let str_arr = res.match(/denetme.net\/([\s\S]*?)"/) || []
|
|
|
- let post_Id = str_arr[1] || ''
|
|
|
- if (!post_Id) {
|
|
|
- return
|
|
|
- }
|
|
|
- // 解析
|
|
|
- let _obj = {
|
|
|
- short_url: url,
|
|
|
- post_Id
|
|
|
- }
|
|
|
- getChromeStorage('cardData', item => {
|
|
|
- if (item) {
|
|
|
- let has = false
|
|
|
- for (let i in item) {
|
|
|
- if (item[i].short_url == _obj.short_url) {
|
|
|
- item[i].short_url = _obj.short_url
|
|
|
- item[i].post_Id = _obj.post_Id
|
|
|
+ try {
|
|
|
+ fetchTwitterShortUrl(url).then(res => {
|
|
|
+ let str_arr = res.match(/denetme.net\/([\s\S]*?)"/) || []
|
|
|
+ let post_Id = str_arr[1] || ''
|
|
|
+ if (!post_Id) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 解析
|
|
|
+ let _obj = {
|
|
|
+ short_url: url,
|
|
|
+ post_Id
|
|
|
+ }
|
|
|
+ getChromeStorage('cardData', item => {
|
|
|
+ if (item) {
|
|
|
+ let has = false
|
|
|
+ for (let i in item) {
|
|
|
+ if (item[i].short_url == _obj.short_url) {
|
|
|
+ item[i].short_url = _obj.short_url
|
|
|
+ item[i].post_Id = _obj.post_Id
|
|
|
+ setChromeStorage({ cardData: JSON.stringify(item) })
|
|
|
+ has = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!has) {
|
|
|
+ item.push(_obj)
|
|
|
setChromeStorage({ cardData: JSON.stringify(item) })
|
|
|
- has = true
|
|
|
- break
|
|
|
}
|
|
|
- }
|
|
|
- if (!has) {
|
|
|
- item.push(_obj)
|
|
|
- setChromeStorage({ cardData: JSON.stringify(item) })
|
|
|
- }
|
|
|
|
|
|
- } else {
|
|
|
- setChromeStorage({ cardData: JSON.stringify([_obj]) })
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ setChromeStorage({ cardData: JSON.stringify([_obj]) })
|
|
|
+ }
|
|
|
|
|
|
- chrome.tabs.sendMessage(sender.tab.id, { actionType: 'BACK_TWITTER_SHORT_URL' }, (response) => { });
|
|
|
- // port.postMessage({
|
|
|
- // state: "BACK_TWITTER_SHORT_URL"
|
|
|
- // });
|
|
|
+ chrome.tabs.sendMessage(sender.tab.id, { actionType: 'BACK_TWITTER_SHORT_URL' }, (response) => { });
|
|
|
+ // port.postMessage({
|
|
|
+ // state: "BACK_TWITTER_SHORT_URL"
|
|
|
+ // });
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'twitterShortUrl',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
// 安装插件后获取mid
|
|
|
export function onInstalledMid() {
|
|
|
- getChromeCookie(LANDING_PAGE_MID, (res_arr) => {
|
|
|
- // 没有cookie
|
|
|
- if (res_arr && res_arr.length) {
|
|
|
- setChromeStorage({ mid: JSON.stringify(res_arr[0]) })
|
|
|
- } else {
|
|
|
- let _params = {
|
|
|
- mid: guid()
|
|
|
+ try {
|
|
|
+ getChromeCookie(LANDING_PAGE_MID, (res_arr) => {
|
|
|
+ // 没有cookie
|
|
|
+ if (res_arr && res_arr.length) {
|
|
|
+ setChromeStorage({ mid: JSON.stringify(res_arr[0]) })
|
|
|
+ } else {
|
|
|
+ let _params = {
|
|
|
+ mid: guid()
|
|
|
+ }
|
|
|
+ setChromeCookie(LANDING_PAGE, { 'mid': _params.mid })
|
|
|
+ setChromeStorage({ mid: JSON.stringify(_params) })
|
|
|
}
|
|
|
- setChromeCookie(LANDING_PAGE, { 'mid': _params.mid })
|
|
|
- setChromeStorage({ mid: JSON.stringify(_params) })
|
|
|
- }
|
|
|
- })
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'onInstalledMid',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export function onInstalledUserSet() {
|
|
|
- chrome.action.getUserSettings().then(res => {
|
|
|
- setChromeStorage({ userSettings: JSON.stringify({ res }) })
|
|
|
- // 无刷新插入js
|
|
|
- chrome.tabs.query({}, (tab) => {
|
|
|
- for (let i in tab) {
|
|
|
- chrome.scripting.executeScript({
|
|
|
- target: { tabId: tab[i].id },
|
|
|
- files: ['js/content_help.js']
|
|
|
- }, () => { })
|
|
|
- if (tab[i].url.indexOf('twitter.com') >= 0 || tab[i].url.indexOf('facebook.com') >= 0) {
|
|
|
+ try {
|
|
|
+ chrome.action.getUserSettings().then(res => {
|
|
|
+ setChromeStorage({ userSettings: JSON.stringify({ res }) })
|
|
|
+ // 无刷新插入js
|
|
|
+ chrome.tabs.query({}, (tab) => {
|
|
|
+ for (let i in tab) {
|
|
|
chrome.scripting.executeScript({
|
|
|
target: { tabId: tab[i].id },
|
|
|
- files: ['js/content.js'],
|
|
|
- }, () => {
|
|
|
- setTimeout(() => {
|
|
|
- setChromeStorage({ executeScript: JSON.stringify({ executeScript: 1 }) })
|
|
|
- }, 2000);
|
|
|
- })
|
|
|
+ files: ['js/content_help.js']
|
|
|
+ }, () => { })
|
|
|
+ if (tab[i].url.indexOf('twitter.com') >= 0 || tab[i].url.indexOf('facebook.com') >= 0) {
|
|
|
+ chrome.scripting.executeScript({
|
|
|
+ target: { tabId: tab[i].id },
|
|
|
+ files: ['js/content.js'],
|
|
|
+ }, () => {
|
|
|
+ setTimeout(() => {
|
|
|
+ setChromeStorage({ executeScript: JSON.stringify({ executeScript: 1 }) })
|
|
|
+ }, 2000);
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'onInstalledUserSet',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -235,14 +287,22 @@ export function checkPined() {
|
|
|
}
|
|
|
|
|
|
function sendActivetabMessage(message = {}) {
|
|
|
- chrome.tabs.query({
|
|
|
- active: true,
|
|
|
- currentWindow: true
|
|
|
- }, (tabs) => {
|
|
|
- chrome.tabs.sendMessage(tabs[0].id, message, res => {
|
|
|
- console.log(res)
|
|
|
+ try {
|
|
|
+ chrome.tabs.query({
|
|
|
+ active: true,
|
|
|
+ currentWindow: true
|
|
|
+ }, (tabs) => {
|
|
|
+ chrome.tabs.sendMessage(tabs[0].id, message, res => {
|
|
|
+ console.log(res)
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'sendActivetabMessage',
|
|
|
+ errMsg: error.message
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -251,94 +311,106 @@ function sendActivetabMessage(message = {}) {
|
|
|
*/
|
|
|
|
|
|
export function onInstalledCreateTab() {
|
|
|
- getChromeCookie(LANDING_PAGE_JUMP_INFO, (res = {}) => {
|
|
|
- setTimeout(() => {
|
|
|
- // 安装成功埋点
|
|
|
- Report.reportLog({
|
|
|
- objectType: Report.objectType.chrome_extension_installed,
|
|
|
- funcName: 'onInstalledCreateTab',
|
|
|
- postId: res?.postId || ''
|
|
|
- })
|
|
|
- }, 5000)
|
|
|
- let url = 'https://twitter.com/search?q=%23denet'
|
|
|
- // jump_info
|
|
|
- if (!res || !res.jump_type) {
|
|
|
- chrome.tabs.create({
|
|
|
- url
|
|
|
- });
|
|
|
- return
|
|
|
- }
|
|
|
- let created_detail = false
|
|
|
- switch (String(res.jump_type)) {
|
|
|
- // 普通红包
|
|
|
- case 'red_packet':
|
|
|
- if (res && res.postNickName && res.srcContentId) {
|
|
|
- created_detail = true
|
|
|
- url = `https://twitter.com/${res.postNickName}/status/${res.srcContentId}`
|
|
|
- chrome.tabs.create({
|
|
|
- url
|
|
|
- });
|
|
|
- }
|
|
|
- break
|
|
|
- // 抽奖红包
|
|
|
- case 'luck_draw':
|
|
|
- if (res && res.postNickName && res.srcContentId) {
|
|
|
- created_detail = true
|
|
|
- url = `https://twitter.com/${res.postNickName}/status/${res.srcContentId}`
|
|
|
- chrome.tabs.create({
|
|
|
- url
|
|
|
- });
|
|
|
- }
|
|
|
- break
|
|
|
- // NFT
|
|
|
- case 'nft_info':
|
|
|
- if (res && res.twitterAccount && res.nftProjectId) {
|
|
|
- created_detail = true
|
|
|
- url = `https://twitter.com/${res.twitterAccount}`
|
|
|
- chrome.tabs.create({
|
|
|
- url
|
|
|
- });
|
|
|
+ try {
|
|
|
+ getChromeCookie(LANDING_PAGE_JUMP_INFO, (res = {}) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ if (!res) {
|
|
|
+ res = {}
|
|
|
}
|
|
|
- break
|
|
|
- // NFT 组
|
|
|
- case 'nft_group_info':
|
|
|
- if (res && res.twitterAccount) {
|
|
|
- created_detail = true
|
|
|
- // setChromeStorage({ groupTabData: JSON.stringify({
|
|
|
- // deTabVal: 'deGroupTab'
|
|
|
- // })})
|
|
|
- chrome.storage.local.set({
|
|
|
- groupTabData: JSON.stringify({
|
|
|
- deTabVal: 'deGroupTab'
|
|
|
- })
|
|
|
- }, (response) => {
|
|
|
+ // 安装成功埋点
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.chrome_extension_installed,
|
|
|
+ funcName: 'onInstalledCreateTab',
|
|
|
+ postId: res.postId || ''
|
|
|
+ })
|
|
|
+ }, 5000)
|
|
|
+ let url = 'https://twitter.com/search?q=%23denet'
|
|
|
+ // jump_info
|
|
|
+ if (!res || !res.jump_type) {
|
|
|
+ chrome.tabs.create({
|
|
|
+ url
|
|
|
+ });
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let created_detail = false
|
|
|
+ switch (String(res.jump_type)) {
|
|
|
+ // 普通红包
|
|
|
+ case 'red_packet':
|
|
|
+ if (res && res.postNickName && res.srcContentId) {
|
|
|
+ created_detail = true
|
|
|
+ url = `https://twitter.com/${res.postNickName}/status/${res.srcContentId}`
|
|
|
+ chrome.tabs.create({
|
|
|
+ url
|
|
|
+ });
|
|
|
+ }
|
|
|
+ break
|
|
|
+ // 抽奖红包
|
|
|
+ case 'luck_draw':
|
|
|
+ if (res && res.postNickName && res.srcContentId) {
|
|
|
+ created_detail = true
|
|
|
+ url = `https://twitter.com/${res.postNickName}/status/${res.srcContentId}`
|
|
|
+ chrome.tabs.create({
|
|
|
+ url
|
|
|
+ });
|
|
|
+ }
|
|
|
+ break
|
|
|
+ // NFT
|
|
|
+ case 'nft_info':
|
|
|
+ if (res && res.twitterAccount && res.nftProjectId) {
|
|
|
+ created_detail = true
|
|
|
url = `https://twitter.com/${res.twitterAccount}`
|
|
|
chrome.tabs.create({
|
|
|
url
|
|
|
});
|
|
|
- })
|
|
|
- }
|
|
|
- break
|
|
|
- // toolbox
|
|
|
- case 'tool_box':
|
|
|
- if (res && res.postNickName && res.srcContentId) {
|
|
|
- created_detail = true
|
|
|
- url = `https://twitter.com/${res.postNickName}/status/${res.srcContentId}`
|
|
|
- chrome.tabs.create({
|
|
|
- url
|
|
|
- });
|
|
|
- }
|
|
|
- break
|
|
|
- }
|
|
|
+ }
|
|
|
+ break
|
|
|
+ // NFT 组
|
|
|
+ case 'nft_group_info':
|
|
|
+ if (res && res.twitterAccount) {
|
|
|
+ created_detail = true
|
|
|
+ // setChromeStorage({ groupTabData: JSON.stringify({
|
|
|
+ // deTabVal: 'deGroupTab'
|
|
|
+ // })})
|
|
|
+ chrome.storage.local.set({
|
|
|
+ groupTabData: JSON.stringify({
|
|
|
+ deTabVal: 'deGroupTab'
|
|
|
+ })
|
|
|
+ }, (response) => {
|
|
|
+ url = `https://twitter.com/${res.twitterAccount}`
|
|
|
+ chrome.tabs.create({
|
|
|
+ url
|
|
|
+ });
|
|
|
+ })
|
|
|
+ }
|
|
|
+ break
|
|
|
+ // toolbox
|
|
|
+ case 'tool_box':
|
|
|
+ if (res && res.postNickName && res.srcContentId) {
|
|
|
+ created_detail = true
|
|
|
+ url = `https://twitter.com/${res.postNickName}/status/${res.srcContentId}`
|
|
|
+ chrome.tabs.create({
|
|
|
+ url
|
|
|
+ });
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
|
|
|
- if (created_detail == false) {
|
|
|
- chrome.tabs.create({
|
|
|
- url
|
|
|
- });
|
|
|
- }
|
|
|
+ if (created_detail == false) {
|
|
|
+ chrome.tabs.create({
|
|
|
+ url
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- removeChromeCookie(LANDING_PAGE_JUMP_INFO)
|
|
|
- })
|
|
|
+ removeChromeCookie(LANDING_PAGE_JUMP_INFO)
|
|
|
+
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'onInstalledCreateTab',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -377,100 +449,144 @@ export async function setMessageCount() {
|
|
|
}
|
|
|
|
|
|
function createAlarm() {
|
|
|
- let alarmInfo = {
|
|
|
- //1分鐘之後開始(該值不能小於1)
|
|
|
- delayInMinutes: 1,
|
|
|
- //與上方等同的寫法是
|
|
|
- // when : Date.now() + n,
|
|
|
- //開始後每一分鐘執行一次(該值不能小于1)
|
|
|
- periodInMinutes: 1
|
|
|
- };
|
|
|
-
|
|
|
- //每次加載就清空定時器
|
|
|
- chrome.alarms.clear('denetChromeAlarm');
|
|
|
- //創造定時器
|
|
|
- chrome.alarms.create('denetChromeAlarm', alarmInfo);
|
|
|
+ try {
|
|
|
+ let alarmInfo = {
|
|
|
+ //1分鐘之後開始(該值不能小於1)
|
|
|
+ delayInMinutes: 1,
|
|
|
+ //與上方等同的寫法是
|
|
|
+ // when : Date.now() + n,
|
|
|
+ //開始後每一分鐘執行一次(該值不能小于1)
|
|
|
+ periodInMinutes: 1
|
|
|
+ };
|
|
|
+
|
|
|
+ //每次加載就清空定時器
|
|
|
+ chrome.alarms.clear('denetChromeAlarm');
|
|
|
+ //創造定時器
|
|
|
+ chrome.alarms.create('denetChromeAlarm', alarmInfo);
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'createAlarm',
|
|
|
+ errMsg: error.message
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export function getMessageInfo() {
|
|
|
- fetchAllMessageInfo().then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- let { unReadCountTotal = 0 } = res.data;
|
|
|
- if (unReadCountTotal > 0) {
|
|
|
- let text = unReadCountTotal > 99 ? '99+' : unReadCountTotal + '';
|
|
|
- setBadgeInfo({ data: { text } });
|
|
|
- } else {
|
|
|
- hideBadge();
|
|
|
+ try {
|
|
|
+ fetchAllMessageInfo().then(res => {
|
|
|
+ if (res.code == 0) {
|
|
|
+ let { unReadCountTotal = 0 } = res.data;
|
|
|
+ if (unReadCountTotal > 0) {
|
|
|
+ let text = unReadCountTotal > 99 ? '99+' : unReadCountTotal + '';
|
|
|
+ setBadgeInfo({ data: { text } });
|
|
|
+ } else {
|
|
|
+ hideBadge();
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- })
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'getMessageInfo',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export function readTaskAllMsg({ msgType }, cb) {
|
|
|
- fetchReadTaskAllMsg({
|
|
|
- msgType // 1:任务红包 2:钱包明细
|
|
|
- }).then(res => {
|
|
|
- if (res.code == 0) {
|
|
|
- cb && cb();
|
|
|
- }
|
|
|
- });
|
|
|
+ try {
|
|
|
+ fetchReadTaskAllMsg({
|
|
|
+ msgType // 1:任务红包 2:钱包明细
|
|
|
+ }).then(res => {
|
|
|
+ if (res.code == 0) {
|
|
|
+ cb && cb();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'readTaskAllMsg',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export const onDisconnectHandler = (port) => {
|
|
|
- if (port.name === "popup" || port.name === "popup_transactions") {
|
|
|
- let msgType = port.name === "popup" ? 1 : 2;
|
|
|
- readTaskAllMsg({ msgType }, () => {
|
|
|
- getMessageInfo();
|
|
|
+ try {
|
|
|
+ if (port.name === "popup" || port.name === "popup_transactions") {
|
|
|
+ let msgType = port.name === "popup" ? 1 : 2;
|
|
|
+ readTaskAllMsg({ msgType }, () => {
|
|
|
+ getMessageInfo();
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'onDisconnectHandler',
|
|
|
+ errMsg: error.message
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export const injectExtensionPopup = (tab) => {
|
|
|
- sendActivetabMessage({
|
|
|
- actionType: 'BG_INJECT_EXTENSION_POPUP'
|
|
|
- });
|
|
|
+ try {
|
|
|
+ sendActivetabMessage({
|
|
|
+ actionType: 'BG_INJECT_EXTENSION_POPUP'
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'injectExtensionPopup',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export const setPopupConfig = (activeInfo) => {
|
|
|
- chrome.tabs.query({
|
|
|
- active: true,
|
|
|
- currentWindow: true
|
|
|
- }, (tabs) => {
|
|
|
- if (tabs.length) {
|
|
|
- let { pendingUrl = '', url = '' } = tabs[0];
|
|
|
- if (pendingUrl.startsWith('https://twitter.com') || url.startsWith('https://twitter.com')) {
|
|
|
- sendActivetabMessage({
|
|
|
- actionType: 'BG_SET_POPUP_CONFIG'
|
|
|
- });
|
|
|
- } else {
|
|
|
- chrome.action.setPopup({
|
|
|
- popup: 'popup.html',
|
|
|
- }, function () {
|
|
|
- });
|
|
|
+ try {
|
|
|
+ chrome.tabs.query({
|
|
|
+ active: true,
|
|
|
+ currentWindow: true
|
|
|
+ }, (tabs) => {
|
|
|
+ if (tabs.length) {
|
|
|
+ let { pendingUrl = '', url = '' } = tabs[0];
|
|
|
+ if (pendingUrl.startsWith('https://twitter.com') || url.startsWith('https://twitter.com')) {
|
|
|
+ sendActivetabMessage({
|
|
|
+ actionType: 'BG_SET_POPUP_CONFIG'
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ chrome.action.setPopup({
|
|
|
+ popup: 'popup.html',
|
|
|
+ }, function () {
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- // if(pendingUrl.startsWith('chrome://') || url.startsWith('chrome://') || pendingUrl.startsWith('https://chrome.google.com') || url.startsWith('https://chrome.google.com')) {
|
|
|
- // chrome.action.setPopup({
|
|
|
- // popup: 'popup.html',
|
|
|
- // },function() {
|
|
|
- // });
|
|
|
- // } else {
|
|
|
- // chrome.action.setPopup({
|
|
|
- // popup: '',
|
|
|
- // },function() {
|
|
|
- // });
|
|
|
- // }
|
|
|
- }
|
|
|
- })
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'setPopupConfig',
|
|
|
+ errMsg: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export const getSysMessage = () => {
|
|
|
- // 请求通知接口
|
|
|
- fetchGetAllUnReadNotices({})
|
|
|
- .then((res) => {
|
|
|
- // 向选中的content发送消息
|
|
|
- setContentMessage({ actionType: 'BACK_UNREAD_MESSAGE', data: res })
|
|
|
+ try {
|
|
|
+ // 请求通知接口
|
|
|
+ fetchGetAllUnReadNotices({})
|
|
|
+ .then((res) => {
|
|
|
+ // 向选中的content发送消息
|
|
|
+ setContentMessage({ actionType: 'BACK_UNREAD_MESSAGE', data: res })
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'getSysMessage',
|
|
|
+ errMsg: error.message
|
|
|
})
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export const windwoLoadSetPopupPage = (data, sender) => {
|
|
@@ -489,22 +605,30 @@ export const windwoLoadSetPopupPage = (data, sender) => {
|
|
|
}
|
|
|
|
|
|
export const setActionPopup = (data) => {
|
|
|
- let { popup } = data.data || {};
|
|
|
- if (popup) {
|
|
|
- chrome.action.getPopup(
|
|
|
- {},
|
|
|
- function (result) {
|
|
|
- if (!result) {
|
|
|
- chrome.action.setPopup({
|
|
|
- popup,
|
|
|
- }, function () {
|
|
|
- });
|
|
|
- }
|
|
|
+ try {
|
|
|
+ let { popup } = data.data || {};
|
|
|
+ if (popup) {
|
|
|
+ chrome.action.getPopup(
|
|
|
+ {},
|
|
|
+ function (result) {
|
|
|
+ if (!result) {
|
|
|
+ chrome.action.setPopup({
|
|
|
+ popup,
|
|
|
+ }, function () {
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ chrome.action.setPopup({
|
|
|
+ popup: '',
|
|
|
+ }, function () {
|
|
|
});
|
|
|
- } else {
|
|
|
- chrome.action.setPopup({
|
|
|
- popup: '',
|
|
|
- }, function () {
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'setActionPopup',
|
|
|
+ errMsg: error.message
|
|
|
});
|
|
|
}
|
|
|
}
|