PageSourceSearch

https://www.83-629.fr/reglementation/api/blog-quiz/cta.js

js 83-629.fr collected 2026-10-02 11:58:47 UTC 3,743 bytes, 57 lines download raw bytes

1/* 83-629.fr - Mini-QCM dissonance · injecteur widget blog (Phase 3.5.3.b) */
2(function(){
3  if (window.__bq83629_injected) return;
4  window.__bq83629_injected = true;
5  var pathname = location.pathname || '';
6  var m = pathname.match(/^\/([a-z0-9-]+)\/?$/i);
7  if (!m) return;
8  var slug = m[1];
9  if (/^(tag|author|search|sitemap|rss|feed|admin|signin|signup|portal|members?|404|abonnement|profil|tarifs|contact)$/.test(slug)) return;
10  var apiBase = 'https://www.83-629.fr';
11  fetch(apiBase + '/reglementation/api/blog-quiz/has/' + encodeURIComponent(slug), { credentials: 'omit' })
12    .then(function(r){ return r.ok ? r.json() : null; })
13    .then(function(j){
14      if (!j || !j.has) return;
15      var target = document.querySelector('.gh-content') || document.querySelector('.post-content') || document.querySelector('article .article-content') || document.querySelector('article');
16      if (!target) return;
17      if (document.getElementById('mini-qcm-widget')) return;
18      var ph = document.createElement('div');
19      ph.id = 'mini-qcm-widget';
20      ph.setAttribute('data-post-slug', j.slug);
21      // Placeholder du widget : on l'insère AVANT le bloc « articles suivants »
22      // (donc plus haut, plus vu), sinon en fin de conteneur article.
23      var morePosts = document.querySelector('.gh-post-page__more-posts, .gh-post-page__more, .post-full-footer, .read-next');
24      if (morePosts && morePosts.parentNode) morePosts.parentNode.insertBefore(ph, morePosts);
25      else target.appendChild(ph);
26      // Teaser en cours d'article : encart cliquable inséré après ~40 % des paragraphes
27      // du corps, qui amène au test. Pur HTML, aucun appel API supplémentaire.
28      try {
29        if (!document.getElementById('mqcm-teaser-inline')) {
30          var ps = target.querySelectorAll(':scope > p');
31          if (ps && ps.length >= 6) {
32            var idx = Math.min(ps.length - 1, Math.max(2, Math.round(ps.length * 0.4)));
33            var anchor = ps[idx];
34            var t = document.createElement('div');
35            t.id = 'mqcm-teaser-inline';
36            t.setAttribute('style', 'margin:24px 0;padding:16px 18px;border:1px solid #C7D2E3;border-left:4px solid #1e3a8a;border-radius:10px;background:#F3F6FB;font-family:Inter,system-ui,-apple-system,sans-serif');
37            t.innerHTML = '<div style="font-weight:700;color:#0E1A2B;margin-bottom:4px">\u23f1\ufe0f Tu maîtrises ce sujet ? Teste ta veille en 2 min</div>' +
38              '<div style="font-size:.9rem;color:#2C3A4E;margin-bottom:10px">5 questions chrono - et vois où ton intuition diffère du droit.</div>' +
39              '<button type="button" id="mqcm-teaser-btn" style="cursor:pointer;border:none;border-radius:8px;padding:9px 16px;font-weight:600;color:#fff;background:linear-gradient(135deg,#1e3a8a,#0f1e4f)">Faire le test \u2192</button>';
40            if (anchor && anchor.parentNode) anchor.parentNode.insertBefore(t, anchor.nextSibling);
41            var tb = document.getElementById('mqcm-teaser-btn');
42            if (tb) tb.addEventListener('click', function(){
43              try { if (typeof window.gtag === 'function') window.gtag('event', 'blog_quiz_teaser_clicked', { post_slug: j.slug }); } catch(_) {}
44              var w = document.getElementById('mini-qcm-widget');
45              if (w && w.scrollIntoView) w.scrollIntoView({ behavior: 'smooth', block: 'start' });
46            });
47          }
48        }
49      } catch (_e) {}
50      // Charge le bundle widget (intro + auto-advance + score + corrections + sticky card)
51      var s = document.createElement('script');
52      s.src = apiBase + '/reglementation/api/quiz-widget.js';
53      s.defer = true;
54      document.body.appendChild(s);
55    })
56    .catch(function(){});
57})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.