|
@@ -1,6 +1,7 @@
|
|
|
import { pageUrl } from "@/http/configAPI.js"
|
|
|
import { exp } from "mathjs"
|
|
|
import { guid } from "@/uilts/help";
|
|
|
+import { consoleSandbox } from "_@sentry_utils@7.5.1@@sentry/utils";
|
|
|
export const LANDING_PAGE = {
|
|
|
name: 'received_log',
|
|
|
url: pageUrl
|
|
@@ -12,10 +13,14 @@ export const LANDING_PAGE_MID = {
|
|
|
}
|
|
|
|
|
|
export function setChromeStorage(params, callback) {
|
|
|
- if (callback) {
|
|
|
- chrome.storage.local.set(params, callback)
|
|
|
- } else {
|
|
|
- chrome.storage.local.set(params)
|
|
|
+ try {
|
|
|
+ if (callback) {
|
|
|
+ chrome.storage.local.set(params, callback)
|
|
|
+ } else {
|
|
|
+ chrome.storage.local.set(params)
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -44,6 +49,13 @@ export function getChromeStorage(key = '', callback) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+// export function chromeSendMessage() {
|
|
|
+// try {
|
|
|
+// // chrome.runtime.sendMessage
|
|
|
+// } catch {
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
export function setChromeCookie({
|
|
|
name,
|
|
|
url
|
|
@@ -56,53 +68,22 @@ export function setChromeCookie({
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-export function getChromeCookie({
|
|
|
- name,
|
|
|
- url
|
|
|
-}, callback) {
|
|
|
- chrome.cookies.getAll(
|
|
|
- {
|
|
|
- name: name || '',
|
|
|
- url: url || ''
|
|
|
- }, (e = []) => {
|
|
|
- let _str = '[]'
|
|
|
- if (e.length > 0) {
|
|
|
- _str = e[0].value
|
|
|
- }
|
|
|
- let _arr = JSON.parse(decodeURIComponent(_str)) || []
|
|
|
- callback(_arr)
|
|
|
- }
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-// 累加ChromeCookie
|
|
|
-export function concatChromeCookie({ name, url }, value_obj) {
|
|
|
- chrome.cookies.getAll(
|
|
|
- {
|
|
|
- name: name || '',
|
|
|
- url: url || ''
|
|
|
- }, (e = []) => {
|
|
|
- let _str = '[]'
|
|
|
- if (e.length > 0) {
|
|
|
- _str = e[0].value
|
|
|
+export function getChromeCookie({ name = '', url = '' }, callback) {
|
|
|
+ try {
|
|
|
+ chrome.cookies.getAll({ name, url }, (res = []) => {
|
|
|
+ let _str = ''
|
|
|
+ if (Array.isArray(res) && res.length) {
|
|
|
+ _str = res[0].value
|
|
|
}
|
|
|
- let _arr = JSON.parse(decodeURIComponent(_str)) || []
|
|
|
- _arr = _arr.concat(value_obj)
|
|
|
-
|
|
|
- // 删除cookies
|
|
|
- chrome.cookies.remove(LANDING_PAGE, () => {
|
|
|
- chrome.cookies.set({
|
|
|
- expirationDate: new Date().getTime() / 10,
|
|
|
- name: name,
|
|
|
- url: url,
|
|
|
- value: encodeURIComponent(JSON.stringify(_arr)) || ''
|
|
|
- }, (e) => {
|
|
|
- console.log(e)
|
|
|
- })
|
|
|
+ if (_str) {
|
|
|
+ callback(JSON.parse(decodeURIComponent(_str)))
|
|
|
+ } else {
|
|
|
+ callback(null)
|
|
|
}
|
|
|
- )
|
|
|
- }
|
|
|
- )
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ console.error('catch',error)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export function removeChromeCookie(params, cb) {
|