-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
151 lines (139 loc) · 4.07 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GitHub镜像代理</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
line-height: 1.6;
color: #24292e;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.container {
background-color: #f6f8fa;
border-radius: 6px;
padding: 24px;
box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
h1 {
font-size: 24px;
border-bottom: 1px solid #eaecef;
padding-bottom: 10px;
margin-top: 0;
}
.search-form {
margin: 20px 0;
}
.search-input {
width: 70%;
padding: 8px 12px;
font-size: 14px;
border: 1px solid #e1e4e8;
border-radius: 6px;
}
.search-button {
background-color: #2ea44f;
color: white;
border: none;
padding: 8px 16px;
font-size: 14px;
border-radius: 6px;
margin-left: 10px;
cursor: pointer;
}
.search-button:hover {
background-color: #2c974b;
}
.example {
background: #fff;
border: 1px solid #e1e4e8;
border-radius: 6px;
padding: 16px;
margin: 20px 0;
}
.example h3 {
margin-top: 0;
font-size: 16px;
}
footer {
margin-top: 30px;
text-align: center;
font-size: 12px;
color: #6a737d;
}
</style>
</head>
<body>
<div class="container">
<h1>GitHub镜像代理</h1>
<div class="search-form">
<input
type="text"
id="github-url"
class="search-input"
placeholder="输入GitHub URL (例如: https://github.com/microsoft/vscode)"
/>
<button class="search-button" onclick="convertUrl()">转换并访问</button>
</div>
<div class="example">
<h3>使用示例:</h3>
<p>1. 访问GitHub仓库页面:</p>
<ul>
<li>原始: <code>https://github.com/用户名/仓库名</code></li>
<li>代理: <code>https://[本站域名]/用户名/仓库名</code></li>
</ul>
<p>2. 访问GitHub API:</p>
<ul>
<li>原始: <code>https://github.com/api/repos/用户名/仓库名</code></li>
<li>代理: <code>https://[本站域名]/api/repos/用户名/仓库名</code></li>
</ul>
<p>3. 访问Raw内容:</p>
<ul>
<li>原始: <code>https://github.com/raw/用户名/仓库名/分支/文件路径</code></li>
<li>代理: <code>https://[本站域名]/raw/用户名/仓库名/分支/文件路径</code></li>
</ul>
</div>
</div>
<footer>
<p>此工具仅供学习和研究使用,请遵守相关法律法规</p>
</footer>
<script>
// 获取当前网站的域名
const currentOrigin = window.location.origin;
function convertUrl() {
const inputUrl = document.getElementById('github-url').value.trim();
if (!inputUrl) {
alert('请输入GitHub URL');
return;
}
try {
const url = new URL(inputUrl);
let convertedUrl = '';
if (url.hostname === 'github.com') {
convertedUrl = `${currentOrigin}${url.pathname}${url.search}${url.hash}`;
} else if (url.hostname === 'api.github.com') {
convertedUrl = `${currentOrigin}/api${url.pathname}${url.search}${url.hash}`;
} else if (url.hostname === 'raw.githubusercontent.com') {
convertedUrl = `${currentOrigin}/raw${url.pathname}${url.search}${url.hash}`;
} else {
alert('不支持的URL格式,请输入GitHub、GitHub API或Raw URL');
return;
}
window.location.href = convertedUrl;
} catch (e) {
alert('URL格式错误,请输入完整的URL,包括https://');
}
}
// 回车键提交
document.getElementById('github-url').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
convertUrl();
}
});
</script>
</body>
</html>