diff --git a/README.md b/README.md index 54dc11d..dfdcb83 100644 --- a/README.md +++ b/README.md @@ -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 Coming soon :) diff --git a/src/garlic.js b/src/garlic.js index 5b456b1..e1653f7 100644 --- a/src/garlic.js +++ b/src/garlic.js @@ -40,12 +40,25 @@ class Garlic { static encode(string) { 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; -/* - - -*/ diff --git a/src/script.js b/src/script.js index a96edc0..e69de29 100644 --- a/src/script.js +++ b/src/script.js @@ -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")); -});