This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
script.js
117 lines (98 loc) · 3.39 KB
/
script.js
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
//DARK MODE
const checkBox = document.getElementById('checkbox');
function theme(navColor, bodyColor) {
document.getElementById('tabColor').setAttribute("content", navColor);
document.getElementById('nav').style.backgroundColor = navColor;
document.body.style.backgroundColor = bodyColor;
}
//prefers color scheme
let colorSchemeQueryList = matchMedia('(prefers-color-scheme: dark)');
const setColorScheme = e => {
if (e.matches) {
theme("#1f1f1f", "#121212");
checkBox.checked = true;
} else {
theme("#ff4548", "white");
checkBox.checked = false;
}
}
setColorScheme(colorSchemeQueryList);
colorSchemeQueryList.addListener(setColorScheme);
//local storage
if (localStorage.getItem('data-theme')) {
theme("#1f1f1f", "#121212");
checkBox.checked = true;
}
checkBox.addEventListener('click', () => {
if (checkBox.checked) {
localStorage.setItem('data-theme', "#1f1f1f");
theme("#1f1f1f", "#121212");
} else {
localStorage.clear();
theme("#ff4548", "white");
}
});
//SEARCH
const search = document.getElementById("search_input");
const categories = document.getElementsByClassName('uk-card');
const search_list = document.getElementsByTagName('li');
document.getElementById('search_button').onclick = () => {
for (const i of categories) {
if (i.nextElementSibling.classList.contains('hide'))
i.click();
i.classList.add('hide');
}
}
document.getElementsByClassName('uk-navbar-toggle')[0].onclick = () => {
search.value = '';
for (const li of search_list) li.style.display = 'list-item';
for (const i of categories) {
i.click();
i.classList.remove('hide');
}
}
search.addEventListener('keyup', () => {
for (const x of search_list)
x.style.display = !x.textContent.toLowerCase().includes(search.value.toLowerCase()) ?
"none" :
"list-item";
});
// DATA INJECTION
fetch('https://raw.githubusercontent.com/wiki/n-ce/YTFLIX/Home.md')
.then(res => res.text())
.then(homeMD => JSON.parse(homeMD.slice(3)))
.then(homeData => {
for (const category of homeData) {
fetch(`https://raw.githubusercontent.com/wiki/n-ce/YTFLIX/${category.name}.md`)
.then(res => res.text())
.then(categoryMD => JSON.parse(categoryMD.slice(3)))
.then(categoryJSON => {
const h3 = document.createElement('h3');
h3.classList.add("uk-card-title", "uk-text-bolder");
h3.textContent = category.name;
const p = document.createElement('p');
p.id = 'text';
p.textContent = category.description;
const a = document.createElement('a');
a.classList.add("uk-accordion-title", "uk-card", "uk-card-hover", "uk-card-body", "uk-background-cover", "uk-card-secondary");
a.dataset.src = category.thumbnail;
a.setAttribute('uk-img', '');
a.append(h3, p);
const ul = document.createElement('ul');
ul.id = category.name;
ul.classList.add("uk-accordion-content", "uk-list", "uk-list-large", "uk-list-divider", "hide")
for (const object of categoryJSON) {
const list = document.createElement('li');
const anchor = document.createElement('a');
anchor.href = "https://youtube.com/" + object.URL;
anchor.textContent = object.Name;
list.appendChild(anchor);
ul.appendChild(list);
}
const li = document.createElement('li');
li.append(a, ul);
li.setAttribute('onclick', `document.getElementById('${category.name}').classList.toggle("hide")`);
document.getElementById('container').appendChild(li);
})
}
});