Repository navigation
Expand file tree
/
Copy pathiframe-test.html
More file actions
383 lines (336 loc) · 16.7 KB
/
Copy pathiframe-test.html
File metadata and controls
383 lines (336 loc) · 16.7 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Selectly iframe Test - JumpServer Simulation</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.header {
background: #2c3e50;
color: white;
padding: 15px;
border-radius: 8px 8px 0 0;
margin-bottom: 0;
}
.tab-container {
background: white;
border: 1px solid #ddd;
border-radius: 0 0 8px 8px;
min-height: 600px;
}
.tabs {
display: flex;
border-bottom: 1px solid #ddd;
background: #f8f9fa;
}
.tab {
padding: 12px 20px;
cursor: pointer;
border-right: 1px solid #ddd;
background: #e9ecef;
transition: background-color 0.2s;
}
.tab.active {
background: white;
border-bottom: 1px solid white;
margin-bottom: -1px;
}
.tab:hover:not(.active) {
background: #dee2e6;
}
.tab-content {
position: relative;
height: 550px;
}
.iframe-wrapper {
width: 100%;
height: 100%;
display: none;
}
.iframe-wrapper.active {
display: block;
}
iframe {
width: 100%;
height: 100%;
border: none;
}
.controls {
margin-bottom: 20px;
padding: 15px;
background: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
button {
background: #007bff;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
margin-right: 10px;
}
button:hover {
background: #0056b3;
}
.status {
margin-top: 10px;
padding: 10px;
background: #e7f3ff;
border: 1px solid #bee5eb;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="container">
<div class="controls">
<h2>Selectly iframe Support Test - JumpServer Simulation</h2>
<p>This simulates a JumpServer-like environment with dynamic iframe tabs. Test text selection in different iframes.</p>
<button onclick="addNewTab()">Connect New Server</button>
<button onclick="removeTab()">Disconnect Current</button>
<button onclick="testCrossOrigin()">Test Cross-Origin iframe</button>
<div class="status" id="status">Ready to test. Click "Connect New Server" to create a new tab with iframe content.</div>
</div>
<div class="header">
<h1>🖥️ JumpServer Management Console</h1>
</div>
<div class="tab-container">
<div class="tabs" id="tabs">
<!-- Tabs will be dynamically added here -->
</div>
<div class="tab-content" id="tab-content">
<!-- iframe content will be added here -->
</div>
</div>
</div>
<script>
let tabCounter = 0;
let activeTab = null;
const sampleContents = [
{
title: 'Web Server Logs',
content: `
<div style="padding: 20px; font-family: monospace; background: #1e1e1e; color: #00ff00; height: 100vh; overflow-y: auto;">
<h3 style="color: #ffffff;">📊 Web Server Access Logs</h3>
<div style="margin: 10px 0;">2024-01-15 10:30:15 [INFO] Server started on port 8080</div>
<div style="margin: 10px 0;">2024-01-15 10:30:23 [INFO] GET /api/users - 200 OK - 45ms</div>
<div style="margin: 10px 0;">2024-01-15 10:30:31 [ERROR] POST /api/login - 401 Unauthorized - Invalid credentials for user: admin@example.com</div>
<div style="margin: 10px 0;">2024-01-15 10:30:45 [WARN] High memory usage detected: 85% of available RAM</div>
<div style="margin: 10px 0;">2024-01-15 10:31:02 [INFO] Database connection pool: 15/20 connections active</div>
<div style="margin: 10px 0;">2024-01-15 10:31:15 [DEBUG] Cache hit rate: 92.5% (1843/1996 requests)</div>
<p style="color: #ffff00; margin: 20px 0;">💡 试着选择这些日志文本来测试 Selectly 的翻译和解释功能。Select any of these log entries to test Selectly's translation and explanation features.</p>
<div style="margin: 10px 0;">2024-01-15 10:31:30 [INFO] SSL certificate expires in 30 days</div>
<div style="margin: 10px 0;">2024-01-15 10:31:45 [ERROR] Failed to connect to external API: timeout after 30s</div>
<div style="margin: 10px 0;">2024-01-15 10:32:00 [INFO] Backup completed successfully: 2.3GB archived</div>
</div>
`
},
{
title: 'Database Console',
content: `
<div style="padding: 20px; background: #f8f9fa; height: 100vh;">
<h3>🗄️ Database Management Console</h3>
<div style="background: white; padding: 15px; border-radius: 5px; margin: 15px 0; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
<h4>Query Results</h4>
<table style="width: 100%; border-collapse: collapse;">
<tr style="background: #007bff; color: white;">
<th style="padding: 10px; border: 1px solid #ddd;">ID</th>
<th style="padding: 10px; border: 1px solid #ddd;">Username</th>
<th style="padding: 10px; border: 1px solid #ddd;">Email</th>
<th style="padding: 10px; border: 1px solid #ddd;">Status</th>
</tr>
<tr>
<td style="padding: 10px; border: 1px solid #ddd;">1001</td>
<td style="padding: 10px; border: 1px solid #ddd;">admin_user</td>
<td style="padding: 10px; border: 1px solid #ddd;">admin@company.com</td>
<td style="padding: 10px; border: 1px solid #ddd;">Active</td>
</tr>
<tr>
<td style="padding: 10px; border: 1px solid #ddd;">1002</td>
<td style="padding: 10px; border: 1px solid #ddd;">developer_john</td>
<td style="padding: 10px; border: 1px solid #ddd;">john.doe@company.com</td>
<td style="padding: 10px; border: 1px solid #ddd;">Active</td>
</tr>
<tr>
<td style="padding: 10px; border: 1px solid #ddd;">1003</td>
<td style="padding: 10px; border: 1px solid #ddd;">test_user</td>
<td style="padding: 10px; border: 1px solid #ddd;">test@company.com</td>
<td style="padding: 10px; border: 1px solid #ddd;">Inactive</td>
</tr>
</table>
</div>
<div style="background: #fff3cd; padding: 15px; border-radius: 5px; border: 1px solid #ffeaa7;">
<strong>📝 测试说明 (Test Instructions):</strong><br>
尝试选择表格中的用户名或邮箱地址,然后使用 Selectly 进行翻译或解释。<br>
Try selecting usernames or email addresses in the table, then use Selectly for translation or explanation.
</div>
</div>
`
},
{
title: 'System Monitor',
content: `
<div style="padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; height: 100vh;">
<h3>📈 System Performance Monitor</h3>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0;">
<div style="background: rgba(255,255,255,0.1); padding: 15px; border-radius: 10px;">
<h4>CPU Usage</h4>
<div style="font-size: 24px; color: #00ff88;">72.5%</div>
<p>Current load average: 2.1, 1.8, 1.5</p>
</div>
<div style="background: rgba(255,255,255,0.1); padding: 15px; border-radius: 10px;">
<h4>Memory Usage</h4>
<div style="font-size: 24px; color: #ff6b6b;">8.2GB / 16GB</div>
<p>Available memory: 7.8GB</p>
</div>
</div>
<div style="background: rgba(255,255,255,0.1); padding: 15px; border-radius: 10px; margin: 20px 0;">
<h4>Recent System Events</h4>
<div style="font-family: monospace; font-size: 14px;">
<div>• Process nginx restarted successfully</div>
<div>• Disk usage warning: /var/log is 89% full</div>
<div>• Network interface eth0: 1000Mbps link detected</div>
<div>• User session started: developer_jane from 192.168.1.100</div>
<div>• Security scan completed: 0 vulnerabilities found</div>
</div>
</div>
<div style="background: rgba(255,215,0,0.2); padding: 15px; border-radius: 10px; border: 1px solid rgba(255,215,0,0.5);">
<strong>🎯 iframe 测试重点 (iframe Test Focus):</strong><br>
在这个动态加载的 iframe 中选择系统监控数据,验证 Selectly 是否能正确工作。<br>
Select system monitoring data in this dynamically loaded iframe to verify Selectly works correctly.
</div>
</div>
`
}
];
function addNewTab() {
tabCounter++;
const tabId = `tab-${tabCounter}`;
const content = sampleContents[(tabCounter - 1) % sampleContents.length];
// Create tab
const tab = document.createElement('div');
tab.className = 'tab';
tab.textContent = `${content.title} #${tabCounter}`;
tab.onclick = () => switchTab(tabId);
document.getElementById('tabs').appendChild(tab);
// Create iframe wrapper
const wrapper = document.createElement('div');
wrapper.className = 'iframe-wrapper';
wrapper.id = tabId;
// Create iframe with dynamic content
const iframe = document.createElement('iframe');
iframe.style.border = 'none';
iframe.style.width = '100%';
iframe.style.height = '100%';
wrapper.appendChild(iframe);
document.getElementById('tab-content').appendChild(wrapper);
// Load content into iframe
iframe.onload = () => {
try {
const doc = iframe.contentDocument || iframe.contentWindow.document;
doc.open();
doc.write(`
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${content.title}</title>
</head>
<body style="margin: 0; padding: 0;">
${content.content}
</body>
</html>
`);
doc.close();
updateStatus(`✅ Created new tab: ${content.title} #${tabCounter} (same-origin iframe)`);
} catch (e) {
updateStatus(`❌ Failed to create iframe content: ${e.message}`);
}
};
// Set a data URL to trigger load
iframe.src = 'about:blank';
// Switch to new tab
setTimeout(() => switchTab(tabId), 100);
}
function removeTab() {
if (!activeTab) {
updateStatus('❌ No active tab to remove');
return;
}
const tab = document.querySelector(`div.tab.active`);
const content = document.getElementById(activeTab);
if (tab) tab.remove();
if (content) content.remove();
updateStatus(`🗑️ Removed tab: ${activeTab}`);
// Switch to first available tab
const remainingTabs = document.querySelectorAll('.tab');
const remainingContent = document.querySelectorAll('.iframe-wrapper');
if (remainingTabs.length > 0 && remainingContent.length > 0) {
switchTab(remainingContent[0].id);
} else {
activeTab = null;
}
}
function switchTab(tabId) {
// Remove active class from all tabs and content
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.iframe-wrapper').forEach(w => w.classList.remove('active'));
// Add active class to selected tab and content
const tabElement = Array.from(document.querySelectorAll('.tab')).find(t =>
t.onclick.toString().includes(tabId)
);
const contentElement = document.getElementById(tabId);
if (tabElement) tabElement.classList.add('active');
if (contentElement) contentElement.classList.add('active');
activeTab = tabId;
updateStatus(`🔄 Switched to tab: ${tabId}`);
}
function testCrossOrigin() {
tabCounter++;
const tabId = `tab-${tabCounter}`;
// Create tab
const tab = document.createElement('div');
tab.className = 'tab';
tab.textContent = `Cross-Origin Test #${tabCounter}`;
tab.onclick = () => switchTab(tabId);
document.getElementById('tabs').appendChild(tab);
// Create iframe wrapper
const wrapper = document.createElement('div');
wrapper.className = 'iframe-wrapper';
wrapper.id = tabId;
// Create cross-origin iframe
const iframe = document.createElement('iframe');
iframe.style.border = 'none';
iframe.style.width = '100%';
iframe.style.height = '100%';
iframe.src = 'https://httpbin.org/html'; // Cross-origin example
wrapper.appendChild(iframe);
document.getElementById('tab-content').appendChild(wrapper);
updateStatus(`🌐 Created cross-origin iframe: httpbin.org (Selectly should still work via content script injection)`);
// Switch to new tab
setTimeout(() => switchTab(tabId), 100);
}
function updateStatus(message) {
const status = document.getElementById('status');
status.textContent = `${new Date().toLocaleTimeString()}: ${message}`;
}
// Initialize with first tab
document.addEventListener('DOMContentLoaded', () => {
addNewTab();
updateStatus('🚀 JumpServer simulation loaded. Ready to test Selectly iframe support!');
});
</script>
</body>
</html>