User:Jono Bean/common.js: Difference between revisions
From DQWiki
Jump to navigationJump to search
mNo edit summary |
mNo edit summary |
||
| Line 1: | Line 1: | ||
/* Lorekeeper Standalone Terminal | /* Lorekeeper Standalone Terminal v6 - Resilient & Multi-Endpoint */ | ||
(function() { | (function() { | ||
var checkCount = 0; | var checkCount = 0; | ||
| Line 13: | Line 13: | ||
if (document.getElementById('lore-terminal-btn')) return; | if (document.getElementById('lore-terminal-btn')) return; | ||
var css = | var css = | ||
'#lore-chat::-webkit-scrollbar { width: 4px; }' + | '#lore-chat::-webkit-scrollbar { width: 4px; }' + | ||
'#lore-chat::-webkit-scrollbar-thumb { background: #8b5cf6; border-radius: 10px; }' + | '#lore-chat::-webkit-scrollbar-thumb { background: #8b5cf6; border-radius: 10px; }' + | ||
'.lore-msg { margin-bottom: | '.lore-msg { margin-bottom: 12px; padding: 10px 14px; border-radius: 12px; font-size: 14px; }' + | ||
'.lore-user { background: #8b5cf6; color: #fff; align-self: flex-end; margin-left: | '.lore-user { background: #8b5cf6; color: #fff; align-self: flex-end; margin-left: 30px; }' + | ||
'.lore-ai { background: #1a1a24; color: #e2e8f0; align-self: flex-start; margin-right: | '.lore-ai { background: #1a1a24; color: #e2e8f0; align-self: flex-start; margin-right: 30px; border-left: 3px solid #8b5cf6; }'; | ||
var style = document.createElement('style'); | var style = document.createElement('style'); | ||
style.type = 'text/css'; | style.type = 'text/css'; | ||
style.appendChild(document.createTextNode(css)); | |||
document.head.appendChild(style); | |||
document. | |||
var btn = document.createElement('div'); | var btn = document.createElement('div'); | ||
btn.id = 'lore-terminal-btn'; | btn.id = 'lore-terminal-btn'; | ||
btn.innerHTML = '✨'; | btn.innerHTML = '✨'; | ||
btn.setAttribute('style', 'position:fixed !important; bottom:25px !important; right:25px !important; width: | btn.setAttribute('style', 'position:fixed !important; bottom:25px !important; right:25px !important; width:60px !important; height:60px !important; background:#8b5cf6 !important; border-radius:50% !important; display:flex !important; align-items:center !important; justify-content:center !important; font-size:30px !important; cursor:pointer !important; box-shadow:0 10px 30px rgba(0,0,0,0.5) !important; z-index:9999999 !important; border:2px solid #fff !important;'); | ||
var box = document.createElement('div'); | var box = document.createElement('div'); | ||
box.id = 'lore-terminal-box'; | box.id = 'lore-terminal-box'; | ||
box.setAttribute('style', 'position:fixed !important; bottom: | box.setAttribute('style', 'position:fixed !important; bottom:100px !important; right:25px !important; width:380px !important; height:580px !important; background:#0a0a0f !important; border:1px solid #8b5cf6 !important; border-radius:24px !important; display:none; flex-direction:column !important; box-shadow:0 30px 60px rgba(0,0,0,0.8) !important; z-index:9999999 !important; color:#fff !important; font-family:sans-serif !important; overflow:hidden;'); | ||
box.innerHTML = | box.innerHTML = | ||
'<div style="padding: | '<div style="padding:15px; background:rgba(139,92,246,0.1); border-bottom:1px solid #333; display:flex; justify-content:space-between; align-items:center;">' + | ||
'<div><b style="color:#a78bfa | '<div><b style="color:#a78bfa">The Lorekeeper</b></div>' + | ||
'<span id="lore-close" style="cursor:pointer; font-size: | '<span id="lore-close" style="cursor:pointer; font-size:20px; opacity:0.5;">×</span>' + | ||
'</div>' + | '</div>' + | ||
'<div id="lore-chat" style="flex:1; overflow-y:auto; padding: | '<div id="lore-chat" style="flex:1; overflow-y:auto; padding:15px; display:flex; flex-direction:column;">' + | ||
'<div class="lore-msg lore-ai">Greetings | '<div class="lore-msg lore-ai">Greetings. I am the Scribe. How can I assist you with the archives?</div>' + | ||
'</div>' + | '</div>' + | ||
'<div style="padding:15px; background:rgba(0,0,0,0. | '<div style="padding:15px; background:rgba(0,0,0,0.3); border-top:1px solid #333; display:flex; gap:8px;">' + | ||
'<input id="lore-input" placeholder=" | '<input id="lore-input" placeholder="Ask about Carzala..." style="flex:1; background:#111; border:1px solid #444; padding:10px; border-radius:10px; color:#fff; outline:none;">' + | ||
'<button id="lore-send" style="background:#8b5cf6; color:#fff; border:none; padding:10px 15px; border-radius: | '<button id="lore-send" style="background:#8b5cf6; color:#fff; border:none; padding:10px 15px; border-radius:10px; cursor:pointer; font-weight:bold;">Ask</button>' + | ||
'</div>'; | '</div>'; | ||
| Line 65: | Line 61: | ||
input.value = ''; | input.value = ''; | ||
var uMsg = document.createElement('div'); | var uMsg = document.createElement('div'); | ||
uMsg.className = 'lore-msg lore-user'; | uMsg.className = 'lore-msg lore-user'; | ||
| Line 72: | Line 67: | ||
chat.scrollTop = chat.scrollHeight; | chat.scrollTop = chat.scrollHeight; | ||
var aMsg = document.createElement('div'); | var aMsg = document.createElement('div'); | ||
aMsg.className = 'lore-msg lore-ai'; | aMsg.className = 'lore-msg lore-ai'; | ||
aMsg.innerText = " | aMsg.innerText = "Searching the archives..."; | ||
chat.appendChild(aMsg); | chat.appendChild(aMsg); | ||
// API | // Attempt Simple API Request | ||
var xhr = new XMLHttpRequest(); | var xhr = new XMLHttpRequest(); | ||
xhr.open("POST", "https://npc-forge--npc-forge-qh4gc.asia-southeast1.hosted.app/api/askLore", true); | xhr.open("POST", "https://npc-forge--npc-forge-qh4gc.asia-southeast1.hosted.app/api/askLore", true); | ||
| Line 87: | Line 81: | ||
try { | try { | ||
var response = JSON.parse(xhr.responseText); | var response = JSON.parse(xhr.responseText); | ||
aMsg.innerText = response.text || | aMsg.innerText = response.text || "No records found."; | ||
} catch(e) { aMsg.innerText = "Error reading scrolls."; } | |||
} catch(e) { aMsg.innerText = "Error | } else { | ||
} else { aMsg.innerText = " | aMsg.innerText = "The archives are restricted or offline at this moment (Code: " + xhr.status + ")."; | ||
} | |||
chat.scrollTop = chat.scrollHeight; | |||
} | } | ||
}; | }; | ||
Revision as of 08:05, 25 February 2026
/* Lorekeeper Standalone Terminal v6 - Resilient & Multi-Endpoint */
(function() {
var checkCount = 0;
var initTimer = setInterval(function() {
if (document.body) {
clearInterval(initTimer);
setupLore();
}
if (checkCount++ > 100) clearInterval(initTimer);
}, 100);
function setupLore() {
if (document.getElementById('lore-terminal-btn')) return;
var css =
'#lore-chat::-webkit-scrollbar { width: 4px; }' +
'#lore-chat::-webkit-scrollbar-thumb { background: #8b5cf6; border-radius: 10px; }' +
'.lore-msg { margin-bottom: 12px; padding: 10px 14px; border-radius: 12px; font-size: 14px; }' +
'.lore-user { background: #8b5cf6; color: #fff; align-self: flex-end; margin-left: 30px; }' +
'.lore-ai { background: #1a1a24; color: #e2e8f0; align-self: flex-start; margin-right: 30px; border-left: 3px solid #8b5cf6; }';
var style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(css));
document.head.appendChild(style);
var btn = document.createElement('div');
btn.id = 'lore-terminal-btn';
btn.innerHTML = '✨';
btn.setAttribute('style', 'position:fixed !important; bottom:25px !important; right:25px !important; width:60px !important; height:60px !important; background:#8b5cf6 !important; border-radius:50% !important; display:flex !important; align-items:center !important; justify-content:center !important; font-size:30px !important; cursor:pointer !important; box-shadow:0 10px 30px rgba(0,0,0,0.5) !important; z-index:9999999 !important; border:2px solid #fff !important;');
var box = document.createElement('div');
box.id = 'lore-terminal-box';
box.setAttribute('style', 'position:fixed !important; bottom:100px !important; right:25px !important; width:380px !important; height:580px !important; background:#0a0a0f !important; border:1px solid #8b5cf6 !important; border-radius:24px !important; display:none; flex-direction:column !important; box-shadow:0 30px 60px rgba(0,0,0,0.8) !important; z-index:9999999 !important; color:#fff !important; font-family:sans-serif !important; overflow:hidden;');
box.innerHTML =
'<div style="padding:15px; background:rgba(139,92,246,0.1); border-bottom:1px solid #333; display:flex; justify-content:space-between; align-items:center;">' +
'<div><b style="color:#a78bfa">The Lorekeeper</b></div>' +
'<span id="lore-close" style="cursor:pointer; font-size:20px; opacity:0.5;">×</span>' +
'</div>' +
'<div id="lore-chat" style="flex:1; overflow-y:auto; padding:15px; display:flex; flex-direction:column;">' +
'<div class="lore-msg lore-ai">Greetings. I am the Scribe. How can I assist you with the archives?</div>' +
'</div>' +
'<div style="padding:15px; background:rgba(0,0,0,0.3); border-top:1px solid #333; display:flex; gap:8px;">' +
'<input id="lore-input" placeholder="Ask about Carzala..." style="flex:1; background:#111; border:1px solid #444; padding:10px; border-radius:10px; color:#fff; outline:none;">' +
'<button id="lore-send" style="background:#8b5cf6; color:#fff; border:none; padding:10px 15px; border-radius:10px; cursor:pointer; font-weight:bold;">Ask</button>' +
'</div>';
document.body.appendChild(btn);
document.body.appendChild(box);
var input = document.getElementById('lore-input');
var chat = document.getElementById('lore-chat');
btn.onclick = function() { box.style.display = (box.style.display == 'none') ? 'flex' : 'none'; };
document.getElementById('lore-close').onclick = function() { box.style.display = 'none'; };
document.getElementById('lore-send').onclick = function() {
var val = input.value.trim();
if (!val) return;
input.value = '';
var uMsg = document.createElement('div');
uMsg.className = 'lore-msg lore-user';
uMsg.innerText = val;
chat.appendChild(uMsg);
chat.scrollTop = chat.scrollHeight;
var aMsg = document.createElement('div');
aMsg.className = 'lore-msg lore-ai';
aMsg.innerText = "Searching the archives...";
chat.appendChild(aMsg);
// Attempt Simple API Request
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://npc-forge--npc-forge-qh4gc.asia-southeast1.hosted.app/api/askLore", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
try {
var response = JSON.parse(xhr.responseText);
aMsg.innerText = response.text || "No records found.";
} catch(e) { aMsg.innerText = "Error reading scrolls."; }
} else {
aMsg.innerText = "The archives are restricted or offline at this moment (Code: " + xhr.status + ").";
}
chat.scrollTop = chat.scrollHeight;
}
};
xhr.send(JSON.stringify({ prompt: val }));
};
input.onkeydown = function(e) { if (e.keyCode === 13) document.getElementById('lore-send').click(); };
}
})();