This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.chrome.js
35 lines (33 loc) · 1.63 KB
/
background.chrome.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import parser from "./modules/parser/march_2023.js";
import htmlCreator from "./modules/htmlCreator.js";
import JSZip from "./modules/jszip.js";
if (typeof browser === "undefined") {
var browser = chrome;
}
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "htmlCreator") {
(async function () {
try {
const result = await htmlCreator(parser, request.data);
const fileName = "[GPTSaver]_"+result.data.title.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/ /g, '_').replace(/[^a-z0-9-_]/g, '') + ".zip";
const comment = `Thank you ${result.data.userName} for using GPTSaver. This app was create by Matsukky, please check https://matsukky.com.\nFor open you conversation, open index.html.`;
const zip = new JSZip();
zip.file('index.html', result.html);
zip.file('data.json', JSON.stringify(result.data));
zip.file('README', comment);
const response = await fetch(browser.runtime.getURL('filesInfo.json'));
const data = await response.json();
for (const filename of data) {
try {
const response = await fetch(browser.runtime.getURL(filename));
const fileData = await response.arrayBuffer();
zip.file(filename, fileData);
} catch (error) {
console.error(error);
sendResponse(error)
}}
const content = await zip.generateAsync({type:"base64", comment});
sendResponse({content, fileName});
} catch (error) { sendResponse(error) }})();
return true;
}})