script.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //Some code created with help from https://invidio.xamh.de/watch?v=zOrejGF0oBA
  2. document.querySelector('#search').addEventListener("click",getSearchResults);
  3. function capitalizeFirstLetter(string){
  4. return string.charAt(0).toUpperCase() + string.slice(1);
  5. }
  6. function getSearchResults(e) {
  7. const name = document.querySelector("#searchInput").value.toLowerCase();
  8. const librex_instance = "https://search.davidovski.xyz/"
  9. fetch(librex_instance+"api.php?q="+name+"&p=1&type=0")
  10. .then((response) => response.json())
  11. .then((data) => {
  12. let list = `
  13. `;
  14. data.forEach(function(result){
  15. list += `
  16. <div class="searchResultInfo">
  17. <p style="color:#ADADAD">${result.base_url}</p>
  18. <a href="${result.url}"><h2>${result.title}</h2></a>
  19. <p>${result.description}</p>
  20. </div>
  21. `;
  22. })
  23. document.querySelector(".searchResult").innerHTML = list
  24. })
  25. .catch((err) => {
  26. document.querySelector(".searchResult").innerHTML = `
  27. <div>
  28. <p>Could not find this 😟. Try again.</p>
  29. </div>`;
  30. console.log(err);
  31. });
  32. e.preventDefault();
  33. }