-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
374 lines (327 loc) · 13.1 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<title>جستجوی فیلمها و سریالهای ایرانی</title>
<script src="vue.global.js"></script>
<style>
* {
font-family: system-ui;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: light-dark(#f5f5f5, #121212);
color: light-dark(black, #e0e0e0);
margin: 0;
direction: rtl;
transition: background-color 0.3s, color 0.3s;
}
#app {
max-width: 800px;
padding: 20px;
background-color: light-dark(#fff, #1e1e1e);
border-radius: 16px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
width: 90%;
transition: background-color 0.3s, color 0.3s;
}
input[type="text"] {
width: 98%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 16px;
}
.options {
display: flex;
flex-wrap: wrap;
gap: 20px;
justify-content: space-around;
margin-bottom: 10px;
border: none;
}
@media (max-width: 768px) {
.options {
flex-direction: column;
align-items: flex-start;
gap: 10px;
}
.options label {
width: 100%;
}
}
.results-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 10px;
}
.item-card {
text-align: center;
padding: 10px;
background: light-dark(#fff, #292929);
border: 1px solid light-dark(#ddd, #444);
border-radius: 16px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
transition: background-color 0.3s, border-color 0.3s;
}
.item-image {
width: 100%;
object-fit: contain;
border-radius: 4px;
background-color: #f0f0f0;
margin-bottom: 10px;
transition: filter 0.3s;
}
.item-title {
font-weight: bold;
}
.item-designer {
font-size: 0.9em;
color: #555;
margin-top: 5px;
}
.item-designer a {
color: #007bff;
text-decoration: none;
}
.item-designer a:hover {
text-decoration: underline;
}
.item-links a {
color: #007bff;
text-decoration: none;
margin: 0 5px;
}
.negative-mode-toggle {
position: fixed;
top: 10px;
left: 10px;
padding: 10px 15px;
background-color: #333;
color: #fff;
border: none;
border-radius: 20px;
cursor: pointer;
transition: background-color 0.3s, color 0.3s;
}
</style>
</head>
<body>
<div id="app">
<input type="text" v-model="searchTerm" placeholder="جستجو…" />
<div class="options">
<fieldset style="border: none; padding: 0; margin: 0;">
<label><input type="radio" v-model="posterMode" :value="false" /> لوگوها</label>
<label><input type="radio" v-model="posterMode" :value="true" /> پوسترها</label>
</fieldset>
<label>
<input type="checkbox" v-model="combineSimilarChars" /> حروف مشابه
</label>
<label>
⇵
<select v-model="sortOrder">
<option value="alphabetical">الفبایی</option>
<option value="year">سال تولید</option>
<option value="random">تصادفی</option>
</select>
</label>
<label>
سال:
<select v-model="selectedYear">
<option value="">همه</option>
<option v-for="[year, count] in filteredYears" :key="year" :value="year">{{ year }} ({{ count }})</option>
</select>
</label>
<label>
طراح:
<select v-model="selectedDesigner">
<option value="">همه</option>
<option v-for="[designer, count] in filteredDesigners" :key="designer" :value="designer">{{ designer }} ({{ count }})</option>
</select>
</label> </div>
<div v-if="filteredItems.length > 0" style="text-align: center; padding-bottom: .5em;">
{{ filteredItems.length.toLocaleString('fa') }} از {{ items.length.toLocaleString('fa') }}
</div>
<div v-if="filteredItems.length > 0" class="results-grid">
<div class="item-card" v-for="(item, index) in (isShowMore ? filteredItems : filteredItems.slice(0, 30))" :key="index">
<a :href="getImageLink(item)" target="_blank"><img :src="getImageUrl(item)" :alt="item.filmLabel"
class="item-image" /></a>
<div class="item-title">{{ getItemTitleWithYear(item) }}</div>
<div v-if="item.designer && item.designerLabel" class="item-designer">
طراح: <a :href="item.designer" target="_blank">{{ item.designerLabel }}</a>
</div>
<div class="item-links">
<a :href="getImdbLink(item.imdbID)" target="_blank">T</a>
<a :href="getWikidataLink(item.film)" target="_blank">Q</a>
</div>
</div>
</div>
<p v-else>نتیجهای برای نمایش وجود ندارد.</p>
<div v-if="!isShowMore && filteredItems.length > 30" style="text-align: center; padding-top: 1em;">
<button @click="showMore">نمایش بیشتر</button>
</div>
</div>
<script>
const { createApp, ref, computed } = Vue;
Object.groupBy = function (array, keyGetter) {
return array.reduce((result, item) => {
const key = keyGetter(item);
if (!result[key]) {
result[key] = [];
}
result[key].push(item);
return result;
}, {});
};
async function getAllItems() {
const response = await fetch(
'https://query.wikidata.org/bigdata/namespace/wdq/sparql',
{
method: 'POST',
headers: {
'Content-Type': 'application/sparql-query',
'Accept': 'application/json'
},
body: `
SELECT DISTINCT ?film ?filmLabel (GROUP_CONCAT(DISTINCT ?alias; separator=", ") AS ?aliases) (MIN(?publicationDate) AS ?date) ?imdbID ?poster ?logo ?designer ?designerLabel WHERE {
VALUES ?type { wd:Q11424 wd:Q24862 wd:Q5398426 wd:Q7777570 wd:Q17517379 }
?film wdt:P31 ?type;
wdt:P495 wd:Q794.
?film p:P3383 ?imageStatement.
?imageStatement ps:P3383 ?poster.
OPTIONAL { ?imageStatement pq:P170 ?designer. }
OPTIONAL { ?film p:P154 ?logoStatement.
?logoStatement ps:P154 ?logo. }
OPTIONAL { ?film wdt:P577 ?publicationDate. }
OPTIONAL { ?film wdt:P345 ?imdbID. }
OPTIONAL { ?film skos:altLabel ?alias.
FILTER(LANG(?alias) = "fa") }
SERVICE wikibase:label { bd:serviceParam wikibase:language "fa". }
}
GROUP BY ?film ?filmLabel ?imdbID ?poster ?designer ?designerLabel ?logo
ORDER BY ?publicationDate
`
}
);
const data = await response.json();
return data.results.bindings.map(x => Object.fromEntries(Object.entries(x).map(x => [x[0], x[1].value])));
}
createApp({
setup() {
const darkMode = ref(false);
const toggleDarkMode = () => {
darkMode.value = !darkMode.value;
};
const isShowMore = ref(false);
const showMore = () => {
isShowMore.value = true;
};
/*
resetFilters() {
this.searchTerm = '';
this.posterMode = false;
this.combineSimilarChars = false;
this.sortOrder = 'default';
this.selectedYear = '';
},
*/
const sortOrder = ref('random');
const searchTerm = ref('');
const combineSimilarChars = ref(false);
const posterMode = ref(false);
const selectedYear = ref('');
const selectedDesigner = ref('');
const items = ref([]);
getAllItems().then(result => items.value = result);
const similarCharsMapping = {
'ط': '[طظ]', 'ظ': '[طظ]', 'ب': '[بپتثنی]', 'پ': '[بپتثنی]',
'ت': '[بپتثنی]', 'ث': '[بپتثنی]', 'ن': '[بپتثنی]', 'ی': '[بپتثنی]', 'ج': '[جچحخ]',
'چ': '[جچحخ]', 'ح': '[جچحخ]', 'خ': '[جچحخ]', 'د': '[دذ]',
'ذ': '[دذ]', 'ر': '[رزژ]', 'ز': '[رزژ]', 'ژ': '[رزژ]', 'س': '[سش]',
'ش': '[سش]', 'ص': '[صض]', 'ض': '[صض]', 'ع': '[عغ]',
'غ': '[عغ]', 'ف': '[فق]', 'ق': '[فق]', 'ک': '[کگ]',
'گ': '[کگ]'
};
const toPersianYear = date => {
const year = new Date(date).toLocaleDateString('fa').split('/')[0];
return year === 'Invalid Date' ? 'ناموجود' : year;
};
const availableYears = computed(() => {
const groups = Object.groupBy(items.value, item => toPersianYear(item.date));
return Object.keys(groups).sort().map(year => [year, groups[year].length.toLocaleString('fa')]);
});
const availableDesigners = computed(() => {
const groups = Object.groupBy(items.value.filter(x => x.designerLabel), item => item.designerLabel);
return Object.keys(groups)
.map(designer => [designer, groups[designer].length])
.sort((a, b) => b[1] - a[1])
.map(([designer, count]) => [designer, count.toLocaleString('fa')]);
});
const getItemTitleWithYear = item => {
return item.filmLabel + (item.date ? ` (${toPersianYear(item.date)})` : '');
};
const filteredItems = computed(() => {
let results = items.value;
if (searchTerm.value.length) {
const modifiedSearchTerm = searchTerm.value
.split('')
.map(char => (combineSimilarChars.value ? (similarCharsMapping[char] || char) : char))
.join('');
const regex = new RegExp(modifiedSearchTerm, 'i');
results = results.filter(item => regex.test(item.filmLabel) || regex.test(item.aliases || ''));
}
if (selectedYear.value) {
results = results.filter(item => toPersianYear(item.date) === selectedYear.value);
}
if (selectedDesigner.value) {
results = results.filter(item => item.designerLabel === selectedDesigner.value);
}
if (sortOrder.value === 'alphabetical') {
results = results.sort((a, b) => a.filmLabel.localeCompare(b.filmLabel, 'fa'));
} else if (sortOrder.value === 'year') {
results = results.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
} else if (sortOrder.value === 'random') {
results = results.slice().sort(() => Math.random() - 0.5);
}
return results;
});
const filteredYears = computed(() => {
const groups = Object.groupBy(filteredItems.value, item => toPersianYear(item.date));
return Object.keys(groups)
.sort()
.map(year => [year, groups[year].length.toLocaleString('fa')]);
});
const filteredDesigners = computed(() => {
const groups = Object.groupBy(filteredItems.value.filter(x => x.designerLabel), item => item.designerLabel);
return Object.keys(groups)
.map(designer => [designer, groups[designer].length])
.sort((a, b) => b[1] - a[1])
.map(([designer, count]) => [designer, count.toLocaleString('fa')]);
});
const getPosterUrl = (filePath, width = 600) => {
if (!filePath) return 'https://via.placeholder.com/300x420?text=No+Poster';
const url = new URL('https://commons.wikimedia.org/w/thumb.php');
url.searchParams.append('f', decodeURIComponent(filePath.replace('http://commons.wikimedia.org/wiki/Special:FilePath/', '')));
url.searchParams.append('w', '600');
return url.toString();
};
const getLogoUrl = item => item.logo ? getPosterUrl(item.logo) : 'https://via.placeholder.com/300x200?text=No+Logo';
const getImageUrl = item => posterMode.value ? getPosterUrl(item.poster) : getLogoUrl(item);
const getImageLink = item => posterMode.value ? item.poster : item.logo;
const getImdbLink = imdbID => `https://www.imdb.com/title/${imdbID}`;
const getWikidataLink = film => film;
return { showMore, isShowMore, searchTerm, combineSimilarChars, posterMode, filteredItems, items, getImageUrl, getImdbLink, getWikidataLink, getItemTitleWithYear, darkMode, toggleDarkMode, sortOrder, selectedYear, availableYears, availableDesigners, selectedDesigner, getImageLink, filteredYears, filteredDesigners };
}
}).mount('#app');
</script>
</body>
</html>