Site assistant (Marty 2026-11-15): chat widget in the ViralAdBlitz look on every page, CANNED + FACTS from this repo's code (Boost $5/500 views, 10% x 5 + 50% company, 20 places, 30-day delivery, ad limits, verified views), retrieval over the shared network knowledge base on the hub (netkb.js publishes this site's entries and reads the others', home entries boosted), OpenRouter deepseek-v4-flash with reasoning off, account problems hand off to network support. kb.json is a MySQL document. qa/chatbot.test.mjs 195 pass, smoke 198/198

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 12:40:33 -06:00
parent 56316c0139
commit d6e36a65bc
24 changed files with 950 additions and 3 deletions
+37
View File
@@ -0,0 +1,37 @@
/* Site assistant widget, ViralAdBlitz look (vab.css): royal header, white clipped-corner panel, red send, gold chips.
Variables fall back to the same values so the widget looks right even before vab.css has loaded. */
#scChat{--sc-bg:var(--card,#fff);--sc-ink:var(--ink,#0A1F6B);--sc-sub:var(--sub,#3E4C7A);--sc-head:var(--royal,#0A1F6B);--sc-head-ink:#fff;
--sc-accent:var(--red,#E3141E);--sc-accent-ink:#fff;--sc-me:var(--royal2,#12308F);--sc-me-ink:#fff;--sc-bot:var(--tint,#E1EBFF);--sc-line:var(--line,#C9D6F5);
--sc-chip:var(--gtint,#FFF3CC);--sc-chip-ink:var(--gold-ink,#7A5B00);--sc-gold:var(--gold,#FFC21A);
--sc-font:var(--body,Inter,system-ui,sans-serif);--sc-headfont:var(--head,'Chakra Petch',system-ui,sans-serif);--sc-cut:polygon(0 0,calc(100% - 14px) 0,100% 14px,100% 100%,14px 100%,0 calc(100% - 14px));
position:fixed;right:18px;bottom:18px;z-index:80;font-family:var(--sc-font)}
#scBtn{width:58px;height:58px;border:0;cursor:pointer;background:var(--sc-accent);color:var(--sc-accent-ink);display:flex;align-items:center;justify-content:center;
clip-path:polygon(0 0,calc(100% - 12px) 0,100% 12px,100% 100%,12px 100%,0 calc(100% - 12px));box-shadow:0 6px 18px rgba(6,26,102,.35)}
#scBtn:hover{background:#C70F18}
#scBtn:focus-visible{outline:3px solid var(--sc-gold);outline-offset:3px}
#scChat.open #scBtn{background:var(--sc-head)}
#scPanel{position:absolute;right:0;bottom:72px;width:370px;max-width:calc(100vw - 32px);height:540px;max-height:calc(100vh - 110px);display:flex;flex-direction:column;
background:var(--sc-bg);color:var(--sc-ink);clip-path:var(--sc-cut);border:1px solid var(--sc-line);box-shadow:0 18px 48px rgba(6,26,102,.3)}
.sc-head{display:flex;align-items:flex-start;gap:10px;padding:14px 16px;background:var(--sc-head);color:var(--sc-head-ink);border-bottom:3px solid var(--sc-gold)}
.sc-head>div{flex:1;min-width:0}
.sc-title{display:block;font-family:var(--sc-headfont);font-size:18px;letter-spacing:.02em}
.sc-sub{display:block;font-size:12.5px;opacity:.8}
#scClose{background:transparent;border:0;color:inherit;font-size:26px;line-height:1;cursor:pointer;padding:0 2px}
.sc-msgs{flex:1;overflow-y:auto;padding:14px;display:flex;flex-direction:column;gap:9px}
.sc-m{max-width:88%;padding:9px 12px;font-size:14.5px;line-height:1.45;word-wrap:break-word;overflow-wrap:anywhere}
.sc-m.bot{align-self:flex-start;background:var(--sc-bot);color:var(--sc-ink);clip-path:polygon(0 0,100% 0,100% 100%,8px 100%,0 calc(100% - 8px))}
.sc-m.me{align-self:flex-end;background:var(--sc-me);color:var(--sc-me-ink);clip-path:polygon(0 0,calc(100% - 8px) 0,100% 8px,100% 100%,0 100%)}
.sc-m a{color:inherit;text-decoration:underline}
.sc-m.wait{opacity:.6}
.sc-cta{display:inline-block;background:var(--sc-accent);color:var(--sc-accent-ink)!important;text-decoration:none!important;font-weight:700;padding:8px 14px;
clip-path:polygon(0 0,calc(100% - 8px) 0,100% 8px,100% 100%,8px 100%,0 calc(100% - 8px))}
.sc-handoff{background:transparent!important;padding:0!important}
.sc-topics{display:flex;flex-wrap:wrap;gap:6px;padding:0 14px 8px}
.sc-topics button{background:var(--sc-chip);color:var(--sc-chip-ink);border:1px solid var(--sc-gold);font:600 12.5px var(--sc-font);padding:5px 10px;cursor:pointer}
.sc-input{display:flex;gap:8px;padding:10px 12px;border-top:1px solid var(--sc-line)}
.sc-input input{flex:1;min-width:0;border:1px solid var(--sc-line);padding:10px 12px;font:15px var(--sc-font);color:var(--sc-ink);background:#fff}
.sc-input input:focus{outline:2px solid var(--blue,#1F66FF);outline-offset:-1px}
.sc-input button{background:var(--sc-accent);color:var(--sc-accent-ink);border:0;font:700 14px var(--sc-font);padding:0 16px;cursor:pointer;
clip-path:polygon(0 0,calc(100% - 8px) 0,100% 8px,100% 100%,8px 100%,0 calc(100% - 8px))}
.sc-human{display:block;text-align:center;font-size:12.5px;color:var(--sc-sub);padding:0 0 10px}
@media (max-width:600px){#scChat{right:12px;bottom:12px}#scBtn{width:52px;height:52px}#scPanel{bottom:64px;height:calc(100vh - 100px)}}
+72
View File
@@ -0,0 +1,72 @@
// 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=20261115c'; document.head.appendChild(css);
var NAME = 'this site', TOPICS = [];
var root = document.createElement('div'); root.id = 'scChat';
root.innerHTML = '<button id="scBtn" type="button" aria-label="Ask a question" aria-expanded="false">'
+ '<svg viewBox="0 0 24 24" width="26" height="26" aria-hidden="true"><path fill="currentColor" d="M4 4h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-5 4v-4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2zm3 6.5a1.5 1.5 0 1 0 0 .01zm5 0a1.5 1.5 0 1 0 0 .01zm5 0a1.5 1.5 0 1 0 0 .01z"/></svg></button>'
+ '<section id="scPanel" role="dialog" aria-label="Questions" hidden>'
+ '<header class="sc-head"><div><b class="sc-title" id="scTitle">Ask a question</b><span class="sc-sub">Straight answers about this site and the network</span></div>'
+ '<button id="scClose" type="button" aria-label="Close">&times;</button></header>'
+ '<div class="sc-msgs" id="scMsgs" aria-live="polite"></div>'
+ '<div class="sc-topics" id="scTopics"></div>'
+ '<form class="sc-input" id="scForm"><input id="scIn" autocomplete="off" maxlength="600" placeholder="Type your question" aria-label="Your question">'
+ '<button type="submit" id="scSend">Send</button></form>'
+ '<a class="sc-human" id="scHuman" href="https://instantadpay.com/support" target="_blank" rel="noopener">Need a person? Open network support</a>'
+ '</section>';
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 { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]; }); }
function add(text, who) {
var d = document.createElement('div'); d.className = 'sc-m ' + who;
d.innerHTML = esc(text).replace(/(https?:\/\/[^\s<]+[^\s<.,;:!?)])/g, '<a href="$1" target="_blank" rel="noopener">$1</a>');
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(); });
})();