whisper.cat/weboasis/js/keyscroll.min.js

1 line
2.6 KiB
JavaScript
Raw Normal View History

2023-10-05 23:28:32 +11:00
function selectKey2(e){if("none"==defaultSearch.style.display){let e=document.querySelectorAll("#mainContainer2 .searchSources");if(!(selectedIndex<0||selectedIndex>e.length-1))var s=e[selectedIndex];selectedIndex>=0&&s.classList.add("selectedResult")}if("none"!==defaultSearch.style.display){s=document.querySelectorAll("#generatedList .searchSources")[selectedIndex];selectedIndex>=0&&s.classList.add("selectedResult")}}function selectKey(e){if(38==e.keyCode&&"none"==defaultSearch.style.display){selectedIndex-=1;var s=selectedIndex+1;let e=document.querySelectorAll("#mainContainer2 .searchSources");-1==selectedIndex&&(selectedIndex=e.length-1);var t=e[selectedIndex];(l=e[s])&&l.classList.remove("selectedResult"),selectedIndex>=0&&t.classList.add("selectedResult")}else if(38==e.keyCode&&"none"!==defaultSearch.style.display&&"yes"===localStorage.getItem("search-suggestions")&&0!==searchInput.value.length){selectedIndex-=1;s=selectedIndex+1;let e=document.querySelectorAll("#generatedList .searchSources");-1==selectedIndex&&(selectedIndex=e.length-1);t=e[selectedIndex];(l=e[s])&&l.classList.remove("selectedResult"),selectedIndex>=0&&t.classList.add("selectedResult")}else if(40==e.keyCode&&"none"==defaultSearch.style.display){selectedIndex+=1;s=selectedIndex-1;let e=document.querySelectorAll("#mainContainer2 .searchSources");selectedIndex==e.length&&(selectedIndex=0);t=e[selectedIndex];(l=e[s])&&l.classList.remove("selectedResult"),selectedIndex>=0&&t.classList.add("selectedResult")}else if(40==e.keyCode&&"none"!==defaultSearch.style.display&&"yes"===localStorage.getItem("search-suggestions")&&0!==searchInput.value.length){selectedIndex+=1;s=selectedIndex-1;let e=document.querySelectorAll("#generatedList .searchSources");selectedIndex==e.length&&(selectedIndex=0);var l;t=e[selectedIndex];(l=e[s])&&l.classList.remove("selectedResult"),selectedIndex>=0&&t.classList.add("selectedResult")}else if(13==e.keyCode&&"none"==defaultSearch.style.display){t=document.querySelectorAll("#mainContainer2 .searchSources")[selectedIndex];selectedIndex>=0&&t.classList.add("selectedResult");var d=t.querySelector("a").href;window.open(d,"_blank")}else if(39==e.keyCode&&"none"!==defaultSearch.style.display&&"yes"===localStorage.getItem("search-suggestions")&&0!==searchInput.value.length){t=document.querySelectorAll("#generatedList .searchSources")[selectedIndex];selectedIndex>=0&&t.classList.add("selectedResult"),searchInput.value=t.innerText}else(38==e.keyCode||40==e.keyCode&&"no"===localStorage.getItem("search-suggestions"))&&(selectedIndex=-1)}document.onkeydown=selectKey,document.onkeyup=selectKey2;