add "trending" category, fix blank gif search, make it easier, and remove unnecessary clutter
parent
b00e724267
commit
392bd92163
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue