Skip to content

Commit 7301fbe

Browse files
authored
Refactor comments and strengthen routing logic
Updated comments for clarity and improved routing logic.
1 parent 82bc1ac commit 7301fbe

1 file changed

Lines changed: 12 additions & 20 deletions

File tree

index.html

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -315,21 +315,21 @@ <h2 id="side-panel-title" class="font-black text-[10px] tracking-widest uppercas
315315
if (internalPages.includes(input)) {
316316
proxyUrl = input;
317317
} else {
318-
// Determine if it's a URL or search query
318+
// Strict URL detection: starts with protocol OR has a dot and no spaces
319319
const isUrl = /^https?:\/\//.test(input) || (!input.includes(' ') && input.includes('.'));
320320

321321
let targetUrl = '';
322322
if (isUrl) {
323-
// Normalize to https://domain
323+
// Extract domain and force https://
324324
let domain = input.replace(/^https?:\/\//, '');
325325
targetUrl = 'https://' + domain;
326326
} else {
327-
// Search query - route to Google via custom active/embed method
327+
// It's a query: route to Google search via the custom embed method
328328
targetUrl = 'https://www.google.com/search?q=' + encodeURIComponent(input);
329329
}
330330

331-
// EXCLUSIVE CUSTOM METHOD: /active/embed.html?url=https://...
332-
proxyUrl = 'active/embed.html?url=' + targetUrl;
331+
// STRENGTHENED ROUTING: Use absolute root path for /active/embed.html
332+
proxyUrl = '/active/embed.html?url=' + targetUrl;
333333
}
334334

335335
updateTab(activeTabId, {
@@ -363,12 +363,11 @@ <h2 id="side-panel-title" class="font-black text-[10px] tracking-widest uppercas
363363
tabStrip.insertBefore(tabEl, addBtn);
364364
});
365365

366-
// Clean up viewports
366+
// Sync Viewports
367367
viewportContainer.querySelectorAll('.viewport').forEach(vp => {
368368
if (!tabs.find(t => t.id === vp.dataset.id)) vp.remove();
369369
});
370370

371-
// Sync Viewports
372371
tabs.forEach(tab => {
373372
let vp = viewportContainer.querySelector(`.viewport[data-id="${tab.id}"]`);
374373
if (!vp) {
@@ -387,13 +386,14 @@ <h2 id="side-panel-title" class="font-black text-[10px] tracking-widest uppercas
387386
zoomCont.style.height = (100 / tab.zoom) + '%';
388387

389388
const iframe = vp.querySelector('iframe');
389+
// Use getAttribute to avoid security issues with cross-origin contentWindow
390390
if (isActive && iframe.getAttribute('src') !== tab.proxyUrl) {
391391
iframe.src = tab.proxyUrl;
392392
}
393393
});
394394
}
395395

396-
// Event Listeners
396+
// Standard Event Listeners
397397
addressBar.onkeydown = (e) => { if (e.key === 'Enter') navigate(addressBar.value); };
398398
menuBtn.onclick = (e) => { e.stopPropagation(); menuDropdown.classList.toggle('hidden'); };
399399
document.onclick = () => menuDropdown.classList.add('hidden');
@@ -402,34 +402,26 @@ <h2 id="side-panel-title" class="font-black text-[10px] tracking-widest uppercas
402402
document.getElementById('zoom-out-btn').onclick = () => updateTab(activeTabId, { zoom: Math.max(0.25, (tabs.find(t => t.id === activeTabId)?.zoom || 1) - 0.1) });
403403
document.getElementById('music-trigger').onclick = (e) => { e.stopPropagation(); toggleSidePanel('Audio', 'music.html'); };
404404
document.getElementById('settings-trigger').onclick = (e) => { e.stopPropagation(); toggleSidePanel('Settings', 'settings.html'); };
405+
405406
document.getElementById('refresh-btn').onclick = () => {
406407
const vp = viewportContainer.querySelector(`.viewport[data-id="${activeTabId}"]`);
407408
if (vp) {
408409
const iframe = vp.querySelector('iframe');
409410
iframe.src = iframe.src;
410411
}
411412
};
412-
document.getElementById('back-btn').onclick = () => {
413-
const vp = viewportContainer.querySelector(`.viewport[data-id="${activeTabId}"]`);
414-
if (vp) try { vp.querySelector('iframe').contentWindow.history.back(); } catch(e) {}
415-
};
416-
document.getElementById('forward-btn').onclick = () => {
417-
const vp = viewportContainer.querySelector(`.viewport[data-id="${activeTabId}"]`);
418-
if (vp) try { vp.querySelector('iframe').contentWindow.history.forward(); } catch(e) {}
419-
};
420-
421-
closeSidePanel.onclick = () => sidePanel.classList.remove('open');
422413

414+
// Navigation messages from child frames
423415
window.addEventListener('message', (e) => {
424416
if (e.data.type === 'navigate') navigate(e.data.query);
425-
if (e.data.type === 'metadata') updateTab(activeTabId, { title: e.data.title, favicon: e.data.favicon });
417+
if (e.data.type === 'metadata') updateTab(activeTabId, { title: e.data.title });
426418
if (e.data.type === 'request-current-tab') {
427419
const tab = tabs.find(t => t.id === activeTabId);
428420
e.source.postMessage({ type: 'response-current-tab', url: tab.url, title: tab.title, favicon: tab.favicon }, '*');
429421
}
430422
});
431423

432-
// App Start
424+
// Initialize App
433425
if (!loadSession()) createTab();
434426
setInterval(() => {
435427
const now = new Date();

0 commit comments

Comments
 (0)