Commit a4465150 authored by Phil Höfer's avatar Phil Höfer
Browse files

Improve stability by allowing multiple (3) tries to load results.

parent 873e05b8
...@@ -6,30 +6,46 @@ xhttp.send(""); ...@@ -6,30 +6,46 @@ xhttp.send("");
return xhttp.responseXML; return xhttp.responseXML;
} }
function render(content) function render(err, content)
{ {
style = loadXMLDoc("style/material.xsl"); if (err) {
if (document.implementation && document.implementation.createDocument)
{ } else {
xsltProcessor = new XSLTProcessor(); style = loadXMLDoc("style/material.xsl");
xsltProcessor.importStylesheet(style); if (document.implementation && document.implementation.createDocument)
resultDocument = xsltProcessor.transformToFragment(content, document); {
document.body.replaceWith(resultDocument); xsltProcessor = new XSLTProcessor();
} xsltProcessor.importStylesheet(style);
resultDocument = xsltProcessor.transformToFragment(content, document);
document.body.replaceWith(resultDocument);
}
}
} }
/** /**
* Returns OpenSearch responseXML for the given query. * Delivers OpenSearch responseXML to callback for the given query.
*/ */
function search(query,focus) { function search(query,focus,callback, tries) {
query = query || "eingabe="; query = query || "eingabe=";
focus = focus || "focus=web"; focus = focus || "focus=web";
return loadXMLDoc("https://metager3.de/meta/meta.ger3?"+focus+"&"+query+"&encoding=utf8&out=atom10&appversion=0.1.0"); let doc;
tries = tries || 3;
try {
doc = loadXMLDoc("https://metager3.de/meta/meta.ger3?"+focus+"&"+query+"&encoding=utf8&out=atom10&appversion=3.0.0");
callback(null, doc);
} catch (e) {
if(--tries) {
console.log("search error, tries left: "+tries);
search(query, focus, callback, tries);
} else {
callback(e);
}
};
} }
function boot() function boot()
{ {
render(search(getParameter('eingabe'),getParameter('focus'))); search(getParameter('eingabe'),getParameter('focus'),render);
} }
function getParameter(parameterName) { function getParameter(parameterName) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment