|
@@ -9,16 +9,24 @@ let consumerKey = ''
|
|
let tab_flag = true
|
|
let tab_flag = true
|
|
|
|
|
|
const isHasTabByUrl = (url, callback) => {
|
|
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() {
|
|
export function twitterPinLoginToken() {
|
|
@@ -209,43 +217,59 @@ export function twitterShortUrl(sender, url) {
|
|
|
|
|
|
// 安装插件后获取mid
|
|
// 安装插件后获取mid
|
|
export function onInstalledMid() {
|
|
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() {
|
|
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({
|
|
chrome.scripting.executeScript({
|
|
target: { tabId: tab[i].id },
|
|
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
|
|
|
|
+ })
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -377,7 +401,7 @@ export function onInstalledCreateTab() {
|
|
objectType: Report.objectType.background_function_catch,
|
|
objectType: Report.objectType.background_function_catch,
|
|
funcName: 'onInstalledCreateTab',
|
|
funcName: 'onInstalledCreateTab',
|
|
errMsg: error.message
|
|
errMsg: error.message
|
|
- });
|
|
|
|
|
|
+ })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|