Spaces:
Runtime error
Runtime error
Download static/js/script.js from santu24/Amazon_Product_Recommendation_Engine: direct link, hf CLI and curl.
- Browser
- Download file 988 Bytes
-
https://huggingface.co/spaces/santu24/Amazon_Product_Recommendation_Engine/resolve/main/static/js/script.js
- Command line
-
hf download hf://spaces/santu24/Amazon_Product_Recommendation_Engine/static/js/script.js
-
curl -L -o script.js https://huggingface.co/spaces/santu24/Amazon_Product_Recommendation_Engine/resolve/main/static/js/script.js
988 Bytes
| // For the normal product search autocomplete | |
| const input = document.getElementById('search-input'); | |
| const resultsBox = document.getElementById('autocomplete-results'); | |
| function showResults(results) { | |
| if (!results || results.length === 0) { | |
| resultsBox.style.display = 'none'; | |
| return; | |
| } | |
| let html = ''; | |
| results.forEach(item => { | |
| html += `<div class="autocomplete-item" onclick="goToProduct(${item.id})">${item.name}</div>`; | |
| }); | |
| resultsBox.innerHTML = html; | |
| resultsBox.style.display = 'block'; | |
| } | |
| function goToProduct(itemId) { | |
| window.location.href = '/product/' + itemId; | |
| } | |
| if (input && resultsBox) { | |
| input.addEventListener('input', function() { | |
| const q = this.value.trim(); | |
| if (q.length < 1) { | |
| resultsBox.style.display = 'none'; | |
| return; | |
| } | |
| fetch(`/autocomplete?q=${encodeURIComponent(q)}`) | |
| .then(resp => resp.json()) | |
| .then(data => { | |
| showResults(data); | |
| }) | |
| .catch(err => console.error(err)); | |
| }); | |
| } | |