File: //var/tmp/fix_reveal_safety.py
path = "/home/kohlsol/public_html/wp-content/themes/brooklyn-child/functions.php"
with open(path) as f:
fn = f.read()
old = """\tdocument.addEventListener('DOMContentLoaded', function () {
\t\tif (!('IntersectionObserver' in window)) {
\t\t\tdocument.querySelectorAll('.kohl-reveal').forEach(function (el) {
\t\t\t\tel.classList.add('kohl-revealed');
\t\t\t});
\t\t\treturn;
\t\t}
\t\tvar observer = new IntersectionObserver(function (entries) {
\t\t\tentries.forEach(function (entry) {
\t\t\t\tif (entry.isIntersecting) {
\t\t\t\t\tentry.target.classList.add('kohl-revealed');
\t\t\t\t\tobserver.unobserve(entry.target);
\t\t\t\t}
\t\t\t});
\t\t}, { threshold: 0.15, rootMargin: '0px 0px -60px 0px' });
\t\tdocument.querySelectorAll('.kohl-reveal').forEach(function (el) {
\t\t\tobserver.observe(el);
\t\t});
\t});"""
new = """\tdocument.addEventListener('DOMContentLoaded', function () {
\t\tvar items = document.querySelectorAll('.kohl-reveal');
\t\t/* Rede de seguranca: NADA fica invisivel para sempre, mesmo se o
\t\t IntersectionObserver falhar ou nunca disparar (viewport muito alto,
\t\t captura de tela automatizada, navegador sem suporte). Achado real
\t\t em teste: 14 de 15 elementos ficaram presos em opacity:0. */
\t\tvar safety = setTimeout(function () {
\t\t\titems.forEach(function (el) { el.classList.add('kohl-revealed'); });
\t\t}, 1200);
\t\tif (!('IntersectionObserver' in window)) {
\t\t\titems.forEach(function (el) { el.classList.add('kohl-revealed'); });
\t\t\treturn;
\t\t}
\t\tvar observer = new IntersectionObserver(function (entries) {
\t\t\tentries.forEach(function (entry) {
\t\t\t\tif (entry.isIntersecting) {
\t\t\t\t\tentry.target.classList.add('kohl-revealed');
\t\t\t\t\tobserver.unobserve(entry.target);
\t\t\t\t}
\t\t\t});
\t\t}, { threshold: 0, rootMargin: '0px 0px 200px 0px' });
\t\titems.forEach(function (el) { observer.observe(el); });
\t});"""
assert fn.count(old) == 1, "padrao nao encontrado"
fn = fn.replace(old, new)
with open(path, "w") as f:
f.write(fn)
print("rede de seguranca adicionada ao reveal")