mirror of
https://github.com/MODSetter/SurfSense.git
synced 2025-09-11 06:44:40 +00:00
Biome: Fixes for extenstion repo
This commit is contained in:
parent
b70d46f732
commit
b76419c6fc
29 changed files with 2668 additions and 2386 deletions
|
@ -1,144 +1,137 @@
|
|||
import { Storage } from "@plasmohq/storage"
|
||||
import type { WebHistory } from "./interfaces"
|
||||
import { Storage } from "@plasmohq/storage";
|
||||
import type { WebHistory } from "./interfaces";
|
||||
|
||||
export const emptyArr: any[] = []
|
||||
export const emptyArr: any[] = [];
|
||||
|
||||
export const initQueues = async (tabId: number) => {
|
||||
const storage = new Storage({ area: "local" })
|
||||
const storage = new Storage({ area: "local" });
|
||||
|
||||
let urlQueueListObj: any = await storage.get("urlQueueList")
|
||||
let timeQueueListObj: any = await storage.get("timeQueueList")
|
||||
const urlQueueListObj: any = await storage.get("urlQueueList");
|
||||
const timeQueueListObj: any = await storage.get("timeQueueList");
|
||||
|
||||
if (!urlQueueListObj && !timeQueueListObj) {
|
||||
await storage.set("urlQueueList", {
|
||||
urlQueueList: [{ tabsessionId: tabId, urlQueue: [] }]
|
||||
})
|
||||
await storage.set("timeQueueList", {
|
||||
timeQueueList: [{ tabsessionId: tabId, timeQueue: [] }]
|
||||
})
|
||||
if (!urlQueueListObj && !timeQueueListObj) {
|
||||
await storage.set("urlQueueList", {
|
||||
urlQueueList: [{ tabsessionId: tabId, urlQueue: [] }],
|
||||
});
|
||||
await storage.set("timeQueueList", {
|
||||
timeQueueList: [{ tabsessionId: tabId, timeQueue: [] }],
|
||||
});
|
||||
|
||||
return
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (urlQueueListObj.urlQueueList && timeQueueListObj.timeQueueList) {
|
||||
const isUrlQueueThere = urlQueueListObj.urlQueueList.find(
|
||||
(data: WebHistory) => data.tabsessionId === tabId
|
||||
)
|
||||
const isTimeQueueThere = timeQueueListObj.timeQueueList.find(
|
||||
(data: WebHistory) => data.tabsessionId === tabId
|
||||
)
|
||||
if (urlQueueListObj.urlQueueList && timeQueueListObj.timeQueueList) {
|
||||
const isUrlQueueThere = urlQueueListObj.urlQueueList.find(
|
||||
(data: WebHistory) => data.tabsessionId === tabId
|
||||
);
|
||||
const isTimeQueueThere = timeQueueListObj.timeQueueList.find(
|
||||
(data: WebHistory) => data.tabsessionId === tabId
|
||||
);
|
||||
|
||||
if (!isUrlQueueThere) {
|
||||
urlQueueListObj.urlQueueList.push({ tabsessionId: tabId, urlQueue: [] })
|
||||
if (!isUrlQueueThere) {
|
||||
urlQueueListObj.urlQueueList.push({ tabsessionId: tabId, urlQueue: [] });
|
||||
|
||||
await storage.set("urlQueueList", {
|
||||
urlQueueList: urlQueueListObj.urlQueueList
|
||||
})
|
||||
}
|
||||
await storage.set("urlQueueList", {
|
||||
urlQueueList: urlQueueListObj.urlQueueList,
|
||||
});
|
||||
}
|
||||
|
||||
if (!isTimeQueueThere) {
|
||||
timeQueueListObj.timeQueueList.push({
|
||||
tabsessionId: tabId,
|
||||
timeQueue: []
|
||||
})
|
||||
if (!isTimeQueueThere) {
|
||||
timeQueueListObj.timeQueueList.push({
|
||||
tabsessionId: tabId,
|
||||
timeQueue: [],
|
||||
});
|
||||
|
||||
await storage.set("timeQueueList", {
|
||||
timeQueueList: timeQueueListObj.timeQueueList
|
||||
})
|
||||
}
|
||||
await storage.set("timeQueueList", {
|
||||
timeQueueList: timeQueueListObj.timeQueueList,
|
||||
});
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
export function getRenderedHtml() {
|
||||
return {
|
||||
url: window.location.href,
|
||||
entryTime: Date.now(),
|
||||
title: document.title,
|
||||
renderedHtml: document.documentElement.outerHTML
|
||||
}
|
||||
return {
|
||||
url: window.location.href,
|
||||
entryTime: Date.now(),
|
||||
title: document.title,
|
||||
renderedHtml: document.documentElement.outerHTML,
|
||||
};
|
||||
}
|
||||
|
||||
export const initWebHistory = async (tabId: number) => {
|
||||
const storage = new Storage({ area: "local" })
|
||||
const result: any = await storage.get("webhistory")
|
||||
const storage = new Storage({ area: "local" });
|
||||
const result: any = await storage.get("webhistory");
|
||||
|
||||
if (result === undefined) {
|
||||
await storage.set("webhistory", { webhistory: emptyArr })
|
||||
return
|
||||
}
|
||||
if (result === undefined) {
|
||||
await storage.set("webhistory", { webhistory: emptyArr });
|
||||
return;
|
||||
}
|
||||
|
||||
const ifIdExists = result.webhistory.find(
|
||||
(data: WebHistory) => data.tabsessionId === tabId
|
||||
)
|
||||
const ifIdExists = result.webhistory.find((data: WebHistory) => data.tabsessionId === tabId);
|
||||
|
||||
if (ifIdExists === undefined) {
|
||||
let webHistory = result.webhistory
|
||||
const initData = {
|
||||
tabsessionId: tabId,
|
||||
tabHistory: emptyArr
|
||||
}
|
||||
if (ifIdExists === undefined) {
|
||||
const webHistory = result.webhistory;
|
||||
const initData = {
|
||||
tabsessionId: tabId,
|
||||
tabHistory: emptyArr,
|
||||
};
|
||||
|
||||
webHistory.push(initData)
|
||||
webHistory.push(initData);
|
||||
|
||||
try {
|
||||
await storage.set("webhistory", { webhistory: webHistory })
|
||||
return
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
try {
|
||||
await storage.set("webhistory", { webhistory: webHistory });
|
||||
return;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
export function toIsoString(date: Date) {
|
||||
var tzo = -date.getTimezoneOffset(),
|
||||
dif = tzo >= 0 ? "+" : "-",
|
||||
pad = function (num: number) {
|
||||
return (num < 10 ? "0" : "") + num
|
||||
}
|
||||
var tzo = -date.getTimezoneOffset(),
|
||||
dif = tzo >= 0 ? "+" : "-",
|
||||
pad = (num: number) => (num < 10 ? "0" : "") + num;
|
||||
|
||||
return (
|
||||
date.getFullYear() +
|
||||
"-" +
|
||||
pad(date.getMonth() + 1) +
|
||||
"-" +
|
||||
pad(date.getDate()) +
|
||||
"T" +
|
||||
pad(date.getHours()) +
|
||||
":" +
|
||||
pad(date.getMinutes()) +
|
||||
":" +
|
||||
pad(date.getSeconds()) +
|
||||
dif +
|
||||
pad(Math.floor(Math.abs(tzo) / 60)) +
|
||||
":" +
|
||||
pad(Math.abs(tzo) % 60)
|
||||
)
|
||||
return (
|
||||
date.getFullYear() +
|
||||
"-" +
|
||||
pad(date.getMonth() + 1) +
|
||||
"-" +
|
||||
pad(date.getDate()) +
|
||||
"T" +
|
||||
pad(date.getHours()) +
|
||||
":" +
|
||||
pad(date.getMinutes()) +
|
||||
":" +
|
||||
pad(date.getSeconds()) +
|
||||
dif +
|
||||
pad(Math.floor(Math.abs(tzo) / 60)) +
|
||||
":" +
|
||||
pad(Math.abs(tzo) % 60)
|
||||
);
|
||||
}
|
||||
|
||||
export const webhistoryToLangChainDocument = (
|
||||
tabId: number,
|
||||
tabHistory: any[]
|
||||
) => {
|
||||
let toSaveFinally = []
|
||||
for (let j = 0; j < tabHistory.length; j++) {
|
||||
const mtadata = {
|
||||
BrowsingSessionId: `${tabId}`,
|
||||
VisitedWebPageURL: `${tabHistory[j].url}`,
|
||||
VisitedWebPageTitle: `${tabHistory[j].title}`,
|
||||
VisitedWebPageDateWithTimeInISOString: `${toIsoString(new Date(tabHistory[j].entryTime))}`,
|
||||
VisitedWebPageReffererURL: `${tabHistory[j].reffererUrl}`,
|
||||
VisitedWebPageVisitDurationInMilliseconds: tabHistory[j].duration
|
||||
}
|
||||
export const webhistoryToLangChainDocument = (tabId: number, tabHistory: any[]) => {
|
||||
const toSaveFinally = [];
|
||||
for (let j = 0; j < tabHistory.length; j++) {
|
||||
const mtadata = {
|
||||
BrowsingSessionId: `${tabId}`,
|
||||
VisitedWebPageURL: `${tabHistory[j].url}`,
|
||||
VisitedWebPageTitle: `${tabHistory[j].title}`,
|
||||
VisitedWebPageDateWithTimeInISOString: `${toIsoString(new Date(tabHistory[j].entryTime))}`,
|
||||
VisitedWebPageReffererURL: `${tabHistory[j].reffererUrl}`,
|
||||
VisitedWebPageVisitDurationInMilliseconds: tabHistory[j].duration,
|
||||
};
|
||||
|
||||
toSaveFinally.push({
|
||||
metadata: mtadata,
|
||||
pageContent: tabHistory[j].pageContentMarkdown
|
||||
})
|
||||
}
|
||||
toSaveFinally.push({
|
||||
metadata: mtadata,
|
||||
pageContent: tabHistory[j].pageContentMarkdown,
|
||||
});
|
||||
}
|
||||
|
||||
return toSaveFinally
|
||||
}
|
||||
return toSaveFinally;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue