-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path404.html
More file actions
129 lines (128 loc) · 5.44 KB
/
Copy path404.html
File metadata and controls
129 lines (128 loc) · 5.44 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404</title>
<link rel="stylesheet" href="https://cdn.jsdmirror.com/npm/mdui/mdui.css">
<script src="https://cdn.jsdmirror.com/npm/mdui/mdui.global.js"></script>
<link rel="preconnect" href="https://cdn.jsdmirror.com" crossorigin>
<link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<script defer src="https://cloud.umami.is/script.js" data-website-id="8a96c320-b541-482f-acd4-6fc1b3ec22dc"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Google+Sans&display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC&display=swap">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
body{
font-family: 'Google Sans','Noto Sans SC';
color: #201b12;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
box-sizing: border-box;
padding: 0;
margin: 0;
}
h1, p{
margin: 5px;
}
</style>
</head>
<body>
<h1 style="font-size: 75px;">404</h1>
<p>找不到页面</p>
<mdui-divider style="width: 50vw; margin: 25px 0;"></mdui-divider>
<p style="display: flex;align-items: center;justify-content: center;gap: 10px;">
<span id="hint1">可能是因为我删除或更名了相应的工具</span>
<mdui-button icon="home" href="/">返回首页找找</mdui-button>
</p>
<p>
也可能是我对它进行了重命名:
<span id="hint2" style="display: inline-flex;align-items: center;justify-content: center;gap: 10px;">正在尝试自动跳转<mdui-circular-progress></mdui-circular-progress></span>
</p>
<script>
(function(){
console.log('[404] 脚本开始执行, 当前路径:', window.location.pathname);
var hintEl = document.getElementById('hint2');
function stripPrefix(path){
var prefixes = ['/proj/', '/vibe/', '/builts/'];
for(var i=0;i<prefixes.length;i++){
if(path.indexOf(prefixes[i])===0){
return path.substring(prefixes[i].length);
};
};
return path;
};
function getCore(path){
path = stripPrefix(path);
path = path.replace(/^\/+/, '');
path = path.replace(/\/index\.html$/, '');
path = path.replace(/\.html$/, '');
path = path.replace(/\/+$/, '');
return path;
};
function buildRedirectUrl(sitemapUrl){
try{
var urlObj = new URL(sitemapUrl);
urlObj.protocol = window.location.protocol;
urlObj.hostname = window.location.hostname;
urlObj.port = window.location.port || '';
var finalPath = urlObj.pathname;
if(!finalPath.match(/\.html$/) && !finalPath.endsWith('/')){
finalPath += '/';
};
urlObj.pathname = finalPath;
return urlObj.toString();
}catch(e){
return null;
};
};
function setHint(text){
if(hintEl){
hintEl.innerHTML = text;
};
};
fetch(window.location.origin + '/sitemap.xml').then(function(res){
if(!res.ok) throw new Error('HTTP ' + res.status);
return res.text();
}).then(function(xmlText){
var parser = new DOMParser();
var doc = parser.parseFromString(xmlText, 'text/xml');
var locs = doc.getElementsByTagNameNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'loc');
if(!locs || locs.length === 0){
locs = doc.getElementsByTagName('loc');
};
if(!locs || locs.length === 0){
locs = doc.querySelectorAll('loc');
};
var currentCore = getCore(window.location.pathname);
var matched = false;
for(var i=0;i<locs.length;i++){
var sitemapUrl = (locs[i].textContent || '').trim();
if(!sitemapUrl) continue;
try{
var sitemapPath = new URL(sitemapUrl).pathname;
var sitemapCore = getCore(sitemapPath);
if(currentCore === sitemapCore){
var target = buildRedirectUrl(sitemapUrl);
if(target){
window.location.href = target;
matched = true;
return;
};
};
}catch(e){};
};
if(!matched){
setHint('自动跳转失败');
};
}).catch(function(err){
setHint('自动跳转失败');
});
})();
</script>
</body>
</html>