-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
121 lines (98 loc) · 3.31 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GIFfer</title>
<link rel="stylesheet" href="src/assets/styles.css">
</head>
<body>
<div class="container">
<h1>GIFfer</h1>
<div id="search-container">
<input
type="text"
id="search-input"
placeholder="...?"
autocomplete="off"
>
<button id="reset-button">Refresh</button>
<button id="open-folder-button" class="folder-button">Open GIFs Folder</button>
</div>
<div id="gif-gallery"></div>
<div id="modal" class="modal">
<div class="modal-content">
<span class="close-button">×</span>
<h2>Edit Tags</h2>
<p id="modal-filename"></p>
<input type="text" id="modal-tags-input" placeholder="Enter tags, separated by commas">
<button id="save-tags-button">Save Tags</button>
</div>
</div>
<div id="notification" class="notification"></div>
</div>
<script src="src/assets/renderer.js">
const TAGS_URL = './tags.json';
const GIFS_FOLDER = './gifs/';
let tagsData = {};
// Function to fetch and display GIFs
const fetchAndDisplayGIFs = () => {
fetch(TAGS_URL)
.then(response => response.json())
.then(data => {
tagsData = data;
displayGIFs(tagsData);
})
.catch(error => {});
};
// Initial fetch
fetchAndDisplayGIFs();
function displayGIFs(data) {
const gallery = document.getElementById('gif-gallery');
gallery.innerHTML = '';
for (const [filename, tags] of Object.entries(data)) {
const gifDiv = document.createElement('div');
gifDiv.classList.add('gif-item');
const img = document.createElement('img');
img.src = GIFS_FOLDER + filename;
img.alt = filename;
const tagsDiv = document.createElement('div');
tagsDiv.classList.add('tags');
tags.forEach(tag => {
const tagSpan = document.createElement('span');
tagSpan.classList.add('tag');
tagSpan.textContent = tag;
tagsDiv.appendChild(tagSpan);
});
gifDiv.appendChild(img);
gifDiv.appendChild(tagsDiv);
gallery.appendChild(gifDiv);
}
}
document.getElementById('search-button').addEventListener('click', () => {
const searchTerm = document.getElementById('search-input').value.trim().toLowerCase();
if (searchTerm === '') {
alert('Please enter a tag to search.');
return;
}
const filteredData = {};
for (const [filename, tags] of Object.entries(tagsData)) {
if (tags.map(tag => tag.toLowerCase()).includes(searchTerm)) {
filteredData[filename] = tags;
}
}
displayGIFs(filteredData);
});
document.getElementById('reset-button').addEventListener('click', () => {
document.getElementById('search-input').value = '';
fetchAndDisplayGIFs();
});
document.getElementById('search-input').addEventListener('keyup', function(event) {
if (event.key === 'Enter') {
document.getElementById('search-button').click();
}
});
setInterval(fetchAndDisplayGIFs, 5000);
</script>
</body>
</html>