-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
231 lines (197 loc) · 7.54 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simplecode Bookmarks</title>
<!-- Add Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
/* Custom styles */
body {
font-family: 'Ubuntu', sans-serif;
color: #333; /* Text color */
}
h1, h2 {
color: #333; /* Text color */
}
.container {
background-color: #fff; /* White background */
border-radius: 10px;
padding: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.btn-primary {
background-color: #333; /* Dark button color */
border-color: #333; /* Dark button border color */
color: #fff; /* Button text color */
}
.list-group-item {
color: #fff; /* List item text color */
}
body {
background-color: unset;
background-image: url('assets/img/bg_dotted.png');
}
.form-control {
background-color: unset;
box-shadow: 0px 1px 5px #bbb;
box-shadow: 0px 1px 5px #bbb;
}
.list-group-item {
background-color: unset;
color: black;
}
.container {
box-shadow: 0px 1px 5px #bbb;
}
.btn-primary {
box-shadow: 0px 1px 5px #bbb;
}
.btn:not(:disabled):not(.disabled) {
box-shadow: 0px 1px 5px #bbb;
}
</style>
</head>
<body>
<div class="container">
<h1>Simplecode Bookmarks</h1>
<br>
<h2>Tags</h2>
<!-- Search bar for Tags -->
<input type="text" id="tagsSearch" class="form-control mb-3" placeholder="Search Tags">
<div id="tagsPanel">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#tagsCollapse">Toggle Tags</button>
<div id="tagsCollapse" class="collapse">
<ul id="tags" class="list-group">
<!-- Tags will be populated here -->
</ul>
</div>
</div>
<br>
<h2>Links</h2>
<!-- Search bar for Links -->
<input type="text" id="linksSearch" class="form-control mb-3" placeholder="Search Links">
<div id="linksPanel">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#linksCollapse">Toggle Links</button>
<button id="linksShuffleBtn" class="btn btn-primary" type="button">Shuffle Links</button>
<div id="linksCollapse" class="show">
<ul id="links" class="list-group">
<!-- Tags will be populated here -->
</ul>
</div>
</div>
</div>
<!-- Add Bootstrap and jQuery JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
// Sample JSON data
function fetchJSON(url) {
return fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
});
}
const sourcesUrl = 'sources.json';
fetchJSON(sourcesUrl).then(sourcesData => {
sourcesData.sources.forEach((sourcesItem) => {
fetchJSON(sourcesItem).then(sourcesItemData => {
populateTags(sourcesItemData);
populateLinks(sourcesItemData);
linksShuffle();
}).catch(error => {
console.error('Error:', error);
});
});
}).catch(error => {
console.error('Error:', error);
});
let populateTagsHistory = [];
// Function to populate Tags
function populateTags(sourceItemData) {
const tagsList = document.getElementById("tags");
sourceItemData.Tags.forEach((tag, index) => {
if (!populateTagsHistory.includes(tag)) {
const li = document.createElement("li");
li.className = "list-group-item";
li.textContent = tag;
tagsList.appendChild(li);
populateTagsHistory.push(tag);
}
});
}
// Function to populate Links
function populateLinks(sourceItemData) {
const linksContainer = document.getElementById("links");
sourceItemData.Links.forEach((link) => {
const linkDiv = document.createElement("li");
linkDiv.className = "list-group-item";
linkDiv.innerHTML = `
<h3>${link.Name}</h3>
<p><i>Posted by ${link.Poster}</i></p>
<p><a href="${link.Link}" target="_blank">${link.Link}</a></p>
<p>Tags: ${link.Tags.map(tagIndex => sourceItemData.Tags[tagIndex]).join(", ")}</p>
`;
linksContainer.appendChild(linkDiv);
});
}
// Function to handle search for Tags
function searchTags() {
const searchValue = document.getElementById("tagsSearch").value.toLowerCase();
const tagsList = document.getElementById("tags");
for (let i = 0; i < tagsList.children.length; i++) {
const tag = tagsList.children[i];
const tagText = tag.textContent.toLowerCase();
if (tagText.includes(searchValue)) {
tag.style.display = "block";
} else {
tag.style.display = "none";
}
}
// Check if the Links panel is collapsed, and expand it if it is
const tagsCollapse = document.getElementById("tagsCollapse");
if (tagsCollapse.classList.contains("collapse")) {
tagsCollapse.classList.remove("collapse");
}
}
// Function to handle search for Links
function searchLinks() {
const searchValue = document.getElementById("linksSearch").value.toLowerCase();
const linksContainer = document.getElementById("links");
for (let i = 0; i < linksContainer.children.length; i++) {
const linkDiv = linksContainer.children[i];
const linkText = linkDiv.textContent.toLowerCase();
if (linkText.includes(searchValue)) {
linkDiv.style.display = "block";
} else {
linkDiv.style.display = "none";
}
}
// Check if the Links panel is collapsed, and expand it if it is
const linksCollapse = document.getElementById("linksCollapse");
if (linksCollapse.classList.contains("collapse")) {
linksCollapse.classList.remove("collapse");
}
}
// Add event listeners for search bars
document.getElementById("tagsSearch").addEventListener("input", searchTags);
document.getElementById("linksSearch").addEventListener("input", searchLinks);
function linksShuffle() {
let rows = Array.from(document.getElementById("links").getElementsByTagName('li'));
for (let i = rows.length - 1; i > 0; i--) {
let randomness = Math.floor(Math.random() * (i + 1));
[rows[i], rows[randomness]] = [rows[randomness], rows[i]];
}
for (const row of rows) {
document.getElementById("links").appendChild(row);
}
}
document.getElementById("linksShuffleBtn").addEventListener("click", linksShuffle);
</script>
</body>
</html>