This commit is contained in:
2023-03-01 13:55:20 +01:00
parent 711b1d9cd4
commit 2b7dc81db8
2 changed files with 59 additions and 23 deletions

View File

@@ -1,4 +1,7 @@
function garlic(body) {
class Garlic {
static clove(body) {
let bodyCopy = {...body}; let bodyCopy = {...body};
if (body.props) { if (body.props) {
if (body.props.children) { if (body.props.children) {
@@ -8,24 +11,41 @@ function garlic(body) {
for (let i = 0; i < body.props.children.length; i++) { for (let i = 0; i < body.props.children.length; i++) {
// if child is a string, convert it to base64 // if child is a string, convert it to base64
if (typeof body.props.children[i] === 'string') { if (typeof body.props.children[i] === 'string') {
newList.push(btoa(body.props.children[i])); newList.push(this.encode(body.props.children[i]));
} else { } else {
// if child is not a string, apply this function to it // if child is not a string, apply this function to it
newList.push(garlic(body.props.children[i])); newList.push(this.clove(body.props.children[i]));
} }
} }
bodyCopy = {...bodyCopy, props: {...bodyCopy.props, children: newList}}; bodyCopy = {...bodyCopy, props: {...bodyCopy.props, children: newList}};
} else { } else {
// if child is a string, convert it to base64 // if child is a string, convert it to base64
if (typeof body.props.children === 'string') { if (typeof body.props.children === 'string') {
bodyCopy = {...body, props: {...body.props, children: btoa(body.props.children)}}; bodyCopy = {...body, props: {...body.props, children: this.encode(body.props.children)}};
} else { } else {
bodyCopy = {...body, props: {...body.props, children: garlic(body.props.children)}}; bodyCopy = {...body, props: {...body.props, children: this.clove(body.props.children)}};
} }
} }
} }
} }
return bodyCopy; return bodyCopy;
}
static addSalt(salt) {
// set a static variable to the salt
this.salt = "_yummy_" + salt;
document.salt = salt;
}
static encode(string) {
return btoa(string+this.salt);
}
} }
export default garlic; export default Garlic;
/*
<script>
</script>
*/

16
src/script.js Normal file
View File

@@ -0,0 +1,16 @@
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"));
});