Files
linkspin/public/assets/fuel.js
T

42 lines
3.7 KiB
JavaScript

// Fuel Your Offers (2026-10-24), LinkSpin: the Monthly Refuel panel on Credits and Ads. The streak lives on InstantAdPay
// and is shared by both sites; /api/my/refuel relays InstantAdPay's view. Hidden while the refuelStreak switch is off.
(function () {
const $ = id => document.getElementById(id);
const esc = s => String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
const n = v => Number(v || 0).toLocaleString('en-US');
window.FUEL = window.FUEL || {};
function site(name, s, minUsd) {
return s && s.refueled ? '<div class="row"><span>' + name + '</span><b>+' + s.pct + '% &middot; ' + n(s.bonus) + ' credits</b></div>'
: '<div class="row"><span>' + name + '</span><span class="muted">not yet ($' + minUsd + '+ counts)</span></div>';
}
function body(v) {
if (v.error) return '<p class="muted">' + esc(v.error) + '</p>';
if (!v.active) {
return '<p style="margin:0 0 8px">' + (v.started ? 'Your last streak ended. ' : '') + 'A package of <b>$' + v.minUsd.linkspin + ' or more</b> here, or $' + v.minUsd.iap + '+ on InstantAdPay, ' + (v.started ? 'starts it again' : 'starts your monthly refuel streak and sets your own refuel day') + '.</p>'
+ '<p class="muted" style="margin:0 0 10px">Bonus ad credits: month 1 +' + v.ladder.single[0] + '%, then +' + v.ladder.single.slice(1).join('%, +') + '%. Refuel both sites in the same cycle and each gets +' + v.ladder.both.join('%, +') + '%.</p>'
+ '<a class="btn pri" href="/credits">Start my streak</a>';
}
const c = v.cycle || {};
let h = v.windowOpen
? '<p style="margin:0 0 8px"><b>Your refuel window is open.</b> Refuel day <b>' + esc(v.refuelDayLabel) + '</b>, grace to ' + esc(v.graceLabel) + ' (Central). Next refuel: +' + v.next.single + '%, or +' + v.next.both + '% on each site with both.</p>'
: '<p style="margin:0 0 8px">Next refuel day <b>' + esc(v.refuelDayLabel) + '</b> (Central). Window opens ' + esc(v.opensLabel) + ', grace to ' + esc(v.graceLabel) + '.</p>';
if (c.month) h += '<div style="margin:0 0 8px">' + site('InstantAdPay', c.iap, v.minUsd.iap) + site('LinkSpin', c.linkspin, v.minUsd.linkspin) + '</div>';
if (!v.windowOpen && c.month && !c.both) h += '<p class="muted" style="margin:0 0 8px">Refuel ' + (c.linkspin && c.linkspin.refueled ? 'InstantAdPay ($' + v.minUsd.iap + '+)' : 'LinkSpin ($' + v.minUsd.linkspin + '+)') + ' before ' + esc(v.opensLabel) + ' and both sites move to +' + v.next.secondEngine + '%.</p>';
if (v.pitStop && (v.pitStop.linkspin || v.pitStop.usedLinkspin)) h += '<p class="muted" style="margin:0 0 8px"><b>Pit Stop</b> ' + (v.pitStop.linkspin ? 'available here: +' + v.pitStop.pct + '% on a $' + v.minUsd.linkspin + '+ top-up, once this cycle. It does not count as your refuel.' : 'used here this cycle.') + '</p>';
h += '<p class="muted" style="margin:0 0 10px">' + (v.freeMiss.available ? 'One free miss left this year.' : 'Free miss for this year used.') + '</p>';
return h + '<a class="btn' + (v.windowOpen ? ' pri' : '') + '" href="/credits">' + (v.windowOpen ? 'Refuel now' : 'Buy a package') + '</a>';
}
async function load() {
const panel = $('rfPanel'); if (!panel) return;
try {
const v = await (await fetch('/api/my/refuel', { cache: 'no-store' })).json();
window.FUEL.refuel = v;
if (!v || !v.on) { panel.hidden = true; return; }
$('rfMeta').textContent = v.active ? 'streak: ' + v.streak + ' month' + (v.streak === 1 ? '' : 's') : 'shared with InstantAdPay';
$('rfBody').innerHTML = body(v); panel.hidden = false;
} catch (e) { panel.hidden = true; }
}
window.FUEL.loadRefuel = load;
load(); setInterval(load, 300000);
})();