Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions chat-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,31 @@ async function pollinationsFetch(url, options = {}, { timeoutMs = 45000 } = {})
clearTimeout(timer);
}
}
window.pollinationsFetch = pollinationsFetch;
// Load global AI instructions from external text file
window.aiInstructions = "";
window.pollinationsFetch = pollinationsFetch;

// Load global AI instructions from external text file
window.aiInstructions = "";
window.aiInstructionPromise = fetch("ai-instruct.txt")
.then(res => res.text())
.then(text => { window.aiInstructions = text; })
.catch(err => {
console.error("Failed to load AI instructions", err);
window.aiInstructions = "";
});

document.addEventListener("DOMContentLoaded", () => {
});

// Utility: allow Enter to send messages and Shift+Enter for new lines
window.setupEnterToSend = function(textarea, sendCallback) {
if (!textarea || typeof sendCallback !== "function") return;
textarea.addEventListener("keydown", (e) => {
const isEnter = e.key === "Enter" || e.keyCode === 13;
if (isEnter && !e.shiftKey) {
e.preventDefault();
sendCallback();
}
});
};

document.addEventListener("DOMContentLoaded", () => {

const chatBox = document.getElementById("chat-box");
const chatInput = document.getElementById("chat-input");
Expand Down
9 changes: 1 addition & 8 deletions chat-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,8 @@ document.addEventListener("DOMContentLoaded", () => {
chatInput.style.height = chatInput.scrollHeight + "px";
});
sendButton.addEventListener("click", handleSendMessage);

// Send on Enter; newline with Shift+Enter
chatInput.addEventListener('keydown', (e) => {
const isEnter = e.key === 'Enter' || e.keyCode === 13;
if (isEnter && !e.shiftKey) {
e.preventDefault();
handleSendMessage();
}
});
window.setupEnterToSend(chatInput, handleSendMessage);
sendButton.disabled = chatInput.value.trim() === "";
chatInput.dispatchEvent(new Event("input"));
const initialSession = Storage.getCurrentSession();
Expand Down
17 changes: 5 additions & 12 deletions simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,12 @@ document.addEventListener("DOMContentLoaded", () => {
});
};
simpleSendBtn.addEventListener("click", handleSimpleSend);

// Send on Enter; newline with Shift+Enter
simpleInput.addEventListener('keydown', (e) => {
const isEnter = e.key === 'Enter' || e.keyCode === 13;
if (isEnter && !e.shiftKey) {
e.preventDefault();
handleSimpleSend();
}
});

function appendSimpleMessage(role, content, index) {
const container = document.createElement("div");
container.classList.add("simple-message");
window.setupEnterToSend(simpleInput, handleSimpleSend);

function appendSimpleMessage(role, content, index) {
const container = document.createElement("div");
container.classList.add("simple-message");
container.dataset.index = index;
container.dataset.role = role;
if (role === "user") {
Expand Down