// Site assistant widget (2026-11-15): a round button bottom right, a panel that asks /api/chat. The look is this site's own,
// in /assets/chat.css (colors and fonts from the site's stylesheet). When an answer cannot help, or the visitor asks for a
// person, it offers "Open network support": InstantAdPay's support desk, which already knows the question and the site.
// The SAME file ships in ViralAdBlitz, DownlineHydra, 5xYourTeam, Viral Banner Blitz, Downline Banners and Stack POL.
(function () {
if (window.__siteChat || /^\/admin/.test(location.pathname)) return;
window.__siteChat = 1;
var css = document.createElement('link'); css.rel = 'stylesheet'; css.href = '/assets/chat.css?v=20261115d'; document.head.appendChild(css);
var NAME = 'this site', TOPICS = [];
var root = document.createElement('div'); root.id = 'scChat';
root.innerHTML = ''
+ ' '
+ '
';
document.body.appendChild(root);
var $ = function (id) { return document.getElementById(id); };
var msgs = $('scMsgs'), input = $('scIn'), panel = $('scPanel'), btn = $('scBtn');
var history = [], greeted = false, support = 'https://instantadpay.com/support';
fetch('/api/chat/config').then(function (r) { return r.json(); }).then(function (c) {
if (c.name) { NAME = c.name; $('scTitle').textContent = 'Ask ' + c.name; }
if (c.support) { support = c.support; $('scHuman').href = c.support; }
TOPICS = c.topics || [];
}).catch(function () {});
function esc(s) { return String(s).replace(/[&<>"]/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"' }[c]; }); }
function add(text, who) {
var d = document.createElement('div'); d.className = 'sc-m ' + who;
d.innerHTML = esc(text).replace(/(https?:\/\/[^\s<]+[^\s<.,;:!?)])/g, '$1 ');
msgs.appendChild(d); msgs.scrollTop = msgs.scrollHeight; return d;
}
function offer(link) {
var old = msgs.querySelector('.sc-handoff'); if (old) old.remove();
var d = document.createElement('div'); d.className = 'sc-m bot sc-handoff';
var a = document.createElement('a'); a.className = 'sc-cta'; a.href = link || support; a.target = '_blank'; a.rel = 'noopener'; a.textContent = 'Open network support';
d.appendChild(a); msgs.appendChild(d); msgs.scrollTop = msgs.scrollHeight;
}
function open() {
panel.hidden = false; btn.setAttribute('aria-expanded', 'true'); root.className = 'open';
if (!greeted) {
greeted = true;
add('Hi. Ask me how ' + NAME + ' works, what it costs, how payouts work, or about any other site in the network. Straight answers, no income hype.', 'bot');
var t = $('scTopics'); TOPICS.slice(0, 4).forEach(function (q) {
var b = document.createElement('button'); b.type = 'button'; b.textContent = q; b.addEventListener('click', function () { input.value = q; send(); }); t.appendChild(b);
});
}
setTimeout(function () { input.focus(); }, 50);
}
function close() { panel.hidden = true; btn.setAttribute('aria-expanded', 'false'); root.className = ''; }
btn.addEventListener('click', function () { panel.hidden ? open() : close(); });
$('scClose').addEventListener('click', close);
document.addEventListener('keydown', function (e) { if (e.key === 'Escape' && !panel.hidden) close(); });
async function send() {
var q = input.value.trim(); if (!q) return;
input.value = ''; $('scTopics').innerHTML = '';
add(q, 'me'); var wait = add('...', 'bot wait');
try {
var r = await (await fetch('/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: q, history: history.slice(-6) }) })).json();
wait.remove();
add(r.reply || r.error || 'Something went wrong. Try again in a moment.', 'bot');
history.push(q, r.reply || '');
if (r.handoff) offer(r.support);
} catch (e) { wait.remove(); add('I could not reach the assistant just now. Try again in a moment, or open network support.', 'bot'); offer(); }
}
$('scForm').addEventListener('submit', function (e) { e.preventDefault(); send(); });
})();