/* ===== INIT ===== */
window.requestIdleCallback ? requestIdleCallback(initGC) : setTimeout(initGC, 1000);
function initGC() {
/* ===== CLOCK ===== */
function updateClock() {
const now = new Date();
document.getElementById(“gc-date”).innerText = now.toLocaleDateString(“pt-BR”);
document.getElementById(“gc-time”).innerText =
now.toLocaleTimeString(“pt-BR”,{hour:’2-digit’,minute:’2-digit’});
}
updateClock();
setInterval(updateClock, 1000);
/* ===== ATIVOS ===== */
const assets = [
{ label:”IBOV”, key:”IBOV”, format:v => v.toLocaleString(“pt-BR”)+” pts” },
{ label:”DÓLAR”, key:”DOLAR”, format:v => “R$ “+v.toFixed(2).replace(“.”,”,”) },
{ label:”BTC”, key:”BTC”, format:v => “US$ “+v.toLocaleString(“pt-BR”) },
{ label:”BRENT”, key:”BRENT”, format:v => “US$ “+v.toFixed(2) },
{ label:”WTI”, key:”WTI”, format:v => “US$ “+v.toFixed(2) },
{ label:”OURO”, key:”OURO”, format:v => “US$ “+v.toFixed(2) },
{ label:”PETR4″, key:”PETR4”, format:v => “R$ “+v.toFixed(2).replace(“.”,”,”) },
{ label:”VALE3″, key:”VALE3″, format:v => “R$ “+v.toFixed(2).replace(“.”,”,”) },
{ label:”ITUB4″, key:”ITUB4″, format:v => “R$ “+v.toFixed(2).replace(“.”,”,”) },
{ label:”BBDC4″, key:”BBDC4″, format:v => “R$ “+v.toFixed(2).replace(“.”,”,”) },
{ label:”BBAS3″, key:”BBAS3″, format:v => “R$ “+v.toFixed(2).replace(“.”,”,”) },
{ label:”WEGE3″, key:”WEGE3″, format:v => “R$ “+v.toFixed(2).replace(“.”,”,”) }
];
const layers = [
document.getElementById(“t1”),
document.getElementById(“t2”),
document.getElementById(“t3”)
];
let index = 0;
let running = false;
let lastFeed = null;
/* ===== FETCH FEED ===== */
async function fetchMarketFeed() {
try {
const controller = new AbortController();
setTimeout(() => controller.abort(), 3000);
const res = await fetch(MARKET_API, {
cache: “no-store”,
signal: controller.signal
});
const json = await res.json();
return json.data;
} catch (err) {
console.warn(“Feed indisponível, usando último cache”);
return null;
}
}
/* ===== BUILD HTML ===== */
function buildHTML(asset, feed) {
let value=”–“, pctText=”–“, pctClass=””;
if (feed && feed[asset.key]) {
const item = feed[asset.key];
const last = item.price;
const pct = item.change;
value = asset.format(last);
pctText = (pct>=0?’+’:”)+pct.toFixed(2).replace(‘.’,’,’)+”%”;
pctClass = pct>=0 ? “up” : “down”;
}
return `
${asset.label}
${value}
${pctText}
`;
}
/* ===== RENDER ===== */
async function renderTickers() {
if (running) return;
running = true;
layers.forEach(l => {
l.classList.remove(“show”);
l.classList.add(“exit”);
});
await new Promise(r => setTimeout(r, 600));
const feed = await fetchMarketFeed();
if (feed) lastFeed = feed;
const trio = [0,1,2].map(i => assets[(index + i) % assets.length]);
for (let i = 0; i
O post Widget BM&C apareceu primeiro em BM&C NEWS.
