| 1 |
(function () { |
| 2 |
function typoCssVarsForEl(typo, prefix, el) { |
| 3 |
if (!typo || typeof typo !== 'object') return; |
| 4 |
var m = { family:'font-family', weight:'font-weight', style:'font-style', |
| 5 |
transform:'text-transform', decoration:'text-decoration', |
| 6 |
sizeDesktop:'font-size-d', sizeTablet:'font-size-t', sizeMobile:'font-size-m', sizeUnit:'font-size-unit', |
| 7 |
lineHeightDesktop:'line-height-d', lineHeightTablet:'line-height-t', lineHeightMobile:'line-height-m', lineHeightUnit:'line-height-unit', |
| 8 |
letterSpacingDesktop:'letter-spacing-d', letterSpacingTablet:'letter-spacing-t', letterSpacingMobile:'letter-spacing-m', letterSpacingUnit:'letter-spacing-unit', |
| 9 |
wordSpacingDesktop:'word-spacing-d', wordSpacingTablet:'word-spacing-t', wordSpacingMobile:'word-spacing-m', wordSpacingUnit:'word-spacing-unit' }; |
| 10 |
var su = typo.sizeUnit || 'px', lu = typo.lineHeightUnit || '', lsu = typo.letterSpacingUnit || 'px', wu = typo.wordSpacingUnit || 'px'; |
| 11 |
for (var k in m) { |
| 12 |
if (typo[k] !== undefined && typo[k] !== '') { |
| 13 |
var v = typo[k], css = m[k]; |
| 14 |
if (css === 'font-size-d' || css === 'font-size-t' || css === 'font-size-m') v = v + su; |
| 15 |
else if ((css === 'line-height-d' || css === 'line-height-t' || css === 'line-height-m') && lu) v = v + lu; |
| 16 |
else if (css === 'letter-spacing-d' || css === 'letter-spacing-t' || css === 'letter-spacing-m') v = v + lsu; |
| 17 |
else if (css === 'word-spacing-d' || css === 'word-spacing-t' || css === 'word-spacing-m') v = v + wu; |
| 18 |
el.style.setProperty(prefix + css, '' + v); |
| 19 |
} |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
var VERDICTS = { |
| 24 |
'true': { icon: '� |
| 25 |
', label: 'True', color: '#15803d', bg: '#f0fdf4', border: '#86efac', scaleIdx: 0 }, |
| 26 |
'mostly-true': { icon: '🟢', label: 'Mostly True', color: '#166534', bg: '#dcfce7', border: '#4ade80', scaleIdx: 1 }, |
| 27 |
'mixed': { icon: '🟡', label: 'Mixed', color: '#92400e', bg: '#fffbeb', border: '#fcd34d', scaleIdx: 2 }, |
| 28 |
'mostly-false': { icon: '🟠', label: 'Mostly False', color: '#9a3412', bg: '#fff7ed', border: '#fdba74', scaleIdx: 3 }, |
| 29 |
'false': { icon: '❌', label: 'False', color: '#991b1b', bg: '#fef2f2', border: '#fca5a5', scaleIdx: 4 }, |
| 30 |
'unverified': { icon: '❓', label: 'Unverified', color: '#1e3a5f', bg: '#eff6ff', border: '#93c5fd', scaleIdx: 2 }, |
| 31 |
'misleading': { icon: '⚠️', label: 'Misleading', color: '#713f12', bg: '#fefce8', border: '#fde047', scaleIdx: 3 }, |
| 32 |
'satire': { icon: '🎭', label: 'Satire', color: '#4c1d95', bg: '#f5f3ff', border: '#c4b5fd', scaleIdx: -1 } |
| 33 |
}; |
| 34 |
var SCALE_COLORS = ['#15803d', '#166534', '#a16207', '#9a3412', '#991b1b']; |
| 35 |
|
| 36 |
function init() { |
| 37 |
document.querySelectorAll('.bkbg-fck-app').forEach(function (el) { |
| 38 |
if (el.dataset.rendered) return; |
| 39 |
el.dataset.rendered = '1'; |
| 40 |
var opts; |
| 41 |
try { opts = JSON.parse(el.dataset.opts || '{}'); } catch (e) { opts = {}; } |
| 42 |
var o = Object.assign({ |
| 43 |
claim: '', verdict: 'mostly-false', explanation: '', |
| 44 |
sources: [], showSources: true, showRatingScale: true, |
| 45 |
showReviewer: false, reviewerName: '', reviewerTitle: '', reviewDate: '', |
| 46 |
openInNewTab: true, |
| 47 |
bgColor: '#ffffff', borderColor: '#e2e8f0', claimBg: '#f8fafc', |
| 48 |
claimColor: '#1e293b', labelColor: '#64748b', explanationColor: '#374151', |
| 49 |
sourceTitleColor: '#374151', sourceLinkColor: '#3b82f6', reviewerColor: '#6b7280', |
| 50 |
borderRadius: 10, paddingTop: 0, paddingBottom: 0 |
| 51 |
}, opts); |
| 52 |
|
| 53 |
var v = VERDICTS[o.verdict] || VERDICTS['mostly-false']; |
| 54 |
var target = o.openInNewTab ? '_blank' : '_self'; |
| 55 |
|
| 56 |
var outer = document.createElement('div'); |
| 57 |
outer.style.cssText = 'padding:' + o.paddingTop + 'px 0 ' + o.paddingBottom + 'px;'; |
| 58 |
|
| 59 |
var wrap = document.createElement('div'); |
| 60 |
wrap.className = 'bkbg-fck-wrap'; |
| 61 |
wrap.style.cssText = 'background:' + o.bgColor + ';border:1px solid ' + o.borderColor + ';border-radius:' + o.borderRadius + 'px;overflow:hidden;box-shadow:0 1px 6px rgba(0,0,0,.06);box-sizing:border-box;font-family:inherit;'; |
| 62 |
typoCssVarsForEl(o.typoClaim || {}, '--bkbg-fck-cl-', wrap); |
| 63 |
typoCssVarsForEl(o.typoExplanation || {}, '--bkbg-fck-ex-', wrap); |
| 64 |
|
| 65 |
/* Verdict banner */ |
| 66 |
var banner = document.createElement('div'); |
| 67 |
banner.className = 'bkbg-fck-banner'; |
| 68 |
banner.style.cssText = 'background:' + v.bg + ';border-bottom:1px solid ' + v.border + ';padding:16px 20px;display:flex;align-items:center;gap:14px;'; |
| 69 |
banner.innerHTML = |
| 70 |
'<span class="bkbg-fck-icon" style="font-size:32px;line-height:1;flex-shrink:0;">' + v.icon + '</span>' + |
| 71 |
'<div><div class="bkbg-fck-verdict-label" style="font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:' + o.labelColor + ';margin-bottom:2px;">Verdict</div>' + |
| 72 |
'<div class="bkbg-fck-verdict-text" style="font-size:20px;font-weight:800;color:' + v.color + ';">' + esc(v.label) + '</div></div>'; |
| 73 |
wrap.appendChild(banner); |
| 74 |
|
| 75 |
/* Rating scale */ |
| 76 |
if (o.showRatingScale) { |
| 77 |
var scale = document.createElement('div'); |
| 78 |
scale.className = 'bkbg-fck-scale'; |
| 79 |
scale.style.cssText = 'display:flex;gap:4px;padding:12px 20px;background:#f8fafc;border-bottom:1px solid ' + o.borderColor + ';'; |
| 80 |
for (var si = 0; si < 5; si++) { |
| 81 |
var seg = document.createElement('div'); |
| 82 |
seg.style.cssText = 'flex:1;height:8px;border-radius:4px;background:' + (si === v.scaleIdx ? SCALE_COLORS[si] : (si < (v.scaleIdx || 0) ? SCALE_COLORS[si] + '55' : '#e2e8f0')) + ';'; |
| 83 |
scale.appendChild(seg); |
| 84 |
} |
| 85 |
wrap.appendChild(scale); |
| 86 |
} |
| 87 |
|
| 88 |
/* Claim */ |
| 89 |
if (o.claim) { |
| 90 |
var claimSec = document.createElement('div'); |
| 91 |
claimSec.className = 'bkbg-fck-claim'; |
| 92 |
claimSec.style.cssText = 'background:' + o.claimBg + ';border-bottom:1px solid ' + o.borderColor + ';padding:14px 20px;'; |
| 93 |
claimSec.innerHTML = |
| 94 |
'<div class="bkbg-fck-section-label" style="font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:' + o.labelColor + ';margin-bottom:6px;">Claim</div>' + |
| 95 |
'<p class="bkbg-fck-claim-text" style="color:' + o.claimColor + ';margin:0;">' + o.claim + '</p>'; |
| 96 |
wrap.appendChild(claimSec); |
| 97 |
} |
| 98 |
|
| 99 |
/* Analysis */ |
| 100 |
if (o.explanation) { |
| 101 |
var hasSources = o.showSources && o.sources && o.sources.length > 0; |
| 102 |
var expSec = document.createElement('div'); |
| 103 |
expSec.className = 'bkbg-fck-explanation'; |
| 104 |
expSec.style.cssText = 'padding:16px 20px;' + (hasSources ? 'border-bottom:1px solid ' + o.borderColor + ';' : ''); |
| 105 |
expSec.innerHTML = |
| 106 |
'<div class="bkbg-fck-section-label" style="font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:' + o.labelColor + ';margin-bottom:8px;">Our Analysis</div>' + |
| 107 |
'<div class="bkbg-fck-explanation-body" style="color:' + o.explanationColor + ';">' + o.explanation + '</div>'; |
| 108 |
wrap.appendChild(expSec); |
| 109 |
} |
| 110 |
|
| 111 |
/* Sources */ |
| 112 |
if (o.showSources && o.sources && o.sources.length) { |
| 113 |
var srcSec = document.createElement('div'); |
| 114 |
srcSec.className = 'bkbg-fck-sources'; |
| 115 |
srcSec.style.cssText = 'padding:14px 20px;background:#fafafa;' + (o.showReviewer && (o.reviewerName || o.reviewDate) ? 'border-bottom:1px solid ' + o.borderColor + ';' : ''); |
| 116 |
var srcHtml = '<div class="bkbg-fck-section-label" style="font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:' + o.labelColor + ';margin-bottom:8px;">Sources</div><ol style="margin:0;padding-left:18px;">'; |
| 117 |
o.sources.forEach(function (s) { |
| 118 |
srcHtml += '<li style="margin-bottom:4px;font-size:13px;">'; |
| 119 |
if (s.url) { |
| 120 |
srcHtml += '<a href="' + esc(s.url) + '" target="' + target + '" rel="noopener noreferrer" class="bkbg-fck-source-link" style="color:' + o.sourceLinkColor + ';text-decoration:none;">' + esc(s.title) + '</a>'; |
| 121 |
} else { |
| 122 |
srcHtml += '<span style="color:' + o.sourceTitleColor + ';">' + esc(s.title) + '</span>'; |
| 123 |
} |
| 124 |
srcHtml += '</li>'; |
| 125 |
}); |
| 126 |
srcHtml += '</ol>'; |
| 127 |
srcSec.innerHTML = srcHtml; |
| 128 |
wrap.appendChild(srcSec); |
| 129 |
} |
| 130 |
|
| 131 |
/* Reviewer */ |
| 132 |
if (o.showReviewer && (o.reviewerName || o.reviewDate)) { |
| 133 |
var rev = document.createElement('div'); |
| 134 |
rev.className = 'bkbg-fck-reviewer'; |
| 135 |
rev.style.cssText = 'padding:10px 20px;background:#f8fafc;border-top:1px solid ' + o.borderColor + ';display:flex;align-items:center;justify-content:space-between;gap:12px;font-size:12px;color:' + o.reviewerColor + ';'; |
| 136 |
var nameStr = o.reviewerName + (o.reviewerTitle ? ' · ' + o.reviewerTitle : ''); |
| 137 |
rev.innerHTML = '<span>' + esc(nameStr) + '</span>' + (o.reviewDate ? '<span>� |
| 138 |
' + esc(o.reviewDate) + '</span>' : ''); |
| 139 |
wrap.appendChild(rev); |
| 140 |
} |
| 141 |
|
| 142 |
outer.appendChild(wrap); |
| 143 |
el.parentNode.insertBefore(outer, el); |
| 144 |
}); |
| 145 |
} |
| 146 |
|
| 147 |
function esc(str) { |
| 148 |
return String(str || '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); |
| 149 |
} |
| 150 |
|
| 151 |
if (document.readyState !== 'loading') { init(); } |
| 152 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 153 |
})(); |
| 154 |
|