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.firefox.html
65 lines (61 loc) · 2.54 KB
/
background.firefox.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GPTSaver</title>
</head>
<body>
<script src="./modules/parser/march_2023.js"></script>
<script src="./modules/htmlCreator.js"></script>
<script src="./modules/jszip.js"></script>
<script>
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.`;
// Create the JSZip instance
const zip = new JSZip();
// Add files to the zip
zip.file('index.html', result.html);
zip.file('data.json', JSON.stringify(result.data));
zip.file('README', comment);
// Fetch and add additional files from filesInfo.json
fetch(browser.runtime.getURL('filesInfo.json'))
.then(response => response.json())
.then(async data => {
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);
}
}
// Generate the zip content and send the response
zip.generateAsync({ type: "base64", comment })
.then(content => sendResponse({ content, fileName }))
.catch(error => sendResponse(error));
})
.catch(error => {
console.error(error);
sendResponse(error);
});
} catch (error) {
sendResponse(error);
}
})();
return true;
}
});
</script>
</body>
</html>