-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathembed.html
More file actions
312 lines (270 loc) · 11.4 KB
/
Copy pathembed.html
File metadata and controls
312 lines (270 loc) · 11.4 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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Embed</title>
<style>
:root {
--bg: #121212;
--primary: #bb86fc;
--text-secondary: #a0a0a0;
--border-color: #333;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
height: 100%;
overflow: hidden;
background: var(--bg);
}
#iframe-container {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: opacity 0.5s ease-in-out;
z-index: 1;
}
#embed-frame {
width: 100%;
height: 100%;
border: none;
background: transparent;
}
.message-container {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
color: #e0e0e0;
text-align: center;
position: relative;
z-index: 10;
}
.message-content {
max-width: 80%;
}
.message-content h1 {
font-size: 2rem;
color: var(--primary);
margin-bottom: 1rem;
}
.message-content p {
color: #a0a0a0;
font-family: monospace;
word-break: break-all;
}
.spinner {
border: 4px solid rgba(255, 255, 255, 0.1);
border-left-color: var(--primary);
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 1s linear infinite;
margin: 0 auto 1.5rem;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
#skip-btn {
margin-top: 1.5rem;
padding: 0.5rem 1rem;
background: transparent;
color: var(--text-secondary);
border: 1px solid var(--border-color);
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
display: none;
}
#skip-btn:hover {
border-color: var(--primary);
color: var(--primary);
}
</style>
<script src="https://cdn.jsdelivr.net/gh/Destroyed12121/Staticsj@main/JS/scramjet.all.js"></script>
<script type="module">
import * as BareMux from "https://cdn.jsdelivr.net/npm/@mercuryworkshop/bare-mux/dist/index.mjs";
window.BareMux = BareMux;
</script>
</head>
<body>
<div id="loading" class="message-container">
<div class="message-content">
<div class="spinner"></div>
<h1 id="loading-title">Connecting</h1>
<p id="loading-url">Initializing proxy</p>
<button id="skip-btn">Skip</button>
</div>
</div>
<div id="error" class="message-container" style="display: none;">
<div class="message-content">
<h1>Connection Error</h1>
<p id="error-message">An error occurred.</p>
</div>
</div>
<div id="iframe-container" style="opacity: 0;"></div>
<script>
console.log("embed.html script starting...");
const loadingContainer = document.getElementById('loading');
const loadingTitle = document.getElementById('loading-title');
const loadingUrl = document.getElementById('loading-url');
const errorContainer = document.getElementById('error');
const errorMessage = document.getElementById('error-message');
const iframeContainer = document.getElementById('iframe-container');
const skipBtn = document.getElementById('skip-btn');
let loadingTimeout = null;
let skipButtonTimeout = null;
function showError(message) {
if (loadingTimeout) clearTimeout(loadingTimeout);
if (skipButtonTimeout) clearTimeout(skipButtonTimeout);
loadingContainer.style.display = 'none';
iframeContainer.innerHTML = '';
errorMessage.textContent = message;
errorContainer.style.display = 'flex';
}
function showContent() {
if (loadingTimeout) clearTimeout(loadingTimeout);
if (skipButtonTimeout) clearTimeout(skipButtonTimeout);
loadingContainer.style.display = 'none';
iframeContainer.style.opacity = '1';
console.log("Content shown successfully");
}
async function init() {
console.log("embed.html init() function called");
const urlParams = new URLSearchParams(window.location.search);
const shouldSkip = urlParams.has('skip');
const targetUrl = window.location.hash.substring(1);
const basePath = location.pathname.replace(/[^/]*$/, '');
console.log(`Target URL: ${targetUrl}`);
console.log(`Should skip: ${shouldSkip}`);
if (!targetUrl) {
console.log("No target URL provided");
showError("No URL was provided. Please specify a URL in the format #<your_url>.");
return;
}
// Validate and decode URL if double-encoded
let validatedUrl = targetUrl;
try {
// Try to decode - if it's double-encoded, this will succeed
const decoded = decodeURIComponent(targetUrl);
if (decoded !== targetUrl && (decoded.startsWith('http://') || decoded.startsWith('https://'))) {
validatedUrl = decoded;
console.log("Detected double-encoded URL, using decoded version:", validatedUrl);
}
} catch (e) {
console.log("URL validation failed:", e.message);
showError(`Invalid URL format. Please ensure the URL is properly encoded. Error: ${e.message}`);
return;
}
// Additional validation for encoded URLs
try {
new URL(validatedUrl);
} catch (e) {
console.log("URL construction failed:", e.message);
showError(`Invalid URL format. Please check the URL: ${e.message}`);
return;
}
// Final URL validation
if (!validatedUrl.startsWith('http://') && !validatedUrl.startsWith('https://')) {
showError("Invalid URL format. Only HTTP and HTTPS URLs are supported.");
return;
}
if (shouldSkip) {
loadingContainer.style.display = 'none';
iframeContainer.style.opacity = '1';
}
try {
console.log("Initializing ScramjetController...");
const { ScramjetController } = $scramjetLoadController();
const scramjet = new ScramjetController({
files: {
wasm: 'https://cdn.jsdelivr.net/gh/Destroyed12121/Staticsj@main/JS/scramjet.wasm.wasm',
all: 'https://cdn.jsdelivr.net/gh/Destroyed12121/Staticsj@main/JS/scramjet.all.js',
sync: 'https://cdn.jsdelivr.net/gh/Destroyed12121/Staticsj@main/JS/scramjet.sync.js'
}
});
console.log("Calling scramjet.init()...");
await scramjet.init();
console.log("Registering service worker...");
// Dynamic path calculation for subfolder hosting compatibility
await navigator.serviceWorker.register(basePath + 'sw.js', { scope: basePath });
const wispUrl = localStorage.getItem('proxServer') || 'wss://gointospace.app/wisp/';
navigator.serviceWorker.ready.then(reg => reg.active?.postMessage({ type: 'config', wispurl: wispUrl }));
console.log("Setting up BareMux connection...");
const connection = new BareMux.BareMuxConnection('/bareworker.js');
await connection.setTransport('https://cdn.jsdelivr.net/npm/@mercuryworkshop/epoxy-transport/dist/index.mjs', [{ wisp: wispUrl }]);
console.log("BareMux connection established successfully");
if (!shouldSkip) {
loadingTitle.textContent = 'Loading';
loadingUrl.textContent = `Please wait while we connect you to: ${validatedUrl}`;
}
console.log("Creating scramjet frame...");
const frame = scramjet.createFrame();
frame.frame.id = 'embed-frame';
frame.frame.referrerPolicy = 'strict-origin-when-cross-origin';
console.log("Scramjet frame created successfully");
if (!shouldSkip) {
console.log("Setting up loading timeouts and event listeners...");
// Show skip button after 5 seconds
skipButtonTimeout = setTimeout(() => {
skipBtn.style.display = 'inline-block';
}, 5000);
skipBtn.addEventListener('click', () => {
console.log("Skip button clicked");
showContent();
});
// Track when frame starts loading
const loadStartTime = Date.now();
const MIN_LOADING_TIME = 2500; // Minimum 2.5 seconds of loading screen
// Use load event listener for iframe readiness
frame.frame.addEventListener('load', () => {
console.log("Frame load event fired");
const elapsed = Date.now() - loadStartTime;
const remainingTime = Math.max(0, MIN_LOADING_TIME - elapsed);
// Show content after minimum loading time
setTimeout(() => {
showContent();
}, remainingTime);
});
frame.frame.addEventListener('error', (event) => {
console.log("Frame error occurred", event);
showError(`An error occurred while trying to load: ${validatedUrl}. Please check the URL and try again.`);
});
// Add timeout with better error handling (60 seconds)
loadingTimeout = setTimeout(() => {
console.log("Loading timeout reached");
if (!frame.frame.contentWindow || frame.frame.contentWindow.location.href === 'about:blank') {
showError(`Timeout: The content took too long to load. You can try skipping next time.`);
}
}, 60000);
}
console.log("Appending frame to container and navigating to target URL...");
iframeContainer.appendChild(frame.frame);
console.log("Frame appended to container");
try {
frame.go(validatedUrl);
console.log("Frame navigation initiated successfully");
} catch (navError) {
console.error("Navigation error:", navError);
showError(`Failed to navigate to URL: ${navError.message}`);
return;
}
} catch (err) {
console.error("Initialization Error:", err);
showError(`A critical error occurred during initialization: ${err.message}.`);
}
}
window.addEventListener('load', init);
</script>
</body>
</html>