Skip to content

Instantly share code, notes, and snippets.

@bernardoadc
Created November 18, 2019 18:22
Show Gist options
  • Save bernardoadc/11ce779521dc7a7fc404a8fb2320c408 to your computer and use it in GitHub Desktop.
Save bernardoadc/11ce779521dc7a7fc404a8fb2320c408 to your computer and use it in GitHub Desktop.
Simple HTML If eval
// function $$(selector, context) {
// context = context || document;
// var elements = context.querySelectorAll(selector);
// return Array.prototype.slice.call(elements);
// }
let html = $$('html')[0].innerHTML
let result
while (result = /{{#if.+}}[^]+?{{\/if}}/g.exec(html)) {
let block = result[0]
let expr = /{{#if \((.+)\)}}/y.exec(block)[1]
let content = /{{#if.+}}([^]+){{\/if}}/y.exec(block)[1]
if (!eval(expr))
$$('html')[0].innerHTML = html.replace(block, '')
else
$$('html')[0].innerHTML = html.replace(block, content)
html = $$('html')[0].innerHTML
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment