add "trending" category, fix blank gif search, make it easier, and remove unnecessary clutter

pull/232/head
Aevann 2024-08-02 11:14:45 +03:00
parent b00e724267
commit 392bd92163
2 changed files with 17 additions and 13 deletions

View File

@ -28,6 +28,10 @@ async function show_gif_categories(t, form) {
noGIFs.classList.add("d-none");
container.innerHTML = `
<div class="card">
<div class="gif-cat-overlay"><div>Trending</div></div>
<img loading="lazy" src="https://media.tenor.com/C84XvrdyLswAAAAx/spongebob-patrick-star.webp">
</div>
<div class="card">
<div class="gif-cat-overlay"><div>Agree</div></div>
<img loading="lazy" src="https://media.giphy.com/media/wGhYz3FHaRJgk/200w.webp">
@ -103,7 +107,10 @@ async function show_gif_categories(t, form) {
const overlays = document.getElementsByClassName('gif-cat-overlay')
for (const element of overlays) {
element.addEventListener('click', () => {searchGifs(element.firstElementChild.innerHTML)});
let searchTerm = element.firstElementChild.innerHTML
if (searchTerm == 'Trending')
searchTerm = ''
element.addEventListener('click', () => {searchGifs(searchTerm)});
}
if (t) {
@ -123,7 +130,7 @@ async function searchGifs(searchTerm) {
container.innerHTML = '';
let response = await fetch("/tenor?searchTerm=" + searchTerm + "&limit=48");
let response = await fetch("/tenor?searchTerm=" + searchTerm);
let data = await response.json()
data = data.results
@ -144,4 +151,7 @@ async function searchGifs(searchTerm) {
}
}
gifSearchBar.addEventListener('change', () => {searchGifs(gifSearchBar.value)});
gifSearchBar.addEventListener("keydown", function(e) {
if (e.key === 'Enter')
searchGifs(gifSearchBar.value)
})

View File

@ -13,15 +13,9 @@ from files.__main__ import app
def tenor(v, path=None):
searchTerm = request.values.get("searchTerm", "").strip()
limit = 48
try:
limit = int(request.values.get("limit", 48))
except:
pass
if searchTerm and limit:
url = f"https://tenor.googleapis.com/v2/search?media_filter=webp&q={searchTerm}&key={TENOR_KEY}&limit={limit}"
elif searchTerm and not limit:
url = f"https://tenor.googleapis.com/v2/search?media_filter=webp&q={searchTerm}&key={TENOR_KEY}&limit=48"
if searchTerm:
url = f"https://tenor.googleapis.com/v2/search?media_filter=webp&key={TENOR_KEY}&limit=50&q={searchTerm}"
else:
url = f"https://tenor.googleapis.com/v2?media_filter=webp&key={TENOR_KEY}&limit=48"
url = f"https://tenor.googleapis.com/v2/featured?media_filter=webp&key={TENOR_KEY}&limit=50"
return requests.get(url, headers=HEADERS, timeout=5).json()