This commit is contained in:
2023-03-01 14:30:35 +01:00
parent 2b7dc81db8
commit 9f0481a180
3 changed files with 27 additions and 22 deletions

View File

@@ -29,6 +29,14 @@ function App() {
}; };
``` ```
Go to `index.js` or anywhere before render. Add the following line of code:
```js
Garlic.peal(document);
```
And all is done!
## Astro ## Astro
Coming soon :) Coming soon :)

View File

@@ -40,12 +40,25 @@ class Garlic {
static encode(string) { static encode(string) {
return btoa(string+this.salt); return btoa(string+this.salt);
} }
static decodeBase64(root) {
for (let i = 0; i < root.childNodes.length; i++) {
const child = root.childNodes[i];
if (child.childNodes.length === 1 && child.childNodes[0].nodeType === 3) {
const decoded = atob(child.childNodes[0].nodeValue).split("_yummy_")[0];
child.innerHTML = decoded;
console.log(child);
} else {
this.decodeBase64(child);
}
}
} }
static peal(document) {
document.addEventListener("DOMContentLoaded", function(event) {
Garlic.decodeBase64(document.getElementById("root"));
});
}
}
export default Garlic; export default Garlic;
/*
<script>
</script>
*/

View File

@@ -1,16 +0,0 @@
function decodeBase64(root) {
for (let i = 0; i < root.childNodes.length; i++) {
const child = root.childNodes[i];
if (child.childNodes.length === 1 && child.childNodes[0].nodeType === 3) {
const decoded = atob(child.childNodes[0].nodeValue).split("_yummy_")[0]
child.innerHTML = decoded;
console.log(child);
} else {
decodeBase64(child);
}
}
}
// when document is ready, decode the base64
document.addEventListener("DOMContentLoaded", function(event) {
decodeBase64(document.getElementById("root"));
});