Class: Shugoi::Notice

Inherits:
Object
  • Object
show all
Defined in:
lib/shugoi/notice.rb

Overview

Injection de la notice de consentement dans le HTML rendu. Parité avec injectNoticeScript (render.ts du module Node) : la notice est injectée dans le HTML APRÈS le split-render (elle ne disparaît pas quand le render remplace le document). L'ack est décidé côté SERVEUR via /notice (machineId), pas de cookie.

Constant Summary collapse

SCRIPT =

Le script est identique au module Node (NOTICE_SCRIPT). Les placeholders mid et sk sont remplacés à l'injection (le guard n'a pas encore défini window.__sg_mid quand le HTML est rendu).

<<~'JS'
  <script>
  (function(){
    var mid=window.__sg_mid||'';
    var sk=window.__sg_siteKey||'';
    if(!mid||!sk||window.__sg_noticeEnabled===false)return;
    var base=window.__sg_baseUrl||'';
    var origin=base.replace(/\/api\/v1\/?$/,'');
    function ack(){try{fetch(base+'/notice',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({machineId:mid,siteKey:sk}),keepalive:true,signal:AbortSignal.timeout(4000)}).catch(function(){})}catch(e){}}
    function build(){var o=document.createElement('div');o.id='__sg_o';o.style.cssText='position:fixed!important;inset:0!important;z-index:2147483647!important;background:rgba(0,0,0,.6)!important;display:flex!important;align-items:center!important;justify-content:center!important;padding:1.2rem!important';var c=document.createElement('div');c.id='__sg_cd';c.style.cssText='background:#fff!important;border:4px solid #000!important;border-radius:28px 6px 32px 10px!important;box-shadow:14px 14px 0 #000!important;padding:0!important;max-width:720px!important;width:100%!important;text-align:center!important;font-family:Arial,sans-serif!important;display:flex!important;overflow:hidden!important';c.innerHTML='<div style="flex:0 0 320px;display:flex;align-items:center;justify-content:center;padding:1.5rem 1rem 1.5rem 3rem;overflow:hidden"><img src="'+origin+'/favicon.png" alt="" style="width:100%;height:auto;max-width:220px;pointer-events:none"></div><div style="flex:1;padding:1.6rem 1.8rem;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center"><img src="'+origin+'/brand-block.png" alt="Shugoi" style="display:block;margin:0 0 .3rem;pointer-events:none;max-width:100%;height:auto;max-height:40px"><div style="border:2px solid #000;display:inline-block;border-radius:8px 2px 12px 4px;padding:.2rem .6rem;font-size:.5rem;font-weight:700;text-transform:uppercase;letter-spacing:.1em;color:#E87090;margin-bottom:.6rem">Protection anti-abus</div><p style="font-size:.8rem;color:#555;line-height:1.7;margin:0 .4rem .6rem;max-width:280px">Ce site utilise Shugoi pour se protéger contre les abus et la fraude. Des caractéristiques techniques de votre navigateur sont analysées pour détecter les scripts automatisés, Tor, les VPN et les environnements virtuels. Aucune donnée personnelle n'est collectée.</p><button id="__sg_ok" style="background:#E87090;color:#fff;border:3px solid #000;border-radius:12px 3px 14px 5px;padding:.35rem 1.4rem;font-size:.8rem;font-weight:700;cursor:pointer">OK</button><div style="margin-top:.5rem;font-size:.5rem;color:#ccc"><a href="'+origin+'/legal/shugoi-notice" target="_blank" style="color:#E87090;text-decoration:underline">En savoir plus · shugoi.com</a></div></div>';o.appendChild(c);document.documentElement.appendChild(o);document.body.style.overflow='hidden';document.documentElement.style.overflow='hidden';var ok=document.getElementById('__sg_ok');if(ok)ok.onclick=function(){ack();var el=document.getElementById('__sg_o');if(el&&el.parentNode)el.parentNode.removeChild(el);document.body.style.overflow='';document.documentElement.style.overflow=''};}
    function show(){if(document.body)build();else if(document.addEventListener)document.addEventListener('DOMContentLoaded',build);else setTimeout(show,50)}
    fetch(base+'/notice?machineId='+encodeURIComponent(mid)+'&siteKey='+encodeURIComponent(sk),{signal:AbortSignal.timeout(4000)}).then(function(r){return r.json()}).then(function(d){if(!d.acknowledged)show()}).catch(function(){show()});
  })();
  </script>
JS

Class Method Summary collapse

Class Method Details

.inject(html, mid, site_key) ⇒ String

Injecte la notice dans le HTML rendu (avant ).

Parameters:

  • html (String)

    HTML rendu

  • mid (String)

    machineId du client

  • site_key (String)

    siteKey

Returns:

  • (String)

    HTML avec la notice injectée



33
34
35
36
37
38
39
40
41
42
# File 'lib/shugoi/notice.rb', line 33

def self.inject(html, mid, site_key)
  script = SCRIPT
    .gsub("var mid=window.__sg_mid||'';", "var mid=#{JSON.generate(mid)}||'';")
    .gsub("var sk=window.__sg_siteKey||'';", "var sk=#{JSON.generate(site_key)}||'';")
  if html.include?("</body>")
    html.sub("</body>", "#{script}</body>")
  else
    "#{html}#{script}"
  end
end