chansung commited on
Commit
5c7d00d
1 Parent(s): e3a164f

Create js.py

Browse files
Files changed (1) hide show
  1. js.py +81 -0
js.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GET_LOCAL_STORAGE = """
2
+ function() {
3
+ globalThis.setStorage = (key, value)=>{
4
+ localStorage.setItem(key, JSON.stringify(value));
5
+ }
6
+ globalThis.getStorage = (key, value)=>{
7
+ return JSON.parse(localStorage.getItem(key));
8
+ }
9
+
10
+ var local_data = getStorage('local_data');
11
+ var history = [];
12
+
13
+ if(local_data) {
14
+ local_data[0].pingpongs.forEach(element =>{
15
+ history.push([element.ping, element.pong]);
16
+ });
17
+ }
18
+ else {
19
+ local_data = [];
20
+ for (let step = 0; step < 10; step++) {
21
+ local_data.push({'ctx': '', 'pingpongs':[]});
22
+ }
23
+ setStorage('local_data', local_data);
24
+ }
25
+
26
+ if(history.length == 0) {
27
+ document.querySelector("#initial-popup").classList.remove('hide');
28
+ }
29
+
30
+ return [history, local_data];
31
+ }
32
+ """
33
+
34
+ UPDATE_LEFT_BTNS_STATE = """
35
+ (v)=>{
36
+ document.querySelector('.custom-btn-highlight').classList.add('custom-btn');
37
+ document.querySelector('.custom-btn-highlight').classList.remove('custom-btn-highlight');
38
+
39
+ const elements = document.querySelectorAll(".custom-btn");
40
+
41
+ for(var i=0; i < elements.length; i++) {
42
+ const element = elements[i];
43
+ if(element.textContent == v) {
44
+ console.log(v);
45
+ element.classList.add('custom-btn-highlight');
46
+ element.classList.remove('custom-btn');
47
+ break;
48
+ }
49
+ }
50
+ }"""
51
+
52
+ UPDATE_PLACEHOLDERS = """
53
+ function update_placeholders(txt, placeholder_txt1, placeholder_txt2, placeholder_txt3) {
54
+ let example_prompt = txt;
55
+
56
+ const regex = /\[([^\]]*)\]/g;
57
+ const matches = txt.match(regex);
58
+
59
+ if (matches != null) {
60
+ if (matches.length >= 1) {
61
+ if (placeholder_txt1 !== "") {
62
+ example_prompt = example_prompt.replace(matches[0], placeholder_txt1);
63
+ }
64
+ }
65
+
66
+ if (matches.length >= 2) {
67
+ if (placeholder_txt2 !== "") {
68
+ example_prompt = example_prompt.replace(matches[1], placeholder_txt2);
69
+ }
70
+ }
71
+
72
+ if (matches.length >= 3) {
73
+ if (placeholder_txt1 !== "") {
74
+ example_prompt = example_prompt.replace(matches[2], placeholder_txt3);
75
+ }
76
+ }
77
+ }
78
+
79
+ return example_prompt
80
+ }
81
+ """