-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqr.html
More file actions
165 lines (149 loc) · 5.59 KB
/
qr.html
File metadata and controls
165 lines (149 loc) · 5.59 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Redirecting...</title>
<style>
body {
font-family: 'Raleway', sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.container {
text-align: center;
padding: 2rem;
}
h1 {
font-size: 2.5rem;
margin-bottom: 1rem;
font-weight: 300;
}
.message {
font-size: 1.2rem;
margin-bottom: 2rem;
opacity: 0.9;
}
.spinner {
width: 50px;
height: 50px;
margin: 2rem auto;
border: 3px solid rgba(255, 255, 255, 0.3);
border-top-color: white;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.error {
background: linear-gradient(135deg, #f5365c 0%, #f56565 100%);
}
.manual-link {
color: white;
text-decoration: underline;
font-size: 1.1rem;
margin-top: 1rem;
display: inline-block;
}
.debug {
margin-top: 2rem;
padding: 1rem;
background: rgba(0,0,0,0.2);
border-radius: 8px;
font-family: monospace;
font-size: 0.9rem;
display: none;
}
.debug.show {
display: block;
}
</style>
</head>
<body>
<div class="container">
<h1>Redirecting...</h1>
<div class="message">Taking you to your destination</div>
<div class="spinner"></div>
<div id="manual-redirect" style="display: none;">
<a href="#" class="manual-link" id="manual-link">Click here if you're not redirected</a>
</div>
<div class="debug" id="debug"></div>
</div>
<script>
async function redirect() {
const debugEl = document.getElementById('debug');
const showDebug = window.location.search.includes('debug=true');
if (showDebug) {
debugEl.classList.add('show');
}
function log(message) {
console.log(message);
if (showDebug) {
debugEl.innerHTML += message + '<br>';
}
}
try {
// Get URL parameters
const urlParams = new URLSearchParams(window.location.search);
const target = urlParams.get('to');
log('Loading configuration...');
// Fetch configuration
const response = await fetch('/qr-config.json');
if (!response.ok) {
throw new Error('Failed to load configuration');
}
const config = await response.json();
log('Configuration loaded successfully');
let redirectUrl;
let delay = 0;
// Determine redirect URL
if (target && config.redirects[target]) {
redirectUrl = config.redirects[target];
log(`Using named redirect: ${target} -> ${redirectUrl}`);
} else if (config.default) {
redirectUrl = config.default.url;
delay = config.default.delay || 0;
log(`Using default redirect: ${redirectUrl}`);
} else {
throw new Error('No redirect URL configured');
}
// Update UI
document.querySelector('.message').textContent = `Redirecting to ${new URL(redirectUrl).hostname || 'destination'}...`;
// Show manual redirect link
setTimeout(() => {
document.getElementById('manual-redirect').style.display = 'block';
document.getElementById('manual-link').href = redirectUrl;
}, 1000);
// Perform redirect
setTimeout(() => {
log(`Redirecting to: ${redirectUrl}`);
window.location.href = redirectUrl;
}, delay);
} catch (error) {
console.error('Redirect error:', error);
document.body.classList.add('error');
document.querySelector('h1').textContent = 'Oops!';
document.querySelector('.message').textContent = 'Something went wrong with the redirect.';
document.querySelector('.spinner').style.display = 'none';
if (showDebug) {
log('ERROR: ' + error.message);
}
// Fallback to homepage
setTimeout(() => {
document.getElementById('manual-redirect').style.display = 'block';
document.getElementById('manual-link').href = '/';
document.getElementById('manual-link').textContent = 'Go to homepage';
}, 500);
}
}
// Start redirect process
redirect();
</script>
</body>
</html>