-
Notifications
You must be signed in to change notification settings - Fork 2
/
mirror.html
170 lines (152 loc) · 6.63 KB
/
mirror.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>GitHub Mirror 文件加速</title>
<link rel="icon" href="dist/icon.svg"/>
<meta name="description" content='github 文件加速'>
<meta name="anthor" content="xiaoxuan6">
<link rel="stylesheet" href="dist/css/tailwind.min.css"/>
<link rel="stylesheet" href="dist/css/notiflix-3.2.6.min.css">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/nprogress.css">
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js"></script>
</head>
<body class="bg-gray-200 h-screen">
<div class="flex flex-col">
<p class="font-bold text-4xl mx-4 my-4">Github-Mirror</p>
<div class="bg-white mx-4 mb-4 p-4 rounded-lg shadow">
<p class="font-bold">随机复制一个节点,添加到 git 地址前面即可</p>
<div class="flex">
<p class="font-bold">例如:
<div class="bg-red-500 text-white">https://example.com</div>
/https://github.com/xiaoxuan6/github-mirror/blob/main/README.md</p>
</div>
<div class="flex">
<p class="font-bold"> or:
<div class="bg-green-500 text-white" id="serve"></div>
/https://github.com/xiaoxuan6/github-mirror/blob/main/README.md</p>
</div>
</div>
<div class="bg-white mx-4 mb-4 p-4 rounded-lg shadow">
<div class="w-full flex">
<input type="text" class="mb-4 p-2 border w-9/12" id="input" placeholder="请输入有效的 url/ip">
<div class="cf-turnstile ml-3" data-sitekey="0x4AAAAAAAcUAv_3p8uWE8ET" data-callback="javascriptCallback"></div>
</div>
<a id="submit" href="javascript:void(0);"
class="bg-blue-500 hover:bg-blue-700 text-white py-3 px-5 w-full block text-center rounded">提交</a>
</div>
</div>
<div class="bg-white mx-4 mb-4 p-4 rounded-lg shadow">
<table class="table-auto w-full">
<div class="flex">站点总个数:<p class="text-red-500" id="count"></p></div>
<tbody id="tbody">
</tbody>
</table>
</div>
<div class="text-center">
Powered by <a href="https://github.com/xiaoxuan6/github-mirror" class="text-blue-500" target="_blank">xiaoxuan6/github-mirror</a>
</div>
</div>
<script src="dist/js/clipboard.min.js"></script>
<script src="dist/js/notiflix-3.2.6.min.js"></script>
<script src="https://unpkg.com/[email protected]/nprogress.js"></script>
<script>
(function () {
function initializeClipboard() {
let clipboard = new ClipboardJS('.btn');
clipboard.on('success', function (e) {
Notiflix.Notify.success('复制成功!')
console.info('Text:', e.text);
});
clipboard.on('error', function (e) {
console.info('Action:', e.action);
});
}
function initServe() {
let hostname = window.location.hostname;
if (hostname.length === 0) {
hostname = "github-mirror-alpha.vercel.app"
}
document.getElementById('serve').innerHTML = "https://" + hostname
}
window.addEventListener("load", function () {
NProgress.start();
fetch("/api/urls")
.then((res) => {
if (res.ok === false) {
console.error("请求失败,状态码: " + res.status);
}
return res.json()
})
.then((data) => {
NProgress.done();
if (data.code !== 200) {
Notiflix.Notify.failure('数据加载失败!' + data.msg);
return
}
let i = 1
let td = ''
let items = data.data
let tbody = document.getElementById("tbody");
for (let url of items) {
let uri = url.trim()
let id = uri.replaceAll('.', '-').replaceAll('://', '-').replace(':', '-')
td += '<td class="border p-2 text-center break-all" id="' + id + '">\n' +
'<a href="' + uri + '" target="_blank">' + uri + '</a>' +
' <button class="btn" data-clipboard-target="#' + id + '" data-clipboard-action="copy">\n' +
' <img src="./dist/clippy.svg" width="16"/>\n' +
' </button>' +
'</td>'
if (i % 5 === 0 || items.length === i) {
let tr = document.createElement('tr')
tr.innerHTML = td
tbody.appendChild(tr)
td = ''
}
i++
}
document.getElementById('count').innerHTML = items.length
})
.catch((error) => {
NProgress.done();
Notiflix.Notify.failure('请求失败:' + error);
});
initializeClipboard()
initServe()
document.getElementById("submit").addEventListener("click", function () {
let val = document.getElementById('input').value
let response = document.querySelector("input[name='cf-turnstile-response']").value
if (val.length < 1) {
Notiflix.Notify.failure('请输入有效的 url/ip');
return
}
if (response.length < 1) {
Notiflix.Notify.failure('请确认您是真人');
return;
}
NProgress.start();
fetch("/api/url/save", {
method: "post",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({url: val, response: response})
})
.then((re) => re.json())
.then((data) => {
NProgress.done();
if (data.code !== 200) {
Notiflix.Notify.failure('提交失败!' + data.msg);
return
}
Notiflix.Notify.success('提交成功!')
setTimeout(function () {
window.location.reload()
}, 3000)
})
})
});
})();
</script>
</body>
</html>