few bug fixes
This commit is contained in:
parent
f9f621c920
commit
79e2013fbd
@ -2,7 +2,6 @@ import {
|
|||||||
type ChatHistory as ChatHistoryType,
|
type ChatHistory as ChatHistoryType,
|
||||||
type Message as MessageType
|
type Message as MessageType
|
||||||
} from "~/store/option"
|
} from "~/store/option"
|
||||||
import { Storage, browser } from "wxt/browser"
|
|
||||||
|
|
||||||
type HistoryInfo = {
|
type HistoryInfo = {
|
||||||
id: string
|
id: string
|
||||||
@ -58,18 +57,15 @@ type ChatHistory = HistoryInfo[]
|
|||||||
type Prompts = Prompt[]
|
type Prompts = Prompt[]
|
||||||
|
|
||||||
export class PageAssitDatabase {
|
export class PageAssitDatabase {
|
||||||
db: Storage.LocalStorageArea
|
db: chrome.storage.StorageArea
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.db = browser.storage.local
|
this.db = chrome.storage.local
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChatHistory(id: string): Promise<MessageHistory> {
|
async getChatHistory(id: string): Promise<MessageHistory> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get(id, (result) => {
|
this.db.get(id, (result) => {
|
||||||
// resolve(result[id] || [])
|
|
||||||
// })
|
|
||||||
this.db.get(id).then((result) => {
|
|
||||||
resolve(result[id] || [])
|
resolve(result[id] || [])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -77,10 +73,7 @@ export class PageAssitDatabase {
|
|||||||
|
|
||||||
async getChatHistories(): Promise<ChatHistory> {
|
async getChatHistories(): Promise<ChatHistory> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get("chatHistories", (result) => {
|
this.db.get("chatHistories", (result) => {
|
||||||
// resolve(result.chatHistories || [])
|
|
||||||
// })
|
|
||||||
this.db.get("chatHistories").then((result) => {
|
|
||||||
resolve(result.chatHistories || [])
|
resolve(result.chatHistories || [])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -133,10 +126,7 @@ export class PageAssitDatabase {
|
|||||||
|
|
||||||
async getAllPrompts(): Promise<Prompts> {
|
async getAllPrompts(): Promise<Prompts> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get("prompts", (result) => {
|
this.db.get("prompts", (result) => {
|
||||||
// resolve(result.prompts || [])
|
|
||||||
// })
|
|
||||||
this.db.get("prompts").then((result) => {
|
|
||||||
resolve(result.prompts || [])
|
resolve(result.prompts || [])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -179,10 +169,7 @@ export class PageAssitDatabase {
|
|||||||
|
|
||||||
async getWebshare(id: string) {
|
async getWebshare(id: string) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get(id, (result) => {
|
this.db.get(id, (result) => {
|
||||||
// resolve(result[id] || [])
|
|
||||||
// })
|
|
||||||
this.db.get(id).then((result) => {
|
|
||||||
resolve(result[id] || [])
|
resolve(result[id] || [])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -190,10 +177,7 @@ export class PageAssitDatabase {
|
|||||||
|
|
||||||
async getAllWebshares(): Promise<Webshare[]> {
|
async getAllWebshares(): Promise<Webshare[]> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get("webshares", (result) => {
|
this.db.get("webshares", (result) => {
|
||||||
// resolve(result.webshares || [])
|
|
||||||
// })
|
|
||||||
this.db.get("webshares").then((result) => {
|
|
||||||
resolve(result.webshares || [])
|
resolve(result.webshares || [])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -213,10 +197,7 @@ export class PageAssitDatabase {
|
|||||||
|
|
||||||
async getUserID() {
|
async getUserID() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get("user_id", (result) => {
|
this.db.get("user_id", (result) => {
|
||||||
// resolve(result.user_id || "")
|
|
||||||
// })
|
|
||||||
this.db.get("user_id").then((result) => {
|
|
||||||
resolve(result.user_id || "")
|
resolve(result.user_id || "")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -474,4 +455,4 @@ export const importPrompts = async (prompts: Prompts) => {
|
|||||||
for (const prompt of prompts) {
|
for (const prompt of prompts) {
|
||||||
await db.addPrompt(prompt)
|
await db.addPrompt(prompt)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
import { Storage, browser } from "wxt/browser"
|
|
||||||
import { deleteVector, deleteVectorByFileId } from "./vector"
|
import { deleteVector, deleteVectorByFileId } from "./vector"
|
||||||
|
|
||||||
export type Source = {
|
export type Source = {
|
||||||
@ -25,105 +24,89 @@ export const generateID = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
export class PageAssistKnowledge {
|
export class PageAssistKnowledge {
|
||||||
db: Storage.LocalStorageArea
|
db: chrome.storage.StorageArea
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.db = browser.storage.local
|
this.db = chrome.storage.local
|
||||||
}
|
}
|
||||||
|
|
||||||
getAll = async (): Promise<Knowledge[]> => {
|
getAll = async (): Promise<Knowledge[]> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get(null, (result) => {
|
this.db.get(null, (result) => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// const data = Object.keys(result).map((key) => result[key])
|
const data = Object.keys(result).map((key) => result[key])
|
||||||
// resolve(data)
|
resolve(data)
|
||||||
// }
|
}
|
||||||
// })
|
|
||||||
this.db.get(null).then((result) => {
|
|
||||||
const data = Object.keys(result).map((key) => result[key])
|
|
||||||
resolve(data)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
getById = async (id: string): Promise<Knowledge> => {
|
getById = async (id: string): Promise<Knowledge> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.db.get(id).then((result) => {
|
this.db.get(id, (result) => {
|
||||||
resolve(result[id])
|
if (chrome.runtime.lastError) {
|
||||||
|
reject(chrome.runtime.lastError)
|
||||||
|
} else {
|
||||||
|
resolve(result[id])
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create = async (knowledge: Knowledge): Promise<void> => {
|
create = async (knowledge: Knowledge): Promise<void> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.set({ [knowledge.id]: knowledge }, () => {
|
this.db.set({ [knowledge.id]: knowledge }, () => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// resolve()
|
resolve()
|
||||||
// }
|
}
|
||||||
// })
|
|
||||||
this.db.set({ [knowledge.id]: knowledge }).then(() => {
|
|
||||||
resolve()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
update = async (knowledge: Knowledge): Promise<void> => {
|
update = async (knowledge: Knowledge): Promise<void> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.set({ [knowledge.id]: knowledge }, () => {
|
this.db.set({ [knowledge.id]: knowledge }, () => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// resolve()
|
resolve()
|
||||||
// }
|
}
|
||||||
// })
|
|
||||||
this.db.set({ [knowledge.id]: knowledge }).then(() => {
|
|
||||||
resolve()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
delete = async (id: string): Promise<void> => {
|
delete = async (id: string): Promise<void> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.remove(id, () => {
|
this.db.remove(id, () => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// resolve()
|
resolve()
|
||||||
// }
|
}
|
||||||
// })
|
|
||||||
this.db.remove(id).then(() => {
|
|
||||||
resolve()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteSource = async (id: string, source_id: string): Promise<void> => {
|
deleteSource = async (id: string, source_id: string): Promise<void> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get(id, (result) => {
|
this.db.get(id, (result) => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// const data = result[id] as Knowledge
|
const data = result[id] as Knowledge
|
||||||
// data.source = data.source.filter((s) => s.source_id !== source_id)
|
data.source = data.source.filter((s) => s.source_id !== source_id)
|
||||||
// this.db.set({ [id]: data }, () => {
|
this.db.set({ [id]: data }, () => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// resolve()
|
resolve()
|
||||||
// }
|
}
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
// })
|
|
||||||
this.db.get(id).then((result) => {
|
|
||||||
const data = result[id] as Knowledge
|
|
||||||
data.source = data.source.filter((s) => s.source_id !== source_id)
|
|
||||||
this.db.set({ [id]: data }).then(() => {
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -219,4 +202,4 @@ export const importKnowledge = async (data: Knowledge[]) => {
|
|||||||
for (const d of data) {
|
for (const d of data) {
|
||||||
await db.create(d)
|
await db.create(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
178
src/db/vector.ts
178
src/db/vector.ts
@ -1,5 +1,3 @@
|
|||||||
import { Storage, browser } from "wxt/browser"
|
|
||||||
|
|
||||||
interface PageAssistVector {
|
interface PageAssistVector {
|
||||||
file_id: string
|
file_id: string
|
||||||
content: string
|
content: string
|
||||||
@ -13,10 +11,10 @@ export type VectorData = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PageAssistVectorDb {
|
export class PageAssistVectorDb {
|
||||||
db: Storage.LocalStorageArea
|
db: chrome.storage.StorageArea
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.db = browser.storage.local
|
this.db = chrome.storage.local
|
||||||
}
|
}
|
||||||
|
|
||||||
insertVector = async (
|
insertVector = async (
|
||||||
@ -24,55 +22,36 @@ export class PageAssistVectorDb {
|
|||||||
vector: PageAssistVector[]
|
vector: PageAssistVector[]
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get(id, (result) => {
|
this.db.get(id, (result) => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
|
||||||
// const data = result[id] as VectorData
|
|
||||||
// if (!data) {
|
|
||||||
// this.db.set({ [id]: { id, vectors: vector } }, () => {
|
|
||||||
// if (chrome.runtime.lastError) {
|
|
||||||
// reject(chrome.runtime.lastError)
|
|
||||||
// } else {
|
|
||||||
// resolve()
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// } else {
|
|
||||||
// this.db.set(
|
|
||||||
// {
|
|
||||||
// [id]: {
|
|
||||||
// ...data,
|
|
||||||
// vectors: data.vectors.concat(vector)
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// () => {
|
|
||||||
// if (chrome.runtime.lastError) {
|
|
||||||
// reject(chrome.runtime.lastError)
|
|
||||||
// } else {
|
|
||||||
// resolve()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
this.db.get(id).then((result) => {
|
|
||||||
const data = result[id] as VectorData
|
|
||||||
if (!data) {
|
|
||||||
this.db.set({ [id]: { id, vectors: vector } }).then(() => {
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
this.db
|
const data = result[id] as VectorData
|
||||||
.set({
|
if (!data) {
|
||||||
[id]: {
|
this.db.set({ [id]: { id, vectors: vector } }, () => {
|
||||||
...data,
|
if (chrome.runtime.lastError) {
|
||||||
vectors: data.vectors.concat(vector)
|
reject(chrome.runtime.lastError)
|
||||||
|
} else {
|
||||||
|
resolve()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(() => {
|
} else {
|
||||||
resolve()
|
this.db.set(
|
||||||
})
|
{
|
||||||
|
[id]: {
|
||||||
|
...data,
|
||||||
|
vectors: data.vectors.concat(vector)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
if (chrome.runtime.lastError) {
|
||||||
|
reject(chrome.runtime.lastError)
|
||||||
|
} else {
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -80,72 +59,56 @@ export class PageAssistVectorDb {
|
|||||||
|
|
||||||
deleteVector = async (id: string): Promise<void> => {
|
deleteVector = async (id: string): Promise<void> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.remove(id, () => {
|
this.db.remove(id, () => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// resolve()
|
resolve()
|
||||||
// }
|
}
|
||||||
// })
|
|
||||||
this.db.remove(id).then(() => {
|
|
||||||
resolve()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteVectorByFileId = async (id: string, file_id: string): Promise<void> => {
|
deleteVectorByFileId = async (id: string, file_id: string): Promise<void> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get(id, (result) => {
|
this.db.get(id, (result) => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// const data = result[id] as VectorData
|
const data = result[id] as VectorData
|
||||||
// data.vectors = data.vectors.filter((v) => v.file_id !== file_id)
|
data.vectors = data.vectors.filter((v) => v.file_id !== file_id)
|
||||||
// this.db.set({ [id]: data }, () => {
|
this.db.set({ [id]: data }, () => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// resolve()
|
resolve()
|
||||||
// }
|
}
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
// })
|
|
||||||
this.db.get(id).then((result) => {
|
|
||||||
const data = result[id] as VectorData
|
|
||||||
data.vectors = data.vectors.filter((v) => v.file_id !== file_id)
|
|
||||||
this.db.set({ [id]: data }).then(() => {
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
getVector = async (id: string): Promise<VectorData> => {
|
getVector = async (id: string): Promise<VectorData> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get(id, (result) => {
|
this.db.get(id, (result) => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// resolve(result[id] as VectorData)
|
resolve(result[id] as VectorData)
|
||||||
// }
|
}
|
||||||
// })
|
|
||||||
this.db.get(id).then((result) => {
|
|
||||||
resolve(result[id] as VectorData)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
getAll = async (): Promise<VectorData[]> => {
|
getAll = async (): Promise<VectorData[]> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.db.get(null, (result) => {
|
this.db.get(null, (result) => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// resolve(Object.values(result))
|
resolve(Object.values(result))
|
||||||
// }
|
}
|
||||||
// })
|
|
||||||
this.db.get(null).then((result) => {
|
|
||||||
resolve(Object.values(result))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -156,15 +119,12 @@ export class PageAssistVectorDb {
|
|||||||
data.forEach((d) => {
|
data.forEach((d) => {
|
||||||
obj[d.id] = d
|
obj[d.id] = d
|
||||||
})
|
})
|
||||||
// this.db.set(obj, () => {
|
this.db.set(obj, () => {
|
||||||
// if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
// reject(chrome.runtime.lastError)
|
reject(chrome.runtime.lastError)
|
||||||
// } else {
|
} else {
|
||||||
// resolve()
|
resolve()
|
||||||
// }
|
}
|
||||||
// })
|
|
||||||
this.db.set(obj).then(() => {
|
|
||||||
resolve()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -204,5 +164,5 @@ export const exportVectors = async () => {
|
|||||||
|
|
||||||
export const importVectors = async (data: VectorData[]) => {
|
export const importVectors = async (data: VectorData[]) => {
|
||||||
const db = new PageAssistVectorDb()
|
const db = new PageAssistVectorDb()
|
||||||
return db.saveImportedData(data)
|
return db.saveImportedData(data)
|
||||||
}
|
}
|
@ -1,13 +1,13 @@
|
|||||||
import { getOllamaURL, isOllamaRunning } from "../services/ollama"
|
import { getOllamaURL, isOllamaRunning } from "../services/ollama"
|
||||||
import { browser } from "wxt/browser"
|
import { browser } from "wxt/browser"
|
||||||
|
import { setBadgeBackgroundColor, setBadgeText, setTitle } from "@/utils/action"
|
||||||
const progressHuman = (completed: number, total: number) => {
|
const progressHuman = (completed: number, total: number) => {
|
||||||
return ((completed / total) * 100).toFixed(0) + "%"
|
return ((completed / total) * 100).toFixed(0) + "%"
|
||||||
}
|
}
|
||||||
|
|
||||||
const clearBadge = () => {
|
const clearBadge = () => {
|
||||||
browser.action.setBadgeText({ text: "" })
|
setBadgeText({ text: "" })
|
||||||
browser.action.setTitle({ title: "" })
|
setTitle({ title: "" })
|
||||||
}
|
}
|
||||||
const streamDownload = async (url: string, model: string) => {
|
const streamDownload = async (url: string, model: string) => {
|
||||||
url += "/api/pull"
|
url += "/api/pull"
|
||||||
@ -42,16 +42,16 @@ const streamDownload = async (url: string, model: string) => {
|
|||||||
completed?: number
|
completed?: number
|
||||||
}
|
}
|
||||||
if (json.total && json.completed) {
|
if (json.total && json.completed) {
|
||||||
browser.action.setBadgeText({
|
setBadgeText({
|
||||||
text: progressHuman(json.completed, json.total)
|
text: progressHuman(json.completed, json.total)
|
||||||
})
|
})
|
||||||
browser.action.setBadgeBackgroundColor({ color: "#0000FF" })
|
setBadgeBackgroundColor({ color: "#0000FF" })
|
||||||
} else {
|
} else {
|
||||||
browser.action.setBadgeText({ text: "🏋️♂️" })
|
setBadgeText({ text: "🏋️♂️" })
|
||||||
browser.action.setBadgeBackgroundColor({ color: "#FFFFFF" })
|
setBadgeBackgroundColor({ color: "#FFFFFF" })
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.action.setTitle({ title: json.status })
|
setTitle({ title: json.status })
|
||||||
|
|
||||||
if (json.status === "success") {
|
if (json.status === "success") {
|
||||||
isSuccess = true
|
isSuccess = true
|
||||||
@ -62,13 +62,13 @@ const streamDownload = async (url: string, model: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
browser.action.setBadgeText({ text: "✅" })
|
setBadgeText({ text: "✅" })
|
||||||
browser.action.setBadgeBackgroundColor({ color: "#00FF00" })
|
setBadgeBackgroundColor({ color: "#00FF00" })
|
||||||
browser.action.setTitle({ title: "Model pulled successfully" })
|
setTitle({ title: "Model pulled successfully" })
|
||||||
} else {
|
} else {
|
||||||
browser.action.setBadgeText({ text: "❌" })
|
setBadgeText({ text: "❌" })
|
||||||
browser.action.setBadgeBackgroundColor({ color: "#FF0000" })
|
setBadgeBackgroundColor({ color: "#FF0000" })
|
||||||
browser.action.setTitle({ title: "Model pull failed" })
|
setTitle({ title: "Model pull failed" })
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -86,9 +86,9 @@ export default defineBackground({
|
|||||||
const isRunning = await isOllamaRunning()
|
const isRunning = await isOllamaRunning()
|
||||||
|
|
||||||
if (!isRunning) {
|
if (!isRunning) {
|
||||||
browser.action.setBadgeText({ text: "E" })
|
setBadgeText({ text: "E" })
|
||||||
browser.action.setBadgeBackgroundColor({ color: "#FF0000" })
|
setBadgeBackgroundColor({ color: "#FF0000" })
|
||||||
browser.action.setTitle({ title: "Ollama is not running" })
|
setTitle({ title: "Ollama is not running" })
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
clearBadge()
|
clearBadge()
|
||||||
}, 5000)
|
}, 5000)
|
||||||
@ -98,9 +98,8 @@ export default defineBackground({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (browser?.action) {
|
if (import.meta.env.BROWSER === "chrome") {
|
||||||
browser.action.onClicked.addListener((tab) => {
|
chrome.action.onClicked.addListener((tab) => {
|
||||||
console.log("browser.action.onClicked.addListener")
|
|
||||||
browser.tabs.create({ url: browser.runtime.getURL("/options.html") })
|
browser.tabs.create({ url: browser.runtime.getURL("/options.html") })
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,7 +4,7 @@ import {
|
|||||||
isTweet,
|
isTweet,
|
||||||
isTwitterTimeline,
|
isTwitterTimeline,
|
||||||
parseTweet,
|
parseTweet,
|
||||||
parseTwitterTimeline,
|
parseTwitterTimeline
|
||||||
} from "@/parser/twitter"
|
} from "@/parser/twitter"
|
||||||
import { isGoogleDocs, parseGoogleDocs } from "@/parser/google-docs"
|
import { isGoogleDocs, parseGoogleDocs } from "@/parser/google-docs"
|
||||||
import { cleanUnwantedUnicode } from "@/utils/clean"
|
import { cleanUnwantedUnicode } from "@/utils/clean"
|
||||||
@ -24,18 +24,35 @@ const _getHtml = () => {
|
|||||||
|
|
||||||
export const getDataFromCurrentTab = async () => {
|
export const getDataFromCurrentTab = async () => {
|
||||||
const result = new Promise((resolve) => {
|
const result = new Promise((resolve) => {
|
||||||
chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => {
|
if (import.meta.env.BROWSER === "chrome") {
|
||||||
const tab = tabs[0]
|
chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => {
|
||||||
|
const tab = tabs[0]
|
||||||
|
|
||||||
const data = await chrome.scripting.executeScript({
|
const data = await chrome.scripting.executeScript({
|
||||||
target: { tabId: tab.id },
|
target: { tabId: tab.id },
|
||||||
func: _getHtml
|
func: _getHtml
|
||||||
|
})
|
||||||
|
|
||||||
|
if (data.length > 0) {
|
||||||
|
resolve(data[0].result)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
browser.tabs
|
||||||
|
.query({ active: true, currentWindow: true })
|
||||||
|
.then(async (tabs) => {
|
||||||
|
const tab = tabs[0]
|
||||||
|
|
||||||
if (data.length > 0) {
|
const data = await browser.scripting.executeScript({
|
||||||
resolve(data[0].result)
|
target: { tabId: tab.id },
|
||||||
}
|
func: _getHtml
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (data.length > 0) {
|
||||||
|
resolve(data[0].result)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}) as Promise<{
|
}) as Promise<{
|
||||||
url: string
|
url: string
|
||||||
content: string
|
content: string
|
||||||
|
@ -95,19 +95,36 @@ const getGoogleDocs = () => {
|
|||||||
|
|
||||||
export const parseGoogleDocs = async () => {
|
export const parseGoogleDocs = async () => {
|
||||||
const result = new Promise((resolve) => {
|
const result = new Promise((resolve) => {
|
||||||
chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => {
|
if (import.meta.env.BROWSER === "chrome") {
|
||||||
const tab = tabs[0]
|
chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => {
|
||||||
|
const tab = tabs[0]
|
||||||
|
|
||||||
const data = await chrome.scripting.executeScript({
|
const data = await chrome.scripting.executeScript({
|
||||||
target: { tabId: tab.id },
|
target: { tabId: tab.id },
|
||||||
world: "MAIN",
|
world: "MAIN",
|
||||||
func: getGoogleDocs
|
func: getGoogleDocs
|
||||||
|
})
|
||||||
|
|
||||||
|
if (data.length > 0) {
|
||||||
|
resolve(data[0].result)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
browser.tabs
|
||||||
|
.query({ active: true, currentWindow: true })
|
||||||
|
.then(async (tabs) => {
|
||||||
|
const tab = tabs[0]
|
||||||
|
|
||||||
if (data.length > 0) {
|
const data = await browser.scripting.executeScript({
|
||||||
resolve(data[0].result)
|
target: { tabId: tab.id },
|
||||||
}
|
func: getGoogleDocs
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (data.length > 0) {
|
||||||
|
resolve(data[0].result)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}) as Promise<{
|
}) as Promise<{
|
||||||
content?: string
|
content?: string
|
||||||
}>
|
}>
|
||||||
|
25
src/utils/action.ts
Normal file
25
src/utils/action.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { browser } from "wxt/browser"
|
||||||
|
|
||||||
|
export const setTitle = ({ title }: { title: string }) => {
|
||||||
|
if (import.meta.env.BROWSER === "chrome") {
|
||||||
|
chrome.action.setTitle({ title })
|
||||||
|
} else {
|
||||||
|
browser.browserAction.setTitle({ title })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const setBadgeBackgroundColor = ({ color }: { color: string }) => {
|
||||||
|
if (import.meta.env.BROWSER === "chrome") {
|
||||||
|
chrome.action.setBadgeBackgroundColor({ color })
|
||||||
|
} else {
|
||||||
|
browser.browserAction.setBadgeBackgroundColor({ color })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const setBadgeText = ({ text }: { text: string }) => {
|
||||||
|
if (import.meta.env.BROWSER === "chrome") {
|
||||||
|
chrome.action.setBadgeText({ text })
|
||||||
|
} else {
|
||||||
|
browser.browserAction.setBadgeText({ text })
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user