forked from DiamondYuan/302
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
268 lines (231 loc) · 8.1 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>URL 302 Redirect</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style type="text/css">
@media (prefers-color-scheme: light) {
:root {
/* 主色 */
--b3-theme-primary: #3575f0;
--b3-theme-primary-light: rgba(53, 117, 240, 0.54);
--b3-theme-primary-lighter: rgba(53, 117, 240, 0.38);
--b3-theme-primary-lightest: rgba(53, 117, 240, 0.12);
--b3-theme-secondary: #f3a92f;
--b3-theme-background: #fff;
--b3-theme-background-light: #dfe0e1;
--b3-theme-surface: #f7f8fa;
--b3-theme-surface-light: rgba(243, 243, 243, .86);
--b3-theme-surface-lighter: rgba(0, 0, 0, .06);
--b3-theme-error: #d23f31;
/* 文字颜色 */
--b3-theme-on-primary: #fff;
--b3-theme-on-secondary: #fff;
--b3-theme-on-background: #202124;
--b3-theme-on-surface: #5f6368;
--b3-theme-on-surface-light: rgba(95, 99, 104, .68);
--b3-theme-on-error: #fff;
}
}
@media (prefers-color-scheme: dark) {
:root {
/* 主色 */
--b3-theme-primary: #3573f0;
--b3-theme-primary-light: rgba(53, 115, 240, 0.72);
--b3-theme-primary-lighter: rgba(53, 115, 240, 0.48);
--b3-theme-primary-lightest: rgba(53, 115, 240, 0.24);
--b3-theme-secondary: #f3a92f;
--b3-theme-background: #1e1f22;
--b3-theme-background-light: #353637;
--b3-theme-surface: #2b2d30;
--b3-theme-surface-light: rgba(41, 42, 45, .86);
--b3-theme-surface-lighter: rgba(230, 230, 230, .06);
--b3-theme-error: #d23f31;
/* 文字颜色 */
--b3-theme-on-primary: #fff;
--b3-theme-on-secondary: #fff;
--b3-theme-on-background: #c9d1d9;
--b3-theme-on-surface: #9aa0a6;
--b3-theme-on-surface-light: rgba(154, 160, 166, .68);
--b3-theme-on-error: #fff;
}
}
</style>
</head>
<style type="text/css">
html,
body {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
}
html {
color: var(--b3-theme-on-background);
background-color: var(--b3-theme-background);
user-select: none;
}
body {
display: flex;
align-items: center;
justify-content: space-around;
background-color: transparent;
}
hr {
border-color: var(--b3-theme-on-surface-light);
}
button {
cursor: pointer;
color: var(--b3-theme-primary);
background-color: transparent;
border: none;
box-shadow: inset 0 0 0 1px var(--b3-theme-primary-light);
box-sizing: border-box;
}
button:hover {
background-color: var(--b3-theme-primary-lightest);
box-shadow: inset 0 0 0 1px var(--b3-theme-primary);
}
button:active {
background-color: var(--b3-theme-primary-lighter);
}
#container {
width: 100%;
}
#edit {
display: flex;
}
#edit>.edit-element {
align-self: center;
margin: 0 0.5em;
display: inline-flex;
align-items: center;
justify-content: center;
text-align: center;
white-space: nowrap;
}
#url {
flex: 1;
background-color: transparent;
color: var(--b3-theme-on-surface);
border: 1px solid var(--b3-theme-on-surface);
border-radius: 4px;
padding: 0.5em;
height: 1.25em;
}
#copy {
padding: 0.5em 1em;
border-radius: 4px;
}
#show {
margin: 0 1em;
min-height: 3em;
}
</style>
<body style="display: none;">
<div id="container">
<div id="edit">
<label class="edit-element"><input id="port" type="checkbox" />6806</label>
<input id="url" placeholder="需重定向的 URL / The URL that needs to be redirected"></input>
<button id="copy" class="edit-element">复制 / Copy</button>
</div>
<hr />
<div id="show"></div>
</div>
</body>
<script type="module">
(() => {
const url = new URL(window.location.href);
const SEARCH_PARAM_KEY = 'location';
/* 是否跳转 */
for (const key of [SEARCH_PARAM_KEY, 'goto']) {
const target = url.searchParams.get(key);
if (target) {
setTimeout(open(window.location, '_self').close, 1000); // 1s 后自动关闭页签/窗口
window.location.href = target;
return;
}
}
document.body.style.display = ""; // 显示内容
/* 样式相关 */
const widget = window.top === window.self; // 是否为挂件
const light = window.matchMedia('(prefers-color-scheme: light)').matches; // 是否为明亮主题
const themeDefaultStyle = window.top.document.getElementById('themeDefaultStyle'); // 思源默认主题节点
const themeStyle = window.top.document.getElementById('themeStyle'); // 思源自定义主题节点
/* 加载默认主题配色 */
if (themeDefaultStyle) {
document.head.appendChild(themeDefaultStyle.cloneNode(true));
}
else {
const style = document.createElement('link');
style.id = 'themeDefaultStyle';
style.rel = 'stylesheet';
style.type = 'text/css';
style.href = light
? '/appearance/themes/daylight/theme.css'
: '/appearance/themes/daylight/theme.css';
document.head.appendChild(style);
}
/* 加载自定义主题配色 */
if (themeStyle) {
document.head.appendChild(themeStyle.cloneNode(true));
}
const port = document.getElementById('port');
const input = document.getElementById('url');
const copy = document.getElementById('copy');
const show = document.getElementById('show');
/* 回显 URL */
function updatePreview() {
show.innerText = `${url.origin}${url.pathname}\n${url.search}`;
}
updatePreview();
/* 监听端口复选框更改 */
port.addEventListener('change', e => {
if (e.target.checked) {
url.port = 6806;
}
else {
url.port = location.port;
}
updatePreview();
e.preventDefault();
e.stopPropagation();
});
/* 监听输入框的输入 */
input.addEventListener('input', e => {
const target = e.target.value;
if (target) {
url.searchParams.set(SEARCH_PARAM_KEY, target);
}
else {
url.searchParams.delete(SEARCH_PARAM_KEY);
}
updatePreview();
e.preventDefault();
e.stopPropagation();
}, true);
/* 监听复制事件 */
document.addEventListener('copy', e => {
e.clipboardData.setData('text/plain', url.toString());
e.clipboardData.setData('text/html', `<a href="${url.toString()}">${url.searchParams.get(SEARCH_PARAM_KEY) ?? 'URL Scheme'}</a>`);
e.preventDefault();
e.stopPropagation();
}, true);
/* 监听复制按钮 */
copy.addEventListener('click', e => {
document.execCommand('copy');
e.preventDefault();
e.stopPropagation();
}, true);
/* 监听输入框中回车事件 */
input.addEventListener('keydown', e => {
if (e.key === 'Enter') {
document.execCommand('copy');
e.preventDefault();
e.stopPropagation();
}
}, true);
})();
</script>
</html>