mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-07-15 11:22:23 +08:00
refactor: services
This commit is contained in:
@@ -11,13 +11,13 @@ import {
|
||||
cropText,
|
||||
getClientPosition,
|
||||
getPossibleElementByQuerySelector,
|
||||
initSession,
|
||||
} from '../utils'
|
||||
import FloatingToolbar from '../components/FloatingToolbar'
|
||||
import Browser from 'webextension-polyfill'
|
||||
import { getPreferredLanguage } from '../config/language.mjs'
|
||||
import '../_locales/i18n-react'
|
||||
import { changeLanguage } from 'i18next'
|
||||
import { initSession } from '../services/init-session.mjs'
|
||||
|
||||
/**
|
||||
* @param {SiteConfig} siteConfig
|
||||
@@ -99,27 +99,6 @@ async function getInput(inputQuery) {
|
||||
}
|
||||
}
|
||||
|
||||
async function overwriteAccessToken() {
|
||||
if (location.hostname !== 'chat.openai.com') return
|
||||
|
||||
let data
|
||||
if (location.pathname === '/api/auth/session') {
|
||||
const response = document.querySelector('pre').textContent
|
||||
try {
|
||||
data = JSON.parse(response)
|
||||
} catch (error) {
|
||||
console.error('json error', error)
|
||||
}
|
||||
} else {
|
||||
const resp = await fetch('https://chat.openai.com/api/auth/session')
|
||||
data = await resp.json().catch(() => ({}))
|
||||
}
|
||||
if (data && data.accessToken) {
|
||||
await setAccessToken(data.accessToken)
|
||||
console.log(data.accessToken)
|
||||
}
|
||||
}
|
||||
|
||||
let toolbarContainer
|
||||
const deleteToolbar = () => {
|
||||
if (toolbarContainer && toolbarContainer.className === 'chatgptbox-toolbar-container')
|
||||
@@ -293,6 +272,27 @@ async function prepareForStaticCard() {
|
||||
}
|
||||
}
|
||||
|
||||
async function overwriteAccessToken() {
|
||||
if (location.hostname !== 'chat.openai.com') return
|
||||
|
||||
let data
|
||||
if (location.pathname === '/api/auth/session') {
|
||||
const response = document.querySelector('pre').textContent
|
||||
try {
|
||||
data = JSON.parse(response)
|
||||
} catch (error) {
|
||||
console.error('json error', error)
|
||||
}
|
||||
} else {
|
||||
const resp = await fetch('https://chat.openai.com/api/auth/session')
|
||||
data = await resp.json().catch(() => ({}))
|
||||
}
|
||||
if (data && data.accessToken) {
|
||||
await setAccessToken(data.accessToken)
|
||||
console.log(data.accessToken)
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
await getPreferredLanguageKey().then((lang) => {
|
||||
changeLanguage(lang)
|
||||
|
||||
Reference in New Issue
Block a user