-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
286 lines (275 loc) · 10.6 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
<!DOCTYPE html>
<!--suppress ALL -->
<html lang="zh">
<head>
<title>SPX Browser</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui" name="viewport">
<meta charset="UTF-8">
</head>
<body>
<div id="root">
<v-app>
<v-main>
<v-app-bar :color="$vuetify.theme.dark ? 'dark' : 'white'">
<v-toolbar-title>SPX Browser</v-toolbar-title>
<v-spacer></v-spacer>
<v-tooltip bottom>
<template v-slot:activator="{ on, attrs }">
<v-btn icon v-bind="attrs" v-on="on" text @click="$vuetify.theme.dark = !$vuetify.theme.dark">
<v-icon v-if="$vuetify.theme.dark">mdi-brightness-7</v-icon>
<v-icon v-else>mdi-brightness-4</v-icon>
</v-btn>
</template>
<span>夜间模式切换</span>
</v-tooltip>
</v-app-bar>
<v-container>
<div>
<v-card class="ma-3 px-3 my-6">
<v-container>
<h5 class="text-h5 text-center my-3">SPX Browser</h5>
<p>SPX Browser 是由开源社区 SPX Fellow 提供的博文目录浏览器,在这里您可以获取最新的 Minecraft.net 博文,并且阅读部分文章的译文。</p>
<p>SPX Fellow 还提供以下服务:</p>
<ul>
<li><a href="https://github.com/SPXFellow/spxx">SPXX 用户脚本</a>:将 Minecraft.net 的博文进行自动排版为 BBCode 格式。</li>
<li><a href="https://crowdin.com/project/spxx/zh-CN">SPXX Bug Center</a>:为新修复的 Minecraft Java 版漏洞提供翻译。</li>
<li><a href="https://github.com/SPXFellow/whitepaper">SPXDesgin 白皮书</a>:Minecraft.net 博文的 BBCode 排版方案手册。</li>
</ul>
</v-container>
</v-card>
</div>
<v-card class="ma-3 px-3 my-6 pb-4">
<v-container>
<h5 class="text-h5 text-center my-3">文章</h5>
<div v-if="loading.filters" class="text-center">
<v-progress-circular
:size="40"
:width="7"
color="indigo"
indeterminate
></v-progress-circular>
</div>
<div v-else>
<div class="mx-3 mb-3" id="filters">
<v-chip-group v-model="checkboxes" active-class="primary--text" column multiple>
<legend class="v-label pr-2"
style="left: 0px; right: auto; position: relative; line-height: 2.38;">
<div>一般分类</div>
</legend>
<v-chip v-for="item in categories">{{ item.toUpperCase().replace('-', ' ') || '无' }}
</v-chip>
</v-chip-group>
<v-chip-group v-model="artCheckboxes" active-class="primary--text" column multiple>
<legend class="v-label pr-2"
style="left: 0px; right: auto; position: relative; line-height: 2.38;">
<div>创作分类</div>
</legend>
<v-chip v-for="item in artCategories">{{ item.toUpperCase().replace('-', ' ') || '无'
}}
</v-chip>
</v-chip-group>
<v-chip-group v-model="statusInput" active-class="primary--text" multiple column>
<legend class="v-label pr-2"
style="left: 0px; right: auto; position: relative; line-height: 2.38;">
<div>文章状态</div>
</legend>
<v-chip>已翻译</v-chip>
<v-chip>未翻译</v-chip>
</v-chip-group>
</div>
<v-card class="mx-3">
<v-simple-table height="500px" fixed-header>
<template v-slot:default>
<thead>
<tr>
<th>时间</th>
<th>分类</th>
<th>原文</th>
<th>译文</th>
</tr>
</thead>
<tbody>
<tr v-for="item in filteredArticles">
<td>{{ item.published }}</td>
<td>{{ item.category || "无" }}</td>
<td><a :href="item.link" target="_blank">{{ item.title }}</a></td>
<td><a v-if="item.isTranslated" :href="item.trLink" target="_blank">by @{{
item.translator
}}</a>
<span v-else>N/A</span></td>
</tr>
</tbody>
</template>
</v-simple-table>
</v-card>
</div>
</v-container>
</v-card>
</v-container>
</v-main>
<v-footer>
<v-col
class="text-center"
cols="12"
>
<p style="text-align: center;">
Powered by <a href="https://github.com/SPXFellow/">SPX Fellow</a> with 🧡 <br>
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-mark-github">
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path>
</svg>
<a href="https://github.com/SPXFellow/spxfellow.github.io">Github - SPX Browser</a> //
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-mark-github">
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path>
</svg>
<a href="https://github.com/SPXFellow/minecraft.net-translations">Github - 博文目录</a>
</p>
</v-col>
</v-footer>
<v-snackbar v-model="snackbar">
{{ snackbarText }}
<template v-slot:action="{ attrs }">
<v-btn text v-bind="attrs" @click="snackbar= false">
关闭
</v-btn>
</template>
</v-snackbar>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.js"></script>
<script type="text/javascript">
"use strict"
const ServerUrl = '//%replace_as_server_url%'
const MiscArtCategory = '其他'
/**
* @param method {'GET' | 'POST'}
* @param url {string}
* @returns {Promise<string>}
*/
async function sendXhr(method, url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest()
xhr.open(method, url, true)
xhr.onreadystatechange = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
resolve(xhr.responseText)
} else {
reject(xhr.status + xhr.responseText ? ` ${xhr.responseText}` : '')
}
}
}
xhr.send()
})
}
Vue.config.devtools = true
new Vue({
el: '#root',
vuetify: new Vuetify(),
created() {
if (localStorage.getItem("spxInitialized") !== "true") {
localStorage.setItem("spxDarkMode", window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? "true" : "false");
}
this.$vuetify.theme.dark = localStorage.getItem("spxDarkMode") === "true"
this.input.mode = localStorage.getItem("spxDarkMode") === "true" ? "dark" : "light"
localStorage.setItem("spxInitialized", "true");
},
mounted() {
this.getArticles()
},
computed: {
status() {
return {
translated: this.statusInput.includes(0),
untranslated: this.statusInput.includes(1)
}
},
filteredArticles() {
let categories = this.checkboxes.map(v => this.categories[v])
let artCategories = this.artCheckboxes.map(v => this.artCategories[v])
let result = this.articles.map(v => {
// published, title, link, cat, tr_link, tr_name
const [published, title, link, cat, trLink, translator] = v
const isTranslated = trLink !== '-'
const [category, artCategory] = cat.split(':')
let translatedMatch = isTranslated ? this.status.translated : this.status.untranslated
if (!(categories.includes(category) && artCategories.includes(artCategory || MiscArtCategory) && translatedMatch)) {
return null
}
return {
published,
category: cat.toUpperCase(),
link,
title,
trLink,
translator,
isTranslated
}
}).filter(v => v != null)
console.log(result)
return result
}
},
methods: {
clear() {
this.showRead = false
},
async getArticles() {
try {
const table = await sendXhr('GET', 'https://raw.githubusercontent.com/SPXFellow/minecraft.net-translations/master/articles.csv')
let articles = [], categories = [], artCategories = []
const rows = table.split(/\r?\n/).slice(1, -1)
for (const row of rows) {
// published, title, link, cat, tr_link, tr_name
// https://stackoverflow.com/questions/21105360/regex-find-comma-not-inside-quotes/21106122
const cols = row.split(/(?!\B"[^"]*),(?![^"]*"\B)/)
const [category, artCategory] = cols[3].split(':')
if (!categories.includes(category)) {
categories.push(category)
}
if (!artCategories.includes(artCategory || MiscArtCategory)) {
artCategories.push(artCategory || MiscArtCategory)
}
articles.push(cols)
}
this.articles = articles
this.categories = categories
this.artCategories = artCategories
this.checkboxes = [...new Array(categories.length).keys()]
this.artCheckboxes = [...new Array(artCategories.length).keys()]
this.loading.filters = false
console.log('[SPX] Article table loaded.')
} catch (status) {
this.snackbarText = `博文录加载失败,错误代码:${status}`
this.snackbar = true
console.error('[SPX] Article table failed loading.')
}
},
},
data() {
return {
articles: [],
categories: [],
artCategories: [],
loading: {
filters: true,
xhrrequest: false,
color: true,
colorFailed: false,
},
checkboxes: [],
artCheckboxes: [],
statusInput: [0, 1, 2, 3],
colorsPreview: [],
showRead: false,
snackbar: false,
snackbarText: '',
}
}
})
</script>
</body>
</html>