function searchEscape(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};return e.replace(/[&<>"'/]/g,(function(e){return t[e]}))}function regEscape(e){const t={"{":"\\{","}":"\\}","[":"\\[","]":"\\]","(":"\\(",")":"\\)","?":"\\?","*":"\\*",".":"\\.","+":"\\+","^":"\\^",$:"\\$"};return e.replace(/[\{\}\[\]\(\)\?\*\.\+\^\$]/g,(function(e){return t[e]}))}function getParam(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");const t=new RegExp("[\\?&]"+e+"=([^]*)").exec(window.location);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))}function setNotice(e,t){const n=document.getElementById("kr-search-notice");n.className="alert alert-"+e,n.innerText=t}function clearPosts(){document.getElementById("result-posts").innerHTML=""}function createPosts(e){const t=document.getElementById("result-posts");let n="";e.forEach(e=>{const t=e[0];let c="";t.tags.forEach((e,t)=>{c+=t?", ":"";const n=`${e[0]}`;c+=n});const r=`\n \n \n \n `;n+=r}),t.innerHTML=n}function loadDataSearch(e,t){fetch(e).then(e=>(setNotice("success","文件加载完成,开始搜索啦~"),"undefined"!=typeof NProgress&&NProgress.inc(),e.json())).then(e=>{const n=performance.now();let c=[],r=0,a=t.trim().toLowerCase().split(/\s/);if(e.forEach(e=>{if(void 0===e.title||void 0===e.content)return;let t=!1;const n=e.title.trim().toLowerCase(),s=e.content?e.content.trim().replace(/<[^>]+>/g,"").toLowerCase():"";let o=0,i={title:-1,content:-1,firstOccur:-1,lastOccur:-1};if(n&&a.forEach(e=>{i.title=n.indexOf(e),i.content=s.indexOf(e),-1===i.title&&-1===i.content||(t=!0,-1!==i.content?((i.firstOccur>i.content||-1===i.firstOccur)&&(i.firstOccur=i.content),i.lastOccur{const n=new RegExp(regEscape(e)+"(?!>)","gi");t.title=t.title.replace(n,"$&")}),i.firstOccur>=0){let e=i.firstOccur-100,n=i.lastOccur+100;e<0&&(e=0),0===e&&(n=200),n>s.length&&(n=s.length),t.content=s.substr(e,n-e),a.forEach(e=>{const n=new RegExp(regEscape(e)+"(?!>)","gi");t.content=t.content.replace(n,"$&")})}c.push([t,o])}}),0!==r){const e=performance.now();setNotice("success","找到 "+r+" 条搜索结果,用时 "+Math.round(100*(e-n))/100+" 毫秒~"),c.sort((e,t)=>t[1]-e[1]),createPosts(c)}else setNotice("danger","什么都没有找到欸..."),clearPosts();"undefined"!=typeof NProgress&&NProgress.done()}).catch(e=>{setNotice("danger","错误 : "+e)})}function keySearch(e){setNotice("info","正在加载搜索文件..."),"undefined"!=typeof NProgress&&NProgress.start(),loadDataSearch(searchDataFile,searchEscape(e))}function inpSearch(){const e=document.getElementById("search-input").value;return window.history.pushState({},0,window.location.href.split("?")[0]+"?s="+e.replace(/\s/g,"+")),keySearch(e),!1}(()=>{const e=getParam("s");""!==e&&(document.getElementById("search-input").value=e,keySearch(e))})();