28
29
30
31
32
33
34
35
36
37
|
# File 'lib/jekyll-js-protect.rb', line 28
def add_to_head(page)
require 'nokogiri'
if page.output.include? "<head"
doc = Nokogiri::HTML(page.output)
head = doc.at("head")
head.add_child("<script> document.addEventListener(\"DOMContentLoaded\",()=>{const e=document.querySelectorAll(\".protect\");e.forEach(e=>{base64=e.innerHTML;if(base64.length>=2){switch(base64.slice(0,2)){case\"_e\":e.innerHTML=a(base64);e.href=\"mailto:\"+unmask;break;case\"_p\":e.innerHTML=a(base64);e.href=\"tel:\"+unmask;break;case\"_n\":e.innerHTML=a(base64);default:break}}})});function a(e){e=e.slice(2);unmask=atob(e);return unmask}</script>")
head.add_child("<noscript><style> .protect {display: none;}</style></noscript>")
page.output = doc.to_html
end
end
|