Spaces:
Runtime error
Runtime error
Commit
•
e053904
1
Parent(s):
1310821
Upload 3 files
Browse files- js/main.js +50 -0
- js/save_files.js +40 -0
- js/switch_tabs.js +43 -0
js/main.js
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
let chat_tab = document.getElementById('chat-tab');
|
2 |
+
let notebook_tab = document.getElementById('notebook-tab');
|
3 |
+
let default_tab = document.getElementById('default-tab');
|
4 |
+
|
5 |
+
let main_parent = chat_tab.parentNode;
|
6 |
+
let extensions = document.getElementById('extensions');
|
7 |
+
|
8 |
+
main_parent.childNodes[0].classList.add("header_bar");
|
9 |
+
main_parent.style = "padding: 0; margin: 0";
|
10 |
+
main_parent.parentNode.parentNode.style = "padding: 0";
|
11 |
+
|
12 |
+
// Add an event listener to the generation tabs
|
13 |
+
main_parent.addEventListener('click', function(e) {
|
14 |
+
let chat_visible = (chat_tab.offsetHeight > 0 && chat_tab.offsetWidth > 0);
|
15 |
+
let notebook_visible = (notebook_tab.offsetHeight > 0 && notebook_tab.offsetWidth > 0);
|
16 |
+
let default_visible = (default_tab.offsetHeight > 0 && default_tab.offsetWidth > 0);
|
17 |
+
|
18 |
+
// Check if one of the generation tabs is visible
|
19 |
+
if (chat_visible || notebook_visible || default_visible) {
|
20 |
+
extensions.style.display = 'flex';
|
21 |
+
if (chat_visible) {
|
22 |
+
extensions.style.maxWidth = "800px";
|
23 |
+
extensions.style.padding = "0px";
|
24 |
+
} else {
|
25 |
+
extensions.style.maxWidth = "none";
|
26 |
+
extensions.style.padding = "15px";
|
27 |
+
}
|
28 |
+
} else {
|
29 |
+
extensions.style.display = 'none';
|
30 |
+
}
|
31 |
+
});
|
32 |
+
|
33 |
+
// Add some scrollbars
|
34 |
+
const textareaElements = document.querySelectorAll('.add_scrollbar textarea');
|
35 |
+
for(i = 0; i < textareaElements.length; i++) {
|
36 |
+
textareaElements[i].classList.remove('scroll-hide');
|
37 |
+
textareaElements[i].classList.add('pretty_scrollbar');
|
38 |
+
textareaElements[i].style.resize = "none";
|
39 |
+
}
|
40 |
+
|
41 |
+
// Stop generation on Esc pressed
|
42 |
+
document.addEventListener("keydown", function(event) {
|
43 |
+
if (event.key === "Escape") {
|
44 |
+
// Find the element with id 'stop' and click it
|
45 |
+
var stopButton = document.getElementById("stop");
|
46 |
+
if (stopButton) {
|
47 |
+
stopButton.click();
|
48 |
+
}
|
49 |
+
}
|
50 |
+
});
|
js/save_files.js
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Functions for downloading JSON files
|
2 |
+
function getCurrentTimestamp() {
|
3 |
+
const now = new Date();
|
4 |
+
const timezoneOffset = now.getTimezoneOffset() * 60000; // Convert to milliseconds
|
5 |
+
const localTime = new Date(now.getTime() - timezoneOffset);
|
6 |
+
const formattedTimestamp = localTime.toISOString().replace(/[-:]/g, '').slice(0, 15);
|
7 |
+
return formattedTimestamp;
|
8 |
+
}
|
9 |
+
|
10 |
+
function saveFile(contents, filename) {
|
11 |
+
const element = document.createElement('a');
|
12 |
+
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(contents));
|
13 |
+
element.setAttribute('download', filename);
|
14 |
+
element.style.display = 'none';
|
15 |
+
document.body.appendChild(element);
|
16 |
+
element.click();
|
17 |
+
document.body.removeChild(element);
|
18 |
+
}
|
19 |
+
|
20 |
+
function saveHistory(history, character, mode) {
|
21 |
+
let path = null;
|
22 |
+
|
23 |
+
if (['chat', 'chat-instruct'].includes(mode) && character && character.trim() !== '') {
|
24 |
+
path = `history_${character}_${getCurrentTimestamp()}.json`;
|
25 |
+
} else {
|
26 |
+
try {
|
27 |
+
path = `history_${mode}_${getCurrentTimestamp()}.json`;
|
28 |
+
} catch (error) {
|
29 |
+
path = `history_${getCurrentTimestamp()}.json`;
|
30 |
+
}
|
31 |
+
}
|
32 |
+
saveFile(history, path);
|
33 |
+
}
|
34 |
+
|
35 |
+
function saveSession(session) {
|
36 |
+
let path = null;
|
37 |
+
|
38 |
+
path = `session_${getCurrentTimestamp()}.json`;
|
39 |
+
saveFile(session, path);
|
40 |
+
}
|
js/switch_tabs.js
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
let chat_tab = document.getElementById('chat-tab');
|
2 |
+
let main_parent = chat_tab.parentNode;
|
3 |
+
|
4 |
+
function scrollToTop() {
|
5 |
+
window.scrollTo({
|
6 |
+
top: 0,
|
7 |
+
// behavior: 'smooth'
|
8 |
+
});
|
9 |
+
}
|
10 |
+
|
11 |
+
function switch_to_chat() {
|
12 |
+
let chat_tab_button = main_parent.childNodes[0].childNodes[1];
|
13 |
+
chat_tab_button.click();
|
14 |
+
scrollToTop();
|
15 |
+
}
|
16 |
+
|
17 |
+
function switch_to_default() {
|
18 |
+
let default_tab_button = main_parent.childNodes[0].childNodes[4];
|
19 |
+
default_tab_button.click();
|
20 |
+
scrollToTop();
|
21 |
+
}
|
22 |
+
|
23 |
+
function switch_to_notebook() {
|
24 |
+
let notebook_tab_button = main_parent.childNodes[0].childNodes[7];
|
25 |
+
notebook_tab_button.click();
|
26 |
+
scrollToTop();
|
27 |
+
}
|
28 |
+
|
29 |
+
function switch_to_generation_parameters() {
|
30 |
+
let parameters_tab_button = main_parent.childNodes[0].childNodes[10];
|
31 |
+
let generation_tab_button = document.getElementById('character-menu').parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[1];
|
32 |
+
parameters_tab_button.click();
|
33 |
+
generation_tab_button.click();
|
34 |
+
scrollToTop();
|
35 |
+
}
|
36 |
+
|
37 |
+
function switch_to_character() {
|
38 |
+
let parameters_tab_button = main_parent.childNodes[0].childNodes[10];
|
39 |
+
let character_tab_button = document.getElementById('character-menu').parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[4];
|
40 |
+
parameters_tab_button.click();
|
41 |
+
character_tab_button.click();
|
42 |
+
scrollToTop();
|
43 |
+
}
|