mirror of
https://github.com/velocitatem/garlic.git
synced 2026-05-31 08:43:36 +00:00
New
This commit is contained in:
@@ -1,31 +1,51 @@
|
||||
function garlic(body) {
|
||||
let bodyCopy = {...body};
|
||||
if (body.props) {
|
||||
if (body.props.children) {
|
||||
// check if children is an array
|
||||
if (Array.isArray(body.props.children)) {
|
||||
let newList = []
|
||||
for (let i = 0; i < body.props.children.length; i++) {
|
||||
// if child is a string, convert it to base64
|
||||
if (typeof body.props.children[i] === 'string') {
|
||||
newList.push(btoa(body.props.children[i]));
|
||||
} else {
|
||||
// if child is not a string, apply this function to it
|
||||
newList.push(garlic(body.props.children[i]));
|
||||
|
||||
class Garlic {
|
||||
|
||||
static clove(body) {
|
||||
let bodyCopy = {...body};
|
||||
if (body.props) {
|
||||
if (body.props.children) {
|
||||
// check if children is an array
|
||||
if (Array.isArray(body.props.children)) {
|
||||
let newList = []
|
||||
for (let i = 0; i < body.props.children.length; i++) {
|
||||
// if child is a string, convert it to base64
|
||||
if (typeof body.props.children[i] === 'string') {
|
||||
newList.push(this.encode(body.props.children[i]));
|
||||
} else {
|
||||
// if child is not a string, apply this function to it
|
||||
newList.push(this.clove(body.props.children[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
bodyCopy = {...bodyCopy, props: {...bodyCopy.props, children: newList}};
|
||||
} else {
|
||||
// if child is a string, convert it to base64
|
||||
if (typeof body.props.children === 'string') {
|
||||
bodyCopy = {...body, props: {...body.props, children: btoa(body.props.children)}};
|
||||
bodyCopy = {...bodyCopy, props: {...bodyCopy.props, children: newList}};
|
||||
} else {
|
||||
bodyCopy = {...body, props: {...body.props, children: garlic(body.props.children)}};
|
||||
// if child is a string, convert it to base64
|
||||
if (typeof body.props.children === 'string') {
|
||||
bodyCopy = {...body, props: {...body.props, children: this.encode(body.props.children)}};
|
||||
} else {
|
||||
bodyCopy = {...body, props: {...body.props, children: this.clove(body.props.children)}};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
return bodyCopy;
|
||||
}
|
||||
|
||||
export default garlic;
|
||||
export default Garlic;
|
||||
/*
|
||||
|
||||
<script>
|
||||
|
||||
</script>
|
||||
*/
|
||||
|
||||
16
src/script.js
Normal file
16
src/script.js
Normal 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"));
|
||||
});
|
||||
Reference in New Issue
Block a user