Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 6,635 Bytes
3993884 a7ff712 3993884 7e4123a 3993884 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
UPDATE_SEARCH_RESULTS = f"""
function search(searchIn, maxResults = 3) {{
if (searchIn.trim().length > 0) {{
const results = [];
let titles = %s;
for (const title of titles) {{ // Assuming 'titles' is an array defined elsewhere
if (results.length > 10) {{
break;
}} else {{
if (title.toLowerCase().includes(searchIn.toLowerCase())) {{ // JavaScript's equivalent to Python's 'in'
results.push(title);
}}
}}
}}
// Handle UI elements (Explanation below)
const resultElements = [1,2,3,4,5,6,7,8,9,10].map(index => {{
return results[index - 1] || '';
}});
if (resultElements[0] == '') {{
document.getElementById('search_r1').style.display = 'none';
}} else {{
document.getElementById('search_r1').style.display = 'block';
}}
if (resultElements[1] == '') {{
document.getElementById('search_r2').style.display = 'none';
}} else {{
document.getElementById('search_r2').style.display = 'block';
}}
if (resultElements[2] == '') {{
document.getElementById('search_r3').style.display = 'none';
}} else {{
document.getElementById('search_r3').style.display = 'block';
}}
if (resultElements[3] == '') {{
document.getElementById('search_r4').style.display = 'none';
}} else {{
document.getElementById('search_r4').style.display = 'block';
}}
if (resultElements[4] == '') {{
document.getElementById('search_r5').style.display = 'none';
}} else {{
document.getElementById('search_r5').style.display = 'block';
}}
if (resultElements[5] == '') {{
document.getElementById('search_r6').style.display = 'none';
}} else {{
document.getElementById('search_r6').style.display = 'block';
}}
if (resultElements[6] == '') {{
document.getElementById('search_r7').style.display = 'none';
}} else {{
document.getElementById('search_r7').style.display = 'block';
}}
if (resultElements[7] == '') {{
document.getElementById('search_r8').style.display = 'none';
}} else {{
document.getElementById('search_r8').style.display = 'block';
}}
if (resultElements[8] == '') {{
document.getElementById('search_r9').style.display = 'none';
}} else {{
document.getElementById('search_r9').style.display = 'block';
}}
if (resultElements[9] == '') {{
document.getElementById('search_r10').style.display = 'none';
}} else {{
document.getElementById('search_r10').style.display = 'block';
}}
return resultElements;
}} else {{
document.getElementById('search_r1').style.display = 'none';
document.getElementById('search_r2').style.display = 'none';
document.getElementById('search_r3').style.display = 'none';
document.getElementById('search_r4').style.display = 'none';
document.getElementById('search_r5').style.display = 'none';
document.getElementById('search_r6').style.display = 'none';
document.getElementById('search_r7').style.display = 'none';
document.getElementById('search_r8').style.display = 'none';
document.getElementById('search_r9').style.display = 'none';
document.getElementById('search_r10').style.display = 'none';
return ['', '', '', '', '', '', '', '', '', '']
}}
}}
"""
UPDATE_IF_TYPE = """
function chage_if_type() {
document.querySelector("#chatbot-back").style.display = 'block';
document.getElementById('qna_block').style.display = 'none';
}
"""
# globalThis.setStorage = (key, value)=>{
# localStorage.setItem(key, JSON.stringify(value));
# }
# globalThis.getStorage = (key, value)=>{
# return JSON.parse(localStorage.getItem(key));
# }
OPEN_CHAT_IF = """
function (arXivId) {
var localData = localStorage.getItem('localData');
if (!localData) {
localData = {}; // Initialize if it doesn't exist
}
else {
localData = JSON.parse(localData);
}
if (!localData[arXivId]) {
localData[arXivId] = { ctx: '', pingpongs: [] };
}
localStorage.setItem('localData', JSON.stringify(localData));
document.querySelector("#chatbot-back").classList.add("visible");
pingpongs = [];
localData[arXivId]['pingpongs'].forEach(element =>{
pingpongs.push([element.ping, element.pong]);
});
return [localData[arXivId], pingpongs];
}
"""
CLOSE_CHAT_IF = """
function close() {
setTimeout(function() {
document.querySelector("#chatbot-back").classList.remove("visible"); // Remove after a slight delay
}, 100); // 100-millisecond delay
}
"""
UPDATE_CHAT_HISTORY = """
function (arXivId, data) {
console.log(arXivId)
console.log(data);
if (localStorage.getItem('localData') === null) {
localStorage['localData'] = {};
}
var localData = localStorage.getItem('localData');
localData = JSON.parse(localData);
localData[arXivId] = data;
console.log(localData[arXivId]);
localStorage.setItem('localData', JSON.stringify(localData));
}
"""
GET_LOCAL_STORAGE = """
function() {
globalThis.setStorage = (arXivId, value) => {
console.log(value);
if (localStorage.getItem('localData') === null) {
localStorage['localData'] = {};
}
var localData = localStorage.getItem('localData');
localData = JSON.parse(localData);
localData[arXivId] = value;
console.log(localData[arXivId]);
localStorage.setItem('localData', JSON.stringify(localData));
}
globalThis.getStorage = (arXivId)=>{
var localData = localStorage.getItem('localData');
console.log(localData);
if (!localData) {
localData = {}; // Initialize if it doesn't exist
}
else {
localData = JSON.parse(localData);
}
if (!localData[arXivId]) {
localData[arXivId] = { ctx: '', pingpongs: [] };
}
localStorage.setItem('localData', JSON.stringify(localData));
console.log(localData[arXivId]['pingpongs']);
return [localData[arXivId], localData[arXivId]['pingpongs']];
}
var localData = localStorage.getItem('localData');
if(!localData) {
localData = {}
localStorage.setItem('localData', JSON.stringify(localData));
}
return [localData['%s']['pingpongs'], localData];
}
""" |