Realitatea

Categorii
Uncategorized

Preview bannere

Cod banner (HTML / script)
Previzualizare
preview banner

Lipește codul și apasă
Previzualizează

'); doc.close();// Măsurare repetată: bannerele externe se randează asincron var attempts = 0; var lastW = 0, lastH = 0, stableCount = 0; window._bptMeasureTimer = setInterval(function(){ attempts++; var idoc; try { idoc = iframe.contentDocument || iframe.contentWindow.document; } catch(e){ return; } if(!idoc || !idoc.body){ return; }var m = measureRendered(idoc);if(m.w >= 10 && m.h >= 10){ // așteaptă 2 măsurători identice (dimensiune stabilă) if(m.w === lastW && m.h === lastH){ stableCount++; if(stableCount >= 2){ applySize(m.w, m.h); clearInterval(window._bptMeasureTimer); window._bptMeasureTimer = null; return; } } else { stableCount = 0; applySize(m.w, m.h); // aplică provizoriu, preview se ajustează în timp real } lastW = m.w; lastH = m.h; }if(attempts >= 30){ // oprire după ~6 secunde if(lastW >= 10 && lastH >= 10){ applySize(lastW, lastH); } clearInterval(window._bptMeasureTimer); window._bptMeasureTimer = null; } }, 200); };window.bptSaveImage = function(){ var btn = document.getElementById('bpt-save-btn'); var iframe = document.getElementById('bpt-iframe'); if(!iframe){ alert('Întâi încarcă un banner în previzualizare.'); return; }var origText = btn.innerHTML; btn.innerHTML = '⏳ Se procesează...'; btn.disabled = true;var iW = window._bptDims.w || 600; var iH = window._bptDims.h || 500; var fileName = 'banner-' + iW + 'x' + iH + '-' + Date.now() + '.png';try { var idoc = iframe.contentDocument || iframe.contentWindow.document; html2canvas(idoc.body, { useCORS: true, allowTaint: true, backgroundColor: '#ffffff', width: iW, height: iH, scale: 1, logging: false }).then(function(canvas){ canvas.toBlob(function(blob){ if(!blob){ throw new Error('blob null'); } var url = URL.createObjectURL(blob); var a = document.createElement('a'); a.href = url; a.download = fileName; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); btn.innerHTML = '✓ Salvat!'; setTimeout(function(){ btn.innerHTML = origText; btn.disabled = false; }, 2000); }, 'image/png'); }).catch(function(err){ handleCaptureError(btn, origText, err); }); } catch(e){ handleCaptureError(btn, origText, e); } };function handleCaptureError(btn, origText, err){ console.error('Banner capture error:', err); btn.innerHTML = '✗ Banner extern protejat'; alert('Acest banner este încărcat dintr-o sursă externă (cross-origin) și nu poate fi capturat din motive de securitate ale browserului.\n\nCaptura funcționează pentru bannerele găzduite local. Pentru bannere externe Bannerflow, folosește un screenshot manual.'); setTimeout(function(){ btn.innerHTML = origText; btn.disabled = false; }, 2500); }window.bptToggleChangelog = function(){ var cl = document.getElementById('bpt-changelog'); var btn = document.querySelector('.bpt-changelog-toggle'); if(cl.style.display === 'none'){ cl.style.display = 'block'; btn.innerHTML = 'Changelog ▴'; } else { cl.style.display = 'none'; btn.innerHTML = 'Changelog ▾'; } };window.bptClear = function(){ if(window._bptMeasureTimer){ clearInterval(window._bptMeasureTimer); window._bptMeasureTimer = null; } document.getElementById('bpt-code').value=''; var body = document.getElementById('bpt-body'); body.style.height = ''; body.style.minHeight = ''; body.innerHTML='

Lipește codul și apasă
Previzualizează

'; document.getElementById('bpt-toplabel').textContent='preview banner'; document.getElementById('bpt-size').textContent=''; document.getElementById('bpt-badge').style.display='none'; document.getElementById('bpt-save-btn').style.display='none'; }; })();