-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
308 lines (263 loc) · 12.6 KB
/
index.html
File metadata and controls
308 lines (263 loc) · 12.6 KB
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
<html>
<head>
<title>Bảng thông tin | Dương Thái Bảo - IUH</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<style>
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.animate-spin {
animation: spin 1s linear infinite;
}
.nav{
top: 0;
width: 100%;
}
body{
display: flex;
flex-direction: column;
min-height: 100dvh;
}
.main{
flex: 1;
}
</style>
<div type="variable" name="version" value="1.1.9"></div>
<body class="bg-gray-100 font-sans">
<!-- Navbar -->
<div class="flex justify-between items-center bg-gray-700 text-white px-8 py-3 nav">
<div>
<a href="https://dtbao.io.vn" class="text-lg font-semibold hover:underline">
<img src="images/avt-40x40.jpg" alt="Profile picture of Bao Duong" class="rounded-full">
</a>
</div>
<div>
<h3 class="text-xl md:text-2xl font-bold">BẢNG THÔNG TIN (V<script>document.write(document.querySelector("div[type='variable'][name='version']").getAttribute("value"))</script>)</h3>
</div>
<div>
</div>
</div>
<!-- Input secret code-->
<div class="mt-8 markdown main hidden" id="input-code">
<div class="max-w-xl mx-auto bg-white rounded-lg shadow p-4 mb-6">
<div class="font-semibold text-red-500">❗ Vui lòng nhập mã của dự án để tiếp tục:</div>
<form action="#" class="flex flex-col p-4 w-full">
<p for="code" class="text-sm font-semibold text-gray-700 mb-2 mt-4">Mã dự án:</p>
<input type="text" name="id" class="w-full p-2 border border-gray-300 rounded-md" placeholder="Nhập mã dự án">
<button type="submit" class="bg-blue-500 text-white p-2 rounded-md mt-6 w-full">Xác nhận</button>
</form>
</div>
</div>
<div class="mt-8 markdown main" id="posts">
<!-- Loading -->
<div id="loading" class="text-center p-4">
<svg class="animate-spin h-6 w-6 mx-auto" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<circle cx="12" cy="12" r="10" stroke-width="4" class="text-blue-500 opacity-25" />
<path d="M12 6v6m0 0v6m0-6h6m-6 0H6" stroke="currentColor" stroke-width="4" class="text-blue-500" />
<span>Đang tải nội dung, vui lòng chờ...</span>
</div>
<!--
<div class="max-w-xl mx-auto bg-white rounded-lg shadow p-4 mb-6">
<div class="text-sm font-semibold text-red-500">❗ IMPORTANT</div>
<div class="flex items-start space-x-4 p-4">
<a href="https://dtbao.io.vn?s=bangthongtin" target="_blank" ><img src="images/avt-40x40.jpg" alt="Profile picture of Bao Duong" class="rounded-full"></a>
<div>
<div class="text-sm font-semibold text-blue-500 hover:underline"><a href="https://dtbao.io.vn?s=bangthongtin" target="_blank" >Bao Duong</a></div>
<div class="text-xs text-gray-500">December 20, 2023 · <i class="fas fa-globe-asia"></i></div>
<div class="text-sm mt-2">
Nội dung tuần này:<br>
Xin chào Hellooo<br>
Allo
</div>
</div>
</div><div class="flex justify-end">
<div class="text-xs text-gray-500">...</div>
</div>
</div>
-->
</div>
<div class="text-center flex flex-row aligns-center justify-center mb-8 hidden" id="sec-offset">
<div class="text-gray-700 me-2">Trang</div>
<ol class="flex gap-2" id="page-offset">
</ol>
</div>
<!-- footer -->
<div class="bg-gray-700 text-white text-center py-4 footer">
<div>
<p class="text-sm">© <script>document.write(new Date().getFullYear())</script> Trang được thiết kế và xây dựng bởi Dương Thái Bảo - IUH<br>Mọi hành vi sao chép ý tưởng đều là vi phạm bản quyền.</p>
</div>
</div>
</body>
<script type="text/javascript" src="js/drawdown.js"></script>
<script type="text/javascript">
const OFFSET = 5;
//get parameter from url
const urlParams = new URLSearchParams(window.location.search);
const id = urlParams.get('id');
const currentPage = urlParams.get('page') ? urlParams.get('page') : 1;
const API_URL = "<REPLACE_UR_URL_HERE>";
const offset = (currentPage - 1) * OFFSET;
// scroll
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) {
document.getElementsByClassName("nav")[0].style.position = "fixed";
} else {
document.getElementsByClassName("nav")[0].style.position = "unset";
}
}
function applyMarkdownStyles(styles, parentElement) {
for (const [selector, classList] of Object.entries(styles)) {
if (typeof selector === 'string' && Array.isArray(classList)) {
// Chỉ áp dụng class cho các phần tử con trong parentElement
parentElement.querySelectorAll(selector).forEach(el => el.classList.add(...classList));
} else {
console.warn(`Invalid selector or classList for: ${selector}`);
}
}
return parentElement.outerHTML;
}
// Định nghĩa các style cho các phần tử Markdown
const markdownStyles = {
'h1': ['text-3xl', 'font-bold', 'text-blue-600', 'mt-6', 'mb-4'],
'h2': ['text-2xl', 'font-semibold', 'text-blue-500', 'mt-5', 'mb-3'],
'h3': ['text-xl', 'font-medium', 'text-blue-400', 'mt-4', 'mb-2'],
'p': ['text-base', 'text-gray-700', 'mt-2', 'mb-4', 'leading-relaxed'],
'ul': ['list-disc', 'list-inside', 'pl-5', 'mt-2', 'mb-4'],
'ol': ['list-decimal', 'list-inside', 'pl-5', 'mt-2', 'mb-4'],
'li': ['text-gray-700', 'mb-2'],
'a': ['text-blue-500', 'hover:underline'],
'code': ['bg-gray-100', 'text-red-500', 'font-mono', 'px-1', 'py-0.5', 'rounded'],
'pre': ['bg-gray-900', 'text-white', 'p-4', 'rounded-md', 'overflow-x-auto', 'my-4'],
'blockquote': ['border-l-4', 'border-blue-300', 'pl-4', 'italic', 'text-gray-600', 'my-4']
};
function createTag(tag, isPinned){
var tagTrans = "🔔 KHÔNG XÁC ĐỊNH";
var classTag = "text-sm font-semibold text-yellow-500";
switch (tag){
case "IMPORTANT":
tagTrans = "⚠️ QUAN TRỌNG";
classTag = "text-sm font-semibold text-yellow-500";
break;
case "INFO":
tagTrans = "ℹ️ THÔNG TIN";
classTag = "text-sm font-semibold text-blue-500";
break;
case "UPDATE":
tagTrans = "🔔 CẬP NHẬT";
classTag = "text-sm font-semibold text-yellow-500";
break;
case "REQUIRE_ACTION":
tagTrans = "❗ YÊU CẦU THỰC HIỆN";
classTag = "text-sm font-semibold text-red-500";
break;
case "ERROR":
tagTrans = "❗ LỖI";
classTag = "text-sm font-semibold text-red-500";
break;
default:
tagTrans = "🔔 KHÔNG XÁC ĐỊNH";
classTag = "text-sm font-semibold text-yellow-500";
break;
}
if (isPinned){
return `<div class='text-sm font-semibold text-red-500'>📌 ĐƯỢC GHIM (TAG_${tag})</div>`;
}
return `<div class='${classTag}'>${tagTrans}</div>`;
}
function createName(name){
return "<a href=\"https://dtbao.io.vn?s=bangthongtin\" target=\"_blank\" class='text-sm font-semibold text-blue-500 hover:underline'>" + name + "</a>";
}
function createAvatar(avatar){
return "<a href='" + avatar + "' target='_blank'><img src='images/avt-40x40.jpg' alt='Profile picture of Bao Duong' class='rounded-full'></a>";
}
function createDate(date){
return "<div class='text-xs text-gray-500'>" + date + " · <i class='fas fa-globe-asia'></i></div>";
}
function createContent(content){
const div = document.createElement('div');
div.innerHTML = markdown(content);
div.classList.add('mt-2');
return applyMarkdownStyles(markdownStyles, div);
}
function createPostElement(tag, name, avatar, date, content, isPinned){
return createTag(tag, isPinned) + "<div class='flex items-start space-x-4 p-4'>" + createAvatar(avatar) + "<div>" + createName(name) + createDate(date) + createContent(content) + "</div></div>";
}
function createPost(tag, name, avatar, date, content, isPinned){
var post = document.createElement("div");
post.className = "max-w-xl mx-auto bg-white rounded-lg shadow p-4 mb-6";
post.innerHTML = createPostElement(tag, name, avatar, date, content, isPinned);
return post;
}
function createElementPageOffset(page){
var li = document.createElement("li");
li.className = "inline-block";
var a = document.createElement("a");
// get current page
const urlParams = new URLSearchParams(window.location.search);
if (!currentPage || currentPage == page){
a.href = "#";
}else {
// get current url & params, add page-offset
var url = new URL(window.location.href);
url.searchParams.set('page', page);
a.href = url.href;
console.log(url.href);
}
a.className = "text-blue-500 hover:underline";
a.innerHTML = page;
li.appendChild(a);
return li;
}
function getPosts(){
var posts = document.getElementById("posts");
fetch(`${API_URL}?id=${id}&offset=${offset}`)
.then(response => response.json()).then(result => {
document.getElementById("sec-offset").classList.toggle("hidden", false);
//result.errorCode = 500;
//result.total = null;
const totalData = result.total ?? 1;
const totalPage = totalData % 10 == 0 ? totalData / 10 : Math.floor(totalData / 10) + 1;
var pageOffset = document.getElementById("page-offset");
for (var i = 1; i <= totalPage + 1; i++){
var li = createElementPageOffset(i);
pageOffset.appendChild(li);
}
if (result.errorCode != 200){
var post = createPost("ERROR", "Bao Duong", "https://dtbao.io.vn?s=bangthongtin", "Bây giờ", "Server trả lỗi: " + result.errorCode + " (" + result.message +"). Hãy thử lại lại trang nhé!", true);
posts.appendChild(post);
return;
}
const data = result.data;
if (data.length == 0){
var post = createPost("INFO", "Bao Duong", "https://dtbao.io.vn?s=bangthongtin", "Bây giờ", "Không có nội dung nào được đăng tải hoặc dự án này không tồn tại!\n\nMã dự án: `"+ id +"`", true);
posts.appendChild(post);
return;
}
for (var i = 0; i < data.length; i++){
var post = createPost(data[i].type, "Bao Duong", "https://dtbao.io.vn?s=bangthongtin", data[i].timestamp, data[i].notification, data[i].isPinned ?? false);
posts.appendChild(post);
}
}).catch(error => {
var post = createPost("ERROR", "Bao Duong", "https://dtbao.io.vn?s=bangthongtin", "Bây giờ", "Load nội dung thất bại, hãy [reload lại trang]("+ window.location.href.replace("#", "") +"), nếu không được xin hãy mở bằng Chrome!\n\nCode dự án nếu cần: `" + id+"`", true);
posts.appendChild(post);
console.log(error);
}).finally(() => {
document.getElementById("loading").style.display = "none";
});
}
window.onload = ()=> {
if (!id || id == "" || id.trim() == ""){
document.getElementById("input-code").classList.toggle("hidden", false);
document.getElementById("loading").style.display = "none";
return;
} else {
getPosts();
}
};
</script>
</html>