/* Small iframe browser. Cross-origin pages decide whether they allow embedding. */ (() => { const HOME = 'https://www.google.com/webhp?igu=1'; const pages = [HOME]; let position = 0; const t = key => LifeI18n.t(`browser.${key}`); const container = () => document.querySelector('#content-browser'); const current = () => pages[position]; function address(value) { const input = String(value || '').trim(); if (!input) return HOME; if (/^[a-z][a-z\d+.-]*:/i.test(input) && !/^https?:\/\//i.test(input)) return null; let url; try { if (/^https?:\/\//i.test(input)) url = new URL(input); else if (/^[^\s/]+\.[^\s]+/.test(input)) url = new URL(`https://${input}`); else return `https://www.google.com/search?igu=1&q=${encodeURIComponent(input)}`; } catch { return null; } if (!['http:', 'https:'].includes(url.protocol) || !url.hostname) return null; if (url.protocol === 'http:') url.protocol = 'https:'; if (['google.com', 'www.google.com'].includes(url.hostname.toLowerCase())) { if (url.pathname === '/') url.pathname = '/webhp'; if (['/webhp', '/search'].includes(url.pathname)) url.searchParams.set('igu', '1'); } return url.href; } function updateChrome(node, navigate = false) { const frame = node.querySelector('iframe'), input = node.querySelector('.browser-address'); if (!frame) return; if (navigate || !frame.getAttribute('src')) frame.src = current(); if (input && document.activeElement !== input) input.value = current(); node.querySelector('[data-action="back"]').disabled = position === 0; node.querySelector('[data-action="forward"]').disabled = position === pages.length - 1; node.querySelector('.browser-external').href = current(); node.querySelector('.browser-hint-link').href = current(); } function go(value) { const url = address(value); if (!url) { toast(t('invalid')); return; } if (url !== current()) { pages.splice(position + 1); pages.push(url); position = pages.length - 1; } const node = container(); if (node) updateChrome(node, true); } window.browserApp = node => { if (node.querySelector('.browser-shell') && node.dataset.browserLocale === lang()) { updateChrome(node); return; } node.dataset.browserLocale = lang(); node.innerHTML = `
${t('embedHint')} ${t('external')}