1/*! 2* Hello Rodolfo â MicroEvents Injector 3* 4* Ascolta evento maitre-aggiornato, rileva micro-event vincente, 5* inietta frase nel hero (o cover se Story attiva o flag config). 6* 7* Copyright © 2026 Ivanov Hristo. All rights reserved. 8* Proprietary license â Unauthorized use prohibited. 9*/ 10(function() { 11'use strict'; 12 13if (!window.DH_MICRO_EVENTS || !window.DH_MICRO_EVENTS.enabled) return; 14if (!window.DH_MicroEvents) return; 15 16var CFG = window.DH_MICRO_EVENTS; 17 18function getCurrentLang() { 19return document.documentElement.getAttribute('data-dh-lang') || 'it'; 20} 21 22function buildContext() { 23var ctx = { now: new Date(), weather: null, citta: '', cittaLoc: '' }; 24 25var cfgEl = document.getElementById('config'); 26if (cfgEl) { 27 ctx.citta = cfgEl.dataset.citta || ''; 28 ctx.cittaLoc = cfgEl.dataset.cittaLocativo || ctx.citta || ''; 29} 30 31if (window.DH_Maitre && typeof window.DH_Maitre.getWeather === 'function') { 32 ctx.weather = window.DH_Maitre.getWeather(); 33} 34 35// Fallback: leggi temperatura da box meteo-live se presente 36if (!ctx.weather) { 37 var meteoBox = document.getElementById('meteo-live'); 38 if (meteoBox) { 39 var t = (meteoBox.innerText || '').match(/(-?\d+)\s*°/); 40 if (t) ctx.weather = { temp: parseInt(t[1], 10), isRain: false, isSnow: false, isThunder: false, isHot: false, isCold: false, isCloudy: false }; 41 } 42} 43 44return ctx; 45} 46 47function ensureSentenceEnd(s) { 48if (!s) return s; 49s = s.replace(/[.\s]+$/, ''); 50return s + '.'; 51} 52 53function alreadyInjected(el, attr, text) { 54if (!el || !text) return false; 55var current = el.getAttribute(attr) || ''; 56var marker = text.substring(0, Math.min(20, text.length)); 57return current.indexOf(marker) === 0; 58} 59 60function injectIntoAttr(el, attr, text) { 61if (!el || !text) return false; 62if (alreadyInjected(el, attr, text)) return false; 63var orig = el.getAttribute(attr) || ''; 64el.setAttribute(attr, ensureSentenceEnd(text) + ' ' + orig); 65return true; 66} 67 68function injectIntoVisibleMaitre(text) { 69var mt = document.getElementById('maitre-testo'); 70if (!mt) return false; 71if (window.scrollY > window.innerHeight / 2) return false; 72var orig = mt.innerText || ''; 73if (orig.indexOf(text.substring(0, Math.min(20, text.length))) === 0) return false; 74mt.innerText = ensureSentenceEnd(text) + ' ' + orig; 75return true; 76} 77 78function storyIsActive() { 79return !!(window.DH_STORY && window.DH_STORY.isValid); 80} 81 82function inject() { 83var ctx = buildContext(); 84var winner = window.DH_MicroEvents.detect(ctx); 85if (!winner) return; 86 87var lang = getCurrentLang(); 88var phrase = window.DH_MicroEvents.pickPhrase(winner, lang); 89if (!phrase) return; 90 91phrase = window.DH_MicroEvents.interpolate(phrase, ctx); 92if (!phrase) return; 93 94var heroEl = document.getElementById('hero'); 95if (!heroEl) return; 96 97var injected = false; 98 99// Logica posizionamento: 100// - Se Story attiva â micro-event va in COVER (per evitare doppio prefix nel hero) 101// - Se config show_in_cover=true â COVER 102// - Altrimenti â HERO 103var useCover = storyIsActive() || !!CFG.showInCover; 104 105if (useCover && heroEl.hasAttribute('data-cover')) { 106 injected = injectIntoAttr(heroEl, 'data-cover', phrase) || injected; 107} 108 109if (!useCover && CFG.showInHero) { 110 injected = injectIntoAttr(heroEl, 'data-testo', phrase) || injected; 111 injectIntoVisibleMaitre(phrase); 112} 113 114if (injected) { 115 window.DH_MicroEvents.recordShown(winner.slug); 116 117 try { 118 document.dispatchEvent(new CustomEvent('dh:microevent-injected', { 119 detail: { slug: winner.slug, phrase: phrase, lang: lang, target: useCover ? 'cover' : 'hero' } 120 })); 121 } catch (e) {} 122 123 if (window.DH_DEBUG) { 124 console.log('[DH MicroEvents] Injected:', winner.slug, 'â', useCover ? 'cover' : 'hero', '|', phrase); 125 } 126} 127} 128 129// Hook su evento maitre-aggiornato 130document.addEventListener('maitre-aggiornato', inject); 131 132// Trigger immediato se maitre ha già completato prima del listener 133if (document.readyState === 'complete' || document.readyState === 'interactive') { 134setTimeout(inject, 50); 135} 136 137if (window.DH_DEBUG) { 138console.log('[DH MicroEvents Injector v1.0.0] Ready.'); 139} 140})();
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.