Skip to content

Commit 82bc1ac

Browse files
authored
Improve URL detection and proxy URL construction
Refactor URL and search query handling in navigation logic.
1 parent 05f8222 commit 82bc1ac

1 file changed

Lines changed: 37 additions & 18 deletions

File tree

index.html

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -315,27 +315,29 @@ <h2 id="side-panel-title" class="font-black text-[10px] tracking-widest uppercas
315315
if (internalPages.includes(input)) {
316316
proxyUrl = input;
317317
} else {
318-
// Strict URL vs Search detection
319-
// Treat as URL if it starts with http or (has a dot AND no spaces)
318+
// Determine if it's a URL or search query
320319
const isUrl = /^https?:\/\//.test(input) || (!input.includes(' ') && input.includes('.'));
321320

322-
let finalTarget = '';
321+
let targetUrl = '';
323322
if (isUrl) {
324-
finalTarget = input;
325-
// Ensure it starts with https:// as requested
326-
if (!/^https?:\/\//.test(finalTarget)) {
327-
finalTarget = 'https://' + finalTarget;
328-
}
323+
// Normalize to https://domain
324+
let domain = input.replace(/^https?:\/\//, '');
325+
targetUrl = 'https://' + domain;
329326
} else {
330-
// Treat as query - route to Google via custom active/embed method
331-
finalTarget = 'https://www.google.com/search?q=' + encodeURIComponent(input);
327+
// Search query - route to Google via custom active/embed method
328+
targetUrl = 'https://www.google.com/search?q=' + encodeURIComponent(input);
332329
}
333330

334-
// Construct strictly using YOUR custom method /active/embed.html?url=
335-
proxyUrl = 'active/embed.html?url=' + encodeURIComponent(finalTarget);
331+
// EXCLUSIVE CUSTOM METHOD: /active/embed.html?url=https://...
332+
proxyUrl = 'active/embed.html?url=' + targetUrl;
336333
}
337334

338-
updateTab(activeTabId, { url: input, proxyUrl, title: input, favicon: getFavicon(input) });
335+
updateTab(activeTabId, {
336+
url: input,
337+
proxyUrl: proxyUrl,
338+
title: input,
339+
favicon: getFavicon(proxyUrl.includes('google.com/search') ? 'https://google.com' : input)
340+
});
339341
menuDropdown.classList.add('hidden');
340342
}
341343

@@ -361,12 +363,12 @@ <h2 id="side-panel-title" class="font-black text-[10px] tracking-widest uppercas
361363
tabStrip.insertBefore(tabEl, addBtn);
362364
});
363365

364-
// Clean up removed viewports
366+
// Clean up viewports
365367
viewportContainer.querySelectorAll('.viewport').forEach(vp => {
366368
if (!tabs.find(t => t.id === vp.dataset.id)) vp.remove();
367369
});
368370

369-
// Handle iframe generation and synchronization
371+
// Sync Viewports
370372
tabs.forEach(tab => {
371373
let vp = viewportContainer.querySelector(`.viewport[data-id="${tab.id}"]`);
372374
if (!vp) {
@@ -385,21 +387,37 @@ <h2 id="side-panel-title" class="font-black text-[10px] tracking-widest uppercas
385387
zoomCont.style.height = (100 / tab.zoom) + '%';
386388

387389
const iframe = vp.querySelector('iframe');
388-
// Use getAttribute('src') for comparison to avoid permission errors on cross-origin content
389390
if (isActive && iframe.getAttribute('src') !== tab.proxyUrl) {
390391
iframe.src = tab.proxyUrl;
391392
}
392393
});
393394
}
394395

396+
// Event Listeners
395397
addressBar.onkeydown = (e) => { if (e.key === 'Enter') navigate(addressBar.value); };
396398
menuBtn.onclick = (e) => { e.stopPropagation(); menuDropdown.classList.toggle('hidden'); };
397399
document.onclick = () => menuDropdown.classList.add('hidden');
398400
document.getElementById('add-tab-btn').onclick = () => createTab();
399-
document.getElementById('zoom-in-btn').onclick = () => updateTab(activeTabId, { zoom: Math.min(3, tabs.find(t => t.id === activeTabId).zoom + 0.1) });
400-
document.getElementById('zoom-out-btn').onclick = () => updateTab(activeTabId, { zoom: Math.max(0.25, tabs.find(t => t.id === activeTabId).zoom - 0.1) });
401+
document.getElementById('zoom-in-btn').onclick = () => updateTab(activeTabId, { zoom: Math.min(3, (tabs.find(t => t.id === activeTabId)?.zoom || 1) + 0.1) });
402+
document.getElementById('zoom-out-btn').onclick = () => updateTab(activeTabId, { zoom: Math.max(0.25, (tabs.find(t => t.id === activeTabId)?.zoom || 1) - 0.1) });
401403
document.getElementById('music-trigger').onclick = (e) => { e.stopPropagation(); toggleSidePanel('Audio', 'music.html'); };
402404
document.getElementById('settings-trigger').onclick = (e) => { e.stopPropagation(); toggleSidePanel('Settings', 'settings.html'); };
405+
document.getElementById('refresh-btn').onclick = () => {
406+
const vp = viewportContainer.querySelector(`.viewport[data-id="${activeTabId}"]`);
407+
if (vp) {
408+
const iframe = vp.querySelector('iframe');
409+
iframe.src = iframe.src;
410+
}
411+
};
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+
403421
closeSidePanel.onclick = () => sidePanel.classList.remove('open');
404422

405423
window.addEventListener('message', (e) => {
@@ -411,6 +429,7 @@ <h2 id="side-panel-title" class="font-black text-[10px] tracking-widest uppercas
411429
}
412430
});
413431

432+
// App Start
414433
if (!loadSession()) createTab();
415434
setInterval(() => {
416435
const now = new Date();

0 commit comments

Comments
 (0)