noones-search/searx/static/themes/simple/js/searxng.min.js

8 lines
26 KiB
JavaScript
Raw Normal View History

2021-10-01 16:07:27 +00:00
/**
* @license
* (C) Copyright Contributors to the SearXNG project.
* (C) Copyright Contributors to the searx project (2014 - 2021).
* SPDX-License-Identifier: AGPL-3.0-or-later
*/window.searxng=function(p,d){p.Element&&function(i){i.matches=i.matches||i.matchesSelector||i.webkitMatchesSelector||i.msMatchesSelector||function(s){for(var l=this,n=(l.parentNode||l.document).querySelectorAll(s),e=-1;n[++e]&&n[e]!=l;);return!!n[e]}}(Element.prototype);function a(i,s,l){try{i.call(s,l)}catch(n){console.log(n)}}var h=window.searxng||{};h.on=function(i,s,l,n){n=n||!1,typeof i!="string"?i.addEventListener(s,l,n):d.addEventListener(s,function(e){for(var t=e.target||e.srcElement,o=!1;t&&t.matches&&t!==d&&!(o=t.matches(i));)t=t.parentElement;o&&a(l,t,e)},n)},h.ready=function(i){document.readyState!="loading"?i.call(p):p.addEventListener("DOMContentLoaded",i.bind(p))},h.http=function(i,s,l=null){return new Promise(function(n,e){try{var t=new XMLHttpRequest;t.open(i,s,!0),t.timeout=2e4,t.onload=function(){t.status==200?n(t.response,t.responseType):e(Error(t.statusText))},t.onerror=function(){e(Error("Network Error"))},t.onabort=function(){e(Error("Transaction is aborted"))},t.ontimeout=function(){e(Error("Timeout"))},l?t.send(l):t.send()}catch(o){e(o)}})},h.loadStyle=function(i){var s=h.settings.theme_static_path+"/"+i,l="style_"+i.replace(".","_"),n=d.getElementById(l);n===null&&(n=d.createElement("link"),n.setAttribute("id",l),n.setAttribute("rel","stylesheet"),n.setAttribute("type","text/css"),n.setAttribute("href",s),d.body.appendChild(n))},h.loadScript=function(i,s){var l=h.settings.theme_static_path+"/"+i,n="script_"+i.replace(".","_"),e=d.getElementById(n);if(e===null)e=d.createElement("script"),e.setAttribute("id",n),e.setAttribute("src",l),e.onload=s,e.onerror=function(){e.setAttribute("error","1")},d.body.appendChild(e);else if(e.hasAttribute("error"))console.log("callback not executed : script '"+l+"' not loaded.");else try{s.apply(e,[])}catch(t){console.log(t)}},h.insertBefore=function(i,s){s.parentNode.insertBefore(i,s)},h.insertAfter=function(i,s){s.parentNode.insertAfter(i,s.nextSibling)},h.on(".close","click",function(){this.parentNode.classList.add("invisible")});function m(){for(var i of d.getElementsByTagName("body")[0].classList.values())if(i.endsWith("_endpoint"))return i.split("_")[0];return""}return h.endpoint=m(),h}(window,document);searxng.ready(function(){if(searxng.infinite_scroll_supported="IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype,searxng.endpoint!=="results")return;if(!searxng.infinite_scroll_supported){console.log("IntersectionObserver not supported");return}let p=document;var d=p.getElementById("results").classList.contains("only_template_images");function a(){var i=p.createElement("div");return i.classList.add("loader"),i}function h(i,s){i.textContent="",s.forEach(l=>i.appendChild(l))}function m(i){var s=p.querySelector("#pagination form.next_page");if(s){h(p.querySelector("#pagination"),[a()]);var l=new FormData(s);searxng.http("POST",p.querySelector("#search").getAttribute("action"),l).then(function(n){var e=new DOMParser().parseFromString(n,"text/html"),t=e.querySelectorAll("#urls article"),o=e.querySelector("#pagination");p.querySelector("#pagination").remove(),t.length>0&&!d&&p.querySelector("#urls").appendChild(p.createElement("hr")),t.forEach(u=>{p.querySelector("#urls").appendChild(u)}),o&&(p.querySelector("#results").appendChild(o),i())}).catch(function(n){console.log(n);var e=p.createElement("div");e.textContent=searxng.settings.translations.error_loading_next_page,e.classList.add("dialog-error"),e.setAttribute("role","alert"),h(p.querySelector("#pagination"),[e])})}}if(searxng.settings.infinite_scroll&&searxng.infinite_scroll_supported){const i={rootMargin:"20rem"},s="article.result:last-child",l=new IntersectionObserver(n=>{const e=n[0];e.isIntersecting&&(l.unobserve(e.target),m(()=>l.observe(p.querySelector(s),i)))});l.observe(p.querySelector(s),i)}});searxng.ready(function(){function p(r){for(;r!==void 0;){if(r.classList.contains("detail"))return!0;if(r.classList.contains("result"))return!1;r=r.parentNode}return!1}function d(r){for(;r!==void 0;){if(r.classList.contains(
//# sourceMappingURL=searxng.min.js.map