mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
Update webapp1.py
This commit is contained in:
parent
d5d8018f00
commit
80a3ae2890
1 changed files with 15 additions and 1 deletions
|
@ -1016,6 +1016,20 @@ function b64EncodeUnicode(t)
|
||||||
}
|
}
|
||||||
var word_last="";
|
var word_last="";
|
||||||
var lock_chat=1;
|
var lock_chat=1;
|
||||||
|
function wait(delay){
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, delay));
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchRetry(url, tries, fetchOptions = {}) {
|
||||||
|
function onError(err){
|
||||||
|
triesLeft = tries - 1;
|
||||||
|
if(!triesLeft){
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
return wait(500).then(() => fetchRetry(url, triesLeft, fetchOptions));
|
||||||
|
}
|
||||||
|
return fetch(url,fetchOptions).catch(onError);
|
||||||
|
}
|
||||||
function send_webchat(elem)
|
function send_webchat(elem)
|
||||||
{
|
{
|
||||||
if(lock_chat!=0) return;
|
if(lock_chat!=0) return;
|
||||||
|
@ -1026,7 +1040,7 @@ function send_webchat(elem)
|
||||||
let word = document.querySelector("#chat_input").value;
|
let word = document.querySelector("#chat_input").value;
|
||||||
if(elem){word = elem.textContent;elem.remove(); chatmore();}
|
if(elem){word = elem.textContent;elem.remove(); chatmore();}
|
||||||
if(word.length==0 || word.length > 140) return;
|
if(word.length==0 || word.length > 140) return;
|
||||||
fetch('https://search.kg/search?q='+encodeURIComponent(word)+'&language=zh-CN&time_range=&safesearch=0&categories=general&format=json')
|
fetchRetry('https://search.kg/search?q='+encodeURIComponent(word)+'&language=zh-CN&time_range=&safesearch=0&categories=general&format=json',3)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
prompt = JSON.parse(atob( (/<div id="prompt" style="display:none">(.*?)<\/div>/).exec(data.infoboxes[0].content)[1] ) )
|
prompt = JSON.parse(atob( (/<div id="prompt" style="display:none">(.*?)<\/div>/).exec(data.infoboxes[0].content)[1] ) )
|
||||||
|
|
Loading…
Add table
Reference in a new issue