-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
88 lines (72 loc) · 3.75 KB
/
index.html
File metadata and controls
88 lines (72 loc) · 3.75 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<head>
<title>Hyte</title>
</head>
<body>
<h1 style="text-align: center">Loading...</h1>
<script type="module">
import { unpaq } from "./paq.mjs"
// Function to convert Base64 string to bytes
function base64ToBytes(base64) {
const binaryString = atob(base64);
return Uint8Array.from(binaryString, (character) => character.codePointAt(0));
}
// Check if the URL contains a hash value
if(window.location.hash) {
// Extract the first part of the hash value
let hashValue = window.location.hash.substring(1).split("&")[0];
// Convert Base64 hash value to bytes
let base64Bytes = base64ToBytes(hashValue);
// Decompress the Base64 bytes using PAQ
let decompressedData = (await unpaq(base64Bytes))
// Decode the decompressed data to a HTML string
let htmlString = new TextDecoder().decode(decompressedData);
// Create a new DOMParser object
let parser = new DOMParser();
// Parse the HTML string into a Document object
let parsedDocument = parser.parseFromString(htmlString, 'text/html');
// Extract scripts from the parsed document
let headScripts = Array.from(parsedDocument.head.getElementsByTagName('script'));
let bodyScripts = Array.from(parsedDocument.body.getElementsByTagName('script'));
// Remove the scripts from the parsed document
headScripts.forEach(script => script.parentNode.removeChild(script));
bodyScripts.forEach(script => script.parentNode.removeChild(script));
// Extract styles from the parsed document
let styles = Array.from(parsedDocument.getElementsByTagName('style')).map(style => style.textContent);
// Extract the head and body HTML from the parsed document
let headHTML = parsedDocument.head.innerHTML;
let bodyHTML = parsedDocument.body.innerHTML;
// Replace the entire document's head and body
document.head.innerHTML = headHTML;
document.body.innerHTML = bodyHTML;
// Copy all body attributes from the parsed document to the current document
for (let i = 0; i < parsedDocument.body.attributes.length; i++) {
let attribute = parsedDocument.body.attributes[i];
document.body.setAttribute(attribute.name, attribute.value);
}
// Add the extracted CSS to the document
let styleElement = document.createElement('style');
styleElement.textContent = styles.join("\n");
document.head.appendChild(styleElement);
// Function to add scripts back to the target (head or body) of the document
const addScripts = (originalScripts, target) => {
originalScripts.forEach(originalScript => {
let scriptElement = document.createElement('script');
if (originalScript.src) {
// For external scripts
scriptElement.src = originalScript.src;
} else {
// For inline scripts
scriptElement.textContent = originalScript.textContent;
if(originalScript.type === "module") {
scriptElement.type = "module";
}
}
target.appendChild(scriptElement);
});
}
// Add the extracted JavaScript back to the head and body of the document
addScripts(headScripts, document.head);
addScripts(bodyScripts, document.body);
}
</script>
</body>