~gg/blog-theme

2d1712d86f2d3241d2a048bcef568ba270897681 — Gui Goncalves 3 months ago e1e08ff
Fix issue where "disable JS" banner was visible with uBO

This is because some JS blockers act at the network level, and thus don't
prevent JS execution that is inlined.
2 files changed, 13 insertions(+), 12 deletions(-)

M layouts/partials/noscript.html
A static/js/show-banner.js
M layouts/partials/noscript.html => layouts/partials/noscript.html +2 -12
@@ 1,3 1,4 @@
<script src="{{ .Site.BaseURL }}js/show-banner.js"></script>
<script type="text/javascript">
 function ready(fn) {
   if (document.readyState != 'loading'){


@@ 6,17 7,6 @@
     document.addEventListener('DOMContentLoaded', fn);
   }
 }
 ready(() => {
   const h1 = document.createElement('h1');
   const a = document.createElement('a');

   h1.innerText = 'Please disable JavaScript';
   h1.id = 'disable-js-banner';
   a.setAttribute('href', '{{ .Site.Params.noJSLink }}');
   a.appendChild(h1);

   document.body.appendChild(a);
 });

 ready(() => showBanner('{{ .Site.Params.noJSLink }}'));
</script>
<script src="{{ .Site.BaseURL }}{{ .Site.Params.uselessJSFile }}"></script>

A static/js/show-banner.js => static/js/show-banner.js +11 -0
@@ 0,0 1,11 @@
window.showBanner = (href) => {
  const h1 = document.createElement('h1');
  const a = document.createElement('a');

  h1.innerText = 'Please disable JavaScript';
  h1.id = 'disable-js-banner';
  a.setAttribute('href', href);
  a.appendChild(h1);

  document.body.appendChild(a);
}