Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added old site tags + old site option #3

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion database.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
"1400",
"any"
]
},
{
"url": "gifs/100/oldsite_0.gif",
"tags": [
"oldsite",
"100",
"any"
]
}
]
]
Binary file added gifs/100/oldsite_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gifs/200/oldsite_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gifs/300/oldsite_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gifs/300/oldsite_1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gifs/400/oldsite_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gifs/500/oldsite_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gifs/500/oldsite_1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 63 additions & 60 deletions gifsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,83 @@ let xhr = new XMLHttpRequest();
xhr.open("GET", "database.json");
xhr.send();
xhr.onload = () => {
database = JSON.parse(xhr.responseText);
database = JSON.parse(xhr.responseText);
}

function getGifs(searchTags) {
return database.filter(gif => {
for (let tag of searchTags)
if (!gif.tags.includes(tag))
return false;
return true;
});
return database.filter(gif => {
for (let tag of searchTags)
if (!gif.tags.includes(tag))
return false;
return true;
});
}

// Tags that will show up as examples
var allTags = ["any", "hundo", "trueskip", "everred", "noot"];
var allTags = ["any", "hundo", "gemskip", "trueskip", "everred", "noot"];
var everredTags = ["any", "hundo", "trueskip", "gemskip"];
var nootTags = ["any", "hundo"];
var adelieTags = ["any", "hundo", "gemskip"];
var oldsiteTags = ["any", "hundo", "gemskip "];

var tagsField = document.getElementById("tags");
var modSelect = document.getElementById("modName");
let textbox = document.getElementById('search')
let submitButton = document.getElementById('submit');
var tagsField = document.getElementById("tags");
var modSelect = document.getElementById("modName");
let textbox = document.getElementById('search')
let submitButton = document.getElementById('submit');

textbox.addEventListener("keyup", (e) => {
if (e.keyCode === 13)
submitButton.click();
});
textbox.addEventListener("keyup", (e) => {
if (e.keyCode === 13)
submitButton.click();
});

// Function that changes the example tags based on the selected dropdown option
function changeTags() {
var modName = modSelect.options[modSelect.selectedIndex].value;
switch (modName) {
case "all":
tagsField.innerHTML = allTags.join(', ');
break;
case "everred":
tagsField.innerHTML = everredTags.join(', ');
break;
case "adelie":
tagsField.innerHTML = adelieTags.join(', ');
break;
case "noot":
tagsField.innerHTML = nootTags.join(', ');
break;
}
}
// Funtion to be triggered when the dropdown value changes
modSelect.addEventListener("change", changeTags);
// Function that changes the example tags based on the selected dropdown option
function changeTags() {
var modName = modSelect.options[modSelect.selectedIndex].value;
switch (modName) {
case "all":
tagsField.innerHTML = allTags.join(', ');
break;
case "everred":
tagsField.innerHTML = everredTags.join(', ');
break;
case "adelie":
tagsField.innerHTML = adelieTags.join(', ');
break;
case "noot":
tagsField.innerHTML = nootTags.join(', ');
break;
case "oldsite":
tagsField.innerHTML = oldsiteTags.join(', ');
break;
}
}
// Funtion to be triggered when the dropdown value changes
modSelect.addEventListener("change", changeTags);

submitButton.addEventListener('click', () => {
var modName = modSelect.options[modSelect.selectedIndex].value;
if (modName == "all") {
querry = textbox.value;
}
else {
querry = textbox.value + ' ' + modName;
}
let searchTags = new Set(querry.split(/\s+/).filter(x => x != ''));
if (searchTags.size == 0)
return;
submitButton.addEventListener('click', () => {
var modName = modSelect.options[modSelect.selectedIndex].value;
if (modName == "all") {
querry = textbox.value;
} else {
querry = textbox.value + ' ' + modName;
}
let searchTags = new Set(querry.split(/\s+/).filter(x => x != ''));
if (searchTags.size == 0)
return;

let content = document.getElementById('content');
while (content.firstChild) {
content.firstChild.remove();
}
let content = document.getElementById('content');
while (content.firstChild) {
content.firstChild.remove();
}

let gifResults = getGifs(searchTags);
for (let gif of gifResults) {
let img = document.createElement("img");
img.src = gif.url;
img.title = 'Tags: ' + gif.tags.join(", ");
let gifResults = getGifs(searchTags);
for (let gif of gifResults) {
let img = document.createElement("img");
img.src = gif.url;
img.title = 'Tags: ' + gif.tags.join(", ");

content.appendChild(img);
}
});
content.appendChild(img);
}
});

window.onload = changeTags();
window.onload = changeTags();
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<option value="adelie" selected="selected">Adelie</option>
<option value="everred">Everred</option>
<option value="noot">Noot</option>
<option value="oldsite">Old Site</option>
</select>
<input id='search' type='text' placeholder="e.g. 1100"></input>
<button id='submit' type="button">Search</button>
Expand Down