forked from sent/waves
<3
This commit is contained in:
parent
6b4ec8b1ae
commit
a21cb430a3
|
@ -8,7 +8,7 @@
|
|||
<meta property="og:image" content="/assets/images/icons/favicon.ico"/>
|
||||
<meta name="theme-color" content="#ffffff"/>
|
||||
<meta name="msapplication-TileColor" content="#ffffff"/>
|
||||
<title>Waves</title>
|
||||
<title>Waves.</title>
|
||||
<link rel="icon" type="image/x-icon" href="/assets/images/icons/favicon.ico">
|
||||
<link rel="stylesheet" href="/assets/css/$.css">
|
||||
<link rel="stylesheet" href="/assets/css/settings.css">
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<meta property="og:image" content="/assets/images/icons/favicon.ico"/>
|
||||
<meta name="theme-color" content="#ffffff"/>
|
||||
<meta name="msapplication-TileColor" content="#ffffff"/>
|
||||
<title>Waves</title>
|
||||
<title>Waves.</title>
|
||||
<link rel="icon" type="image/x-icon" href="/assets/images/icons/favicon.ico">
|
||||
<link rel="stylesheet" href="/assets/css/$.css">
|
||||
<link rel="stylesheet" href="/assets/css/settings.css">
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<meta property="og:image" content="/assets/images/icons/favicon.ico"/>
|
||||
<meta name="theme-color" content="#ffffff"/>
|
||||
<meta name="msapplication-TileColor" content="#ffffff"/>
|
||||
<title>Waves</title>
|
||||
<title>Waves.</title>
|
||||
<link rel="icon" type="image/x-icon" href="/assets/images/icons/favicon.ico">
|
||||
<link rel="stylesheet" href="/assets/css/$.css">
|
||||
<link rel="stylesheet" href="/assets/css/settings.css">
|
||||
|
|
|
@ -1,320 +1,315 @@
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const historyStack = [];
|
||||
let currentIndex = -1;
|
||||
const refreshIcon = document.getElementById('refreshIcon');
|
||||
const fullscreenIcon = document.getElementById('fullscreenIcon');
|
||||
const backIcon = document.getElementById('backIcon');
|
||||
const forwardIcon = document.getElementById('forwardIcon');
|
||||
const iframe = document.getElementById('cool-iframe');
|
||||
const erudaLoadingScreen = document.getElementById('erudaLoadingScreen');
|
||||
if (!refreshIcon || !fullscreenIcon || !backIcon || !forwardIcon || !iframe) return;
|
||||
let loadingHidden = false;
|
||||
const historyStack = []
|
||||
let currentIndex = -1
|
||||
const refreshIcon = document.getElementById('refreshIcon')
|
||||
const fullscreenIcon = document.getElementById('fullscreenIcon')
|
||||
const backIcon = document.getElementById('backIcon')
|
||||
const forwardIcon = document.getElementById('forwardIcon')
|
||||
const iframe = document.getElementById('cool-iframe')
|
||||
const erudaLoadingScreen = document.getElementById('erudaLoadingScreen')
|
||||
if (!refreshIcon || !fullscreenIcon || !backIcon || !forwardIcon || !iframe) return
|
||||
|
||||
const originalTitle = document.title
|
||||
let loadingHidden = false
|
||||
|
||||
function showLoadingScreen(withToast = true, showEruda = false) {
|
||||
loadingHidden = false;
|
||||
NProgress.start();
|
||||
if (withToast) {
|
||||
showToast(
|
||||
'Consider joining our <a href="https://discord.gg/dJvdkPRheV" target="_blank" class="hover-link">Discord</a> <3',
|
||||
'success',
|
||||
'heart'
|
||||
);
|
||||
}
|
||||
loadingHidden = false
|
||||
NProgress.start()
|
||||
document.title = 'Loading... <3'
|
||||
if (withToast) {
|
||||
showToast(
|
||||
'Consider joining our <a href="https://discord.gg/dJvdkPRheV" target="_blank" class="hover-link">Discord</a> <3',
|
||||
'success',
|
||||
'heart'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function hideLoadingScreen() {
|
||||
if (loadingHidden) return;
|
||||
loadingHidden = true;
|
||||
NProgress.done();
|
||||
if (loadingHidden) return
|
||||
loadingHidden = true
|
||||
NProgress.done()
|
||||
document.title = originalTitle
|
||||
}
|
||||
|
||||
refreshIcon.addEventListener('click', () => {
|
||||
refreshIcon.classList.add('spin');
|
||||
if (iframe.tagName === 'IFRAME') {
|
||||
const currentUrl = iframe.contentWindow.location.href;
|
||||
if (normalizeUrl(currentUrl) !== normalizeUrl(historyStack[currentIndex] || '')) {
|
||||
addToHistory(currentUrl);
|
||||
refreshIcon.classList.add('spin')
|
||||
if (iframe.tagName === 'IFRAME') {
|
||||
const currentUrl = iframe.contentWindow.location.href
|
||||
if (normalizeUrl(currentUrl) !== normalizeUrl(historyStack[currentIndex] || '')) {
|
||||
addToHistory(currentUrl)
|
||||
}
|
||||
iframe.contentWindow.location.reload(true)
|
||||
}
|
||||
iframe.contentWindow.location.reload(true);
|
||||
}
|
||||
setTimeout(() => refreshIcon.classList.remove('spin'), 300);
|
||||
});
|
||||
setTimeout(() => refreshIcon.classList.remove('spin'), 300)
|
||||
})
|
||||
|
||||
fullscreenIcon.addEventListener('click', () => {
|
||||
if (iframe.requestFullscreen) iframe.requestFullscreen();
|
||||
else if (iframe.mozRequestFullScreen) iframe.mozRequestFullScreen();
|
||||
else if (iframe.webkitRequestFullscreen) iframe.webkitRequestFullscreen();
|
||||
else if (iframe.msRequestFullscreen) iframe.msRequestFullscreen();
|
||||
});
|
||||
if (iframe.requestFullscreen) iframe.requestFullscreen()
|
||||
else if (iframe.mozRequestFullScreen) iframe.mozRequestFullScreen()
|
||||
else if (iframe.webkitRequestFullscreen) iframe.webkitRequestFullscreen()
|
||||
else if (iframe.msRequestFullscreen) iframe.msRequestFullscreen()
|
||||
})
|
||||
|
||||
backIcon.addEventListener('click', () => {
|
||||
if (currentIndex > 0) {
|
||||
currentIndex--;
|
||||
iframe.src = historyStack[currentIndex];
|
||||
showLoadingScreen(false, false);
|
||||
updateNavButtons();
|
||||
updateDecodedSearchInput();
|
||||
}
|
||||
});
|
||||
if (currentIndex > 0) {
|
||||
currentIndex--
|
||||
iframe.src = historyStack[currentIndex]
|
||||
showLoadingScreen(false, false)
|
||||
updateNavButtons()
|
||||
updateDecodedSearchInput()
|
||||
}
|
||||
})
|
||||
|
||||
forwardIcon.addEventListener('click', () => {
|
||||
if (currentIndex < historyStack.length - 1) {
|
||||
currentIndex++;
|
||||
iframe.src = historyStack[currentIndex];
|
||||
showLoadingScreen(false, false);
|
||||
updateNavButtons();
|
||||
updateDecodedSearchInput();
|
||||
}
|
||||
});
|
||||
if (currentIndex < historyStack.length - 1) {
|
||||
currentIndex++
|
||||
iframe.src = historyStack[currentIndex]
|
||||
showLoadingScreen(false, false)
|
||||
updateNavButtons()
|
||||
updateDecodedSearchInput()
|
||||
}
|
||||
})
|
||||
|
||||
function normalizeUrl(urlStr) {
|
||||
try {
|
||||
const url = new URL(urlStr);
|
||||
url.searchParams.delete('ia');
|
||||
return url.toString();
|
||||
} catch (e) {
|
||||
return urlStr;
|
||||
}
|
||||
try {
|
||||
const url = new URL(urlStr)
|
||||
url.searchParams.delete('ia')
|
||||
return url.toString()
|
||||
} catch (e) {
|
||||
return urlStr
|
||||
}
|
||||
}
|
||||
|
||||
function addToHistory(url) {
|
||||
const normalized = normalizeUrl(url);
|
||||
if (currentIndex >= 0 && normalizeUrl(historyStack[currentIndex]) === normalized) return;
|
||||
if (currentIndex < historyStack.length - 1) historyStack.splice(currentIndex + 1);
|
||||
historyStack.push(url);
|
||||
currentIndex++;
|
||||
updateNavButtons();
|
||||
updateDecodedSearchInput();
|
||||
const normalized = normalizeUrl(url)
|
||||
if (currentIndex >= 0 && normalizeUrl(historyStack[currentIndex]) === normalized) return
|
||||
if (currentIndex < historyStack.length - 1) historyStack.splice(currentIndex + 1)
|
||||
historyStack.push(url)
|
||||
currentIndex++
|
||||
updateNavButtons()
|
||||
updateDecodedSearchInput()
|
||||
}
|
||||
|
||||
function updateNavButtons() {
|
||||
backIcon.disabled = currentIndex <= 0;
|
||||
forwardIcon.disabled = currentIndex >= historyStack.length - 1;
|
||||
backIcon.classList.toggle('disabled', currentIndex <= 0);
|
||||
forwardIcon.classList.toggle('disabled', currentIndex >= historyStack.length - 1);
|
||||
backIcon.disabled = currentIndex <= 0
|
||||
forwardIcon.disabled = currentIndex >= historyStack.length - 1
|
||||
backIcon.classList.toggle('disabled', currentIndex <= 0)
|
||||
forwardIcon.classList.toggle('disabled', currentIndex >= historyStack.length - 1)
|
||||
}
|
||||
|
||||
function updateDecodedSearchInput() {
|
||||
const searchInput2 = document.getElementById('searchInputt');
|
||||
if (!searchInput2) return;
|
||||
let url = '';
|
||||
if (currentIndex >= 0 && historyStack[currentIndex]) {
|
||||
url = historyStack[currentIndex];
|
||||
} else if (iframe.src) {
|
||||
url = iframe.src;
|
||||
}
|
||||
searchInput2.value = decodeUrl(url);
|
||||
const lockIcon = document.getElementById('lockIcon');
|
||||
if (lockIcon) {
|
||||
lockIcon.className = decodeUrl(url).startsWith('https://')
|
||||
? 'fa-regular fa-lock'
|
||||
: 'fa-regular fa-lock-open';
|
||||
lockIcon.style.color = '';
|
||||
}
|
||||
const searchInput2 = document.getElementById('searchInputt')
|
||||
if (!searchInput2) return
|
||||
let url = ''
|
||||
if (currentIndex >= 0 && historyStack[currentIndex]) {
|
||||
url = historyStack[currentIndex]
|
||||
} else if (iframe.src) {
|
||||
url = iframe.src
|
||||
}
|
||||
searchInput2.value = decodeUrl(url)
|
||||
const lockIcon = document.getElementById('lockIcon')
|
||||
if (lockIcon) {
|
||||
lockIcon.className = decodeUrl(url).startsWith('https://') ?
|
||||
'fa-regular fa-lock' :
|
||||
'fa-regular fa-lock-open'
|
||||
lockIcon.style.color = ''
|
||||
}
|
||||
}
|
||||
|
||||
iframe.addEventListener('load', () => {
|
||||
try { hideLoadingScreen(); }
|
||||
catch (error) {
|
||||
console.error('Error during iframe load:', error);
|
||||
hideLoadingScreen();
|
||||
} finally {
|
||||
if (erudaLoadingScreen) erudaLoadingScreen.style.display = 'none';
|
||||
}
|
||||
});
|
||||
try {
|
||||
hideLoadingScreen()
|
||||
} catch {
|
||||
hideLoadingScreen()
|
||||
} finally {
|
||||
if (erudaLoadingScreen) erudaLoadingScreen.style.display = 'none'
|
||||
}
|
||||
})
|
||||
|
||||
iframe.addEventListener('error', () => {
|
||||
console.error('Error loading iframe content.');
|
||||
hideLoadingScreen();
|
||||
});
|
||||
hideLoadingScreen()
|
||||
})
|
||||
|
||||
iframe.addEventListener('loadstart', () => {
|
||||
if (navbarToggle && navbarToggle.checked && navBar) {
|
||||
navBar.style.display = 'block';
|
||||
}
|
||||
showLoadingScreen(false, false);
|
||||
});
|
||||
const navBar = document.querySelector('.navbar')
|
||||
const navbarToggle = document.getElementById('navbar-toggle')
|
||||
if (navbarToggle && navbarToggle.checked && navBar) navBar.style.display = 'block'
|
||||
showLoadingScreen(false, false)
|
||||
})
|
||||
|
||||
const navBar = document.querySelector('.navbar');
|
||||
const topBar = document.querySelector('.topbar');
|
||||
const searchInput1 = document.getElementById('searchInput');
|
||||
const searchInput2 = document.getElementById('searchInputt');
|
||||
const movies = document.getElementById('movies');
|
||||
const ai = document.getElementById('ai');
|
||||
const navbarToggle = document.getElementById('navbar-toggle');
|
||||
const navBar = document.querySelector('.navbar')
|
||||
const topBar = document.querySelector('.topbar')
|
||||
const searchInput1 = document.getElementById('searchInput')
|
||||
const searchInput2 = document.getElementById('searchInputt')
|
||||
const movies = document.getElementById('movies')
|
||||
const ai = document.getElementById('ai')
|
||||
const navbarToggle = document.getElementById('navbar-toggle')
|
||||
|
||||
if (navbarToggle && navBar) {
|
||||
const savedNavbarState = localStorage.getItem('navbarToggled');
|
||||
navbarToggle.checked = savedNavbarState === null ? true : savedNavbarState === 'true';
|
||||
navBar.style.display =
|
||||
iframe.style.display === 'block' && navbarToggle.checked ? 'block' : 'none';
|
||||
navbarToggle.addEventListener('change', () => {
|
||||
localStorage.setItem('navbarToggled', navbarToggle.checked);
|
||||
navBar.style.display =
|
||||
iframe.style.display === 'block' && navbarToggle.checked ? 'block' : 'none';
|
||||
});
|
||||
const savedNavbarState = localStorage.getItem('navbarToggled')
|
||||
navbarToggle.checked = savedNavbarState === null ? true : savedNavbarState === 'true'
|
||||
navBar.style.display = iframe.style.display === 'block' && navbarToggle.checked ? 'block' : 'none'
|
||||
navbarToggle.addEventListener('change', () => {
|
||||
localStorage.setItem('navbarToggled', navbarToggle.checked)
|
||||
navBar.style.display = iframe.style.display === 'block' && navbarToggle.checked ? 'block' : 'none'
|
||||
})
|
||||
}
|
||||
|
||||
iframe.style.display = 'none';
|
||||
window.addEventListener('load', hideLoadingScreen);
|
||||
iframe.style.display = 'none'
|
||||
window.addEventListener('load', hideLoadingScreen)
|
||||
|
||||
;
|
||||
[searchInput1, searchInput2].forEach(input => {
|
||||
if (input) {
|
||||
input.addEventListener('keyup', e => {
|
||||
if (e.key === 'Enter') handleSearch(input.value);
|
||||
});
|
||||
}
|
||||
});
|
||||
if (movies) movies.addEventListener('click', e => { e.preventDefault(); handleSearch('https://movies.usewaves.site/'); });
|
||||
if (ai) ai.addEventListener('click', e => { e.preventDefault(); handleSearch('https://ai.usewaves.site/'); });
|
||||
if (input) {
|
||||
input.addEventListener('keyup', e => {
|
||||
if (e.key === 'Enter') handleSearch(input.value)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
if (movies) movies.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
handleSearch('https://movies.usewaves.site/')
|
||||
})
|
||||
if (ai) ai.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
handleSearch('https://ai.usewaves.site/')
|
||||
})
|
||||
|
||||
function clearBackground() {
|
||||
const preserved = [
|
||||
document.querySelector('.navbar'),
|
||||
document.getElementById('cool-iframe'),
|
||||
document.querySelector('.loading-screen'),
|
||||
erudaLoadingScreen
|
||||
];
|
||||
Array.from(document.body.children).forEach(child => {
|
||||
if (!preserved.includes(child)) child.remove();
|
||||
});
|
||||
const preserved = [
|
||||
document.querySelector('.navbar'),
|
||||
document.getElementById('cool-iframe'),
|
||||
document.querySelector('.loading-screen'),
|
||||
erudaLoadingScreen
|
||||
]
|
||||
Array.from(document.body.children).forEach(child => {
|
||||
if (!preserved.includes(child)) child.remove()
|
||||
})
|
||||
}
|
||||
|
||||
async function handleSearch(query) {
|
||||
clearBackground();
|
||||
|
||||
let searchURL;
|
||||
clearBackground()
|
||||
let searchURL
|
||||
if (
|
||||
query.startsWith('/assets/g/') ||
|
||||
query.startsWith(window.location.origin + '/assets/g/')
|
||||
query.startsWith('/assets/g/') ||
|
||||
query.startsWith(window.location.origin + '/assets/g/')
|
||||
) {
|
||||
searchURL = query;
|
||||
searchURL = query
|
||||
} else {
|
||||
searchURL = generateSearchUrl(query);
|
||||
searchURL = generateSearchUrl(query)
|
||||
}
|
||||
|
||||
if (searchInput2) searchInput2.value = searchURL;
|
||||
|
||||
historyStack.length = 0;
|
||||
currentIndex = -1;
|
||||
showLoadingScreen(true, false);
|
||||
iframe.style.display = 'block';
|
||||
if (topBar) topBar.style.display = 'none';
|
||||
backIcon.disabled = forwardIcon.disabled = true;
|
||||
|
||||
let finalUrl;
|
||||
if (searchInput2) searchInput2.value = searchURL
|
||||
historyStack.length = 0
|
||||
currentIndex = -1
|
||||
showLoadingScreen(true, false)
|
||||
iframe.style.display = 'block'
|
||||
if (topBar) topBar.style.display = 'none'
|
||||
backIcon.disabled = forwardIcon.disabled = true
|
||||
let finalUrl
|
||||
try {
|
||||
const u = new URL(searchURL, window.location.origin);
|
||||
if (u.origin === window.location.origin && u.pathname.startsWith('/assets/g/')) {
|
||||
finalUrl = u.href;
|
||||
} else {
|
||||
finalUrl = await getUrl(searchURL);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error parsing URL, proxying by default:', err);
|
||||
finalUrl = await getUrl(searchURL);
|
||||
const u = new URL(searchURL, window.location.origin)
|
||||
if (u.origin === window.location.origin && u.pathname.startsWith('/assets/g/')) {
|
||||
finalUrl = u.href
|
||||
} else {
|
||||
finalUrl = await getUrl(searchURL)
|
||||
}
|
||||
} catch {
|
||||
finalUrl = await getUrl(searchURL)
|
||||
}
|
||||
|
||||
iframe.src = finalUrl;
|
||||
iframe.src = finalUrl
|
||||
iframe.onload = () => {
|
||||
hideLoadingScreen();
|
||||
if (navbarToggle && navbarToggle.checked && navBar) navBar.style.display = 'block';
|
||||
generateSubject();
|
||||
updateDecodedSearchInput();
|
||||
};
|
||||
hideLoadingScreen()
|
||||
if (navbarToggle && navbarToggle.checked && navBar) navBar.style.display = 'block'
|
||||
generateSubject()
|
||||
updateDecodedSearchInput()
|
||||
}
|
||||
iframe.onerror = () => {
|
||||
console.error('Failed to load content.');
|
||||
hideLoadingScreen();
|
||||
};
|
||||
}
|
||||
hideLoadingScreen()
|
||||
}
|
||||
}
|
||||
|
||||
window.handleSearch = handleSearch;
|
||||
window.handleSearch = handleSearch
|
||||
|
||||
function generateSearchUrl(query) {
|
||||
try {
|
||||
return new URL(query).toString();
|
||||
} catch {
|
||||
try {
|
||||
const u = new URL(`https://${query}`);
|
||||
if (u.hostname.includes('.')) return u.toString();
|
||||
} catch {}
|
||||
}
|
||||
return `https://duckduckgo.com/?q=${encodeURIComponent(query)}&ia=web`;
|
||||
return new URL(query).toString()
|
||||
} catch {
|
||||
try {
|
||||
const u = new URL(`https://${query}`)
|
||||
if (u.hostname.includes('.')) return u.toString()
|
||||
} catch {}
|
||||
}
|
||||
return `https://duckduckgo.com/?q=${encodeURIComponent(query)}&ia=web`
|
||||
}
|
||||
|
||||
function showToast(message, type = 'success', iconType = 'check') {
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast show ${type}`;
|
||||
const icons = {
|
||||
success: '<i class="fa-regular fa-check-circle" style="margin-right: 8px;"></i>',
|
||||
error: '<i class="fa-regular fa-times-circle" style="margin-right: 8px;"></i>',
|
||||
info: '<i class="fa-regular fa-info-circle" style="margin-right: 8px;"></i>',
|
||||
warning: '<i class="fa-regular fa-exclamation-triangle" style="margin-right: 8px;"></i>',
|
||||
heart: '<i class="fa-regular fa-heart" style="margin-right: 8px;"></i>'
|
||||
};
|
||||
const icon = icons[iconType] || icons.heart;
|
||||
toast.innerHTML = `${icon}${message} `;
|
||||
const progressBar = document.createElement('div');
|
||||
progressBar.className = 'progress-bar';
|
||||
toast.appendChild(progressBar);
|
||||
const closeBtn = document.createElement('button');
|
||||
closeBtn.className = 'toast-close';
|
||||
closeBtn.innerHTML = '<i class="fa-solid fa-xmark" style="margin-left: 8px; font-size: 0.8em;"></i>';
|
||||
closeBtn.addEventListener('click', () => {
|
||||
toast.classList.add('hide');
|
||||
setTimeout(() => toast.remove(), 500);
|
||||
});
|
||||
toast.appendChild(closeBtn);
|
||||
document.body.appendChild(toast);
|
||||
setTimeout(() => {
|
||||
toast.classList.add('hide');
|
||||
setTimeout(() => toast.remove(), 500);
|
||||
}, 3000);
|
||||
const toast = document.createElement('div')
|
||||
toast.className = `toast show ${type}`
|
||||
const icons = {
|
||||
success: '<i class="fa-regular fa-check-circle" style="margin-right: 8px;"></i>',
|
||||
error: '<i class="fa-regular fa-times-circle" style="margin-right: 8px;"></i>',
|
||||
info: '<i class="fa-regular fa-info-circle" style="margin-right: 8px;"></i>',
|
||||
warning: '<i class="fa-regular fa-exclamation-triangle" style="margin-right: 8px;"></i>',
|
||||
heart: '<i class="fa-regular fa-heart" style="margin-right: 8px;"></i>'
|
||||
}
|
||||
const icon = icons[iconType] || icons.heart
|
||||
toast.innerHTML = `${icon}${message} `
|
||||
const progressBar = document.createElement('div')
|
||||
progressBar.className = 'progress-bar'
|
||||
toast.appendChild(progressBar)
|
||||
const closeBtn = document.createElement('button')
|
||||
closeBtn.className = 'toast-close'
|
||||
closeBtn.innerHTML = '<i class="fa-solid fa-xmark" style="margin-left: 8px; font-size: 0.8em;"></i>'
|
||||
closeBtn.addEventListener('click', () => {
|
||||
toast.classList.add('hide')
|
||||
setTimeout(() => toast.remove(), 500)
|
||||
})
|
||||
toast.appendChild(closeBtn)
|
||||
document.body.appendChild(toast)
|
||||
setTimeout(() => {
|
||||
toast.classList.add('hide')
|
||||
setTimeout(() => toast.remove(), 500)
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
function preloadResources(url) {
|
||||
if (!url) {
|
||||
console.error('Preload failed: URL is undefined or empty.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!url) return
|
||||
try {
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'preload';
|
||||
link.href = url;
|
||||
link.as = 'fetch';
|
||||
link.crossOrigin = 'anonymous';
|
||||
document.head.appendChild(link);
|
||||
console.log(`Resource preloaded: ${url}`);
|
||||
} catch (error) {
|
||||
console.error('Error preloading resource:', error);
|
||||
}
|
||||
const link = document.createElement('link')
|
||||
link.rel = 'preload'
|
||||
link.href = url
|
||||
link.as = 'fetch'
|
||||
link.crossOrigin = 'anonymous'
|
||||
document.head.appendChild(link)
|
||||
} catch {}
|
||||
}
|
||||
|
||||
function getUrl(url) {
|
||||
return Promise.resolve(__uv$config.prefix + __uv$config.encodeUrl(url));
|
||||
return Promise.resolve(__uv$config.prefix + __uv$config.encodeUrl(url))
|
||||
}
|
||||
|
||||
function generateSubject() {
|
||||
const subjects = ['math', 'science', 'history', 'art', 'programming', 'philosophy'];
|
||||
const random = subjects[Math.floor(Math.random() * subjects.length)];
|
||||
history.replaceState({}, '', '/learning?subject=' + random);
|
||||
const subjects = ['math', 'science', 'history', 'art', 'programming', 'philosophy']
|
||||
const random = subjects[Math.floor(Math.random() * subjects.length)]
|
||||
history.replaceState({}, '', '/learning?subject=' + random)
|
||||
}
|
||||
|
||||
function decodeUrl(enc) {
|
||||
try {
|
||||
const o = new URL(enc, window.location.origin);
|
||||
const p = (__uv$config && __uv$config.prefix) || '/wa/a/';
|
||||
if (o.pathname.startsWith(p)) {
|
||||
const part = o.pathname.slice(p.length);
|
||||
return (__uv$config.decodeUrl ? __uv$config.decodeUrl(part) : decodeURIComponent(part));
|
||||
}
|
||||
} catch {}
|
||||
return enc;
|
||||
try {
|
||||
const o = new URL(enc, window.location.origin)
|
||||
const p = (__uv$config && __uv$config.prefix) || '/wa/a/'
|
||||
if (o.pathname.startsWith(p)) {
|
||||
const part = o.pathname.slice(p.length)
|
||||
return (__uv$config.decodeUrl ? __uv$config.decodeUrl(part) : decodeURIComponent(part))
|
||||
}
|
||||
} catch {}
|
||||
return enc
|
||||
}
|
||||
|
||||
window.decodeUrl = decodeUrl;
|
||||
window.addToHistory = addToHistory;
|
||||
window.updateDecodedSearchInput = updateDecodedSearchInput;
|
||||
window.normalizeUrl = normalizeUrl;
|
||||
});
|
||||
window.decodeUrl = decodeUrl
|
||||
window.addToHistory = addToHistory
|
||||
window.updateDecodedSearchInput = updateDecodedSearchInput
|
||||
window.normalizeUrl = normalizeUrl
|
||||
})
|
|
@ -10,13 +10,14 @@ document.head.appendChild(style);
|
|||
const historyStack = [];
|
||||
let currentIndex = -1;
|
||||
const elements = {
|
||||
refreshIcon: document.getElementById('refreshIcon'),
|
||||
fullscreenIcon: document.getElementById('fullscreenIcon'),
|
||||
backIcon: document.getElementById('backIcon'),
|
||||
forwardIcon: document.getElementById('forwardIcon'),
|
||||
searchInput2: document.getElementById('searchInputt'),
|
||||
iframe: document.getElementById('cool-iframe')
|
||||
refreshIcon: document.getElementById('refreshIcon'),
|
||||
fullscreenIcon: document.getElementById('fullscreenIcon'),
|
||||
backIcon: document.getElementById('backIcon'),
|
||||
forwardIcon: document.getElementById('forwardIcon'),
|
||||
searchInput2: document.getElementById('searchInputt'),
|
||||
iframe: document.getElementById('cool-iframe')
|
||||
};
|
||||
const originalTitle = document.title;
|
||||
let loadingFallbackTimeout;
|
||||
|
||||
elements.refreshIcon.addEventListener('click', handleRefresh);
|
||||
|
@ -25,99 +26,106 @@ elements.backIcon.addEventListener('click', handleBack);
|
|||
elements.forwardIcon.addEventListener('click', handleForward);
|
||||
|
||||
function showLoadingScreen() {
|
||||
if (typeof NProgress !== 'undefined') NProgress.start();
|
||||
if (typeof NProgress !== 'undefined') {
|
||||
NProgress.start();
|
||||
document.title = 'Loading... <3';
|
||||
setTimeout(() => {
|
||||
if (typeof NProgress !== 'undefined') NProgress.done();
|
||||
}, 10000);
|
||||
}
|
||||
}
|
||||
|
||||
function hideLoadingScreen() {
|
||||
if (typeof NProgress !== 'undefined') NProgress.done();
|
||||
if (typeof NProgress !== 'undefined') NProgress.done();
|
||||
document.title = originalTitle;
|
||||
}
|
||||
|
||||
function handleRefresh() {
|
||||
elements.refreshIcon.classList.add('spin');
|
||||
const iframe = elements.iframe;
|
||||
const currentUrl = iframe.contentWindow.location.href;
|
||||
if (normalizeUrl(currentUrl) !== normalizeUrl(historyStack[currentIndex] || '')) {
|
||||
addToHistory(currentUrl);
|
||||
}
|
||||
iframe.contentWindow.location.reload(true);
|
||||
setTimeout(() => elements.refreshIcon.classList.remove('spin'), 300);
|
||||
elements.refreshIcon.classList.add('spin');
|
||||
const iframe = elements.iframe;
|
||||
const currentUrl = iframe.contentWindow.location.href;
|
||||
if (normalizeUrl(currentUrl) !== normalizeUrl(historyStack[currentIndex] || '')) {
|
||||
addToHistory(currentUrl);
|
||||
}
|
||||
iframe.contentWindow.location.reload(true);
|
||||
setTimeout(() => elements.refreshIcon.classList.remove('spin'), 300);
|
||||
}
|
||||
|
||||
function handleFullscreen() {
|
||||
const iframe = elements.iframe;
|
||||
if (iframe && iframe.tagName === 'IFRAME') iframe.requestFullscreen();
|
||||
const iframe = elements.iframe;
|
||||
if (iframe && iframe.tagName === 'IFRAME') iframe.requestFullscreen();
|
||||
}
|
||||
|
||||
function handleBack() {
|
||||
toggleButtonAnimation(elements.backIcon, 'button-animate-back');
|
||||
if (currentIndex > 0) {
|
||||
currentIndex--;
|
||||
updateIframeSrc();
|
||||
}
|
||||
toggleButtonAnimation(elements.backIcon, 'button-animate-back');
|
||||
if (currentIndex > 0) {
|
||||
currentIndex--;
|
||||
updateIframeSrc();
|
||||
}
|
||||
}
|
||||
|
||||
function handleForward() {
|
||||
toggleButtonAnimation(elements.forwardIcon, 'button-animate-forward');
|
||||
if (currentIndex < historyStack.length - 1) {
|
||||
currentIndex++;
|
||||
updateIframeSrc();
|
||||
}
|
||||
toggleButtonAnimation(elements.forwardIcon, 'button-animate-forward');
|
||||
if (currentIndex < historyStack.length - 1) {
|
||||
currentIndex++;
|
||||
updateIframeSrc();
|
||||
}
|
||||
}
|
||||
|
||||
function toggleButtonAnimation(button, animationClass) {
|
||||
button.classList.add(animationClass);
|
||||
setTimeout(() => button.classList.remove(animationClass), 200);
|
||||
button.classList.add(animationClass);
|
||||
setTimeout(() => button.classList.remove(animationClass), 200);
|
||||
}
|
||||
|
||||
function normalizeUrl(urlStr) {
|
||||
try {
|
||||
const url = new URL(urlStr);
|
||||
url.searchParams.delete('ia');
|
||||
return url.toString();
|
||||
} catch (e) {
|
||||
return urlStr;
|
||||
}
|
||||
try {
|
||||
const url = new URL(urlStr);
|
||||
url.searchParams.delete('ia');
|
||||
return url.toString();
|
||||
} catch (e) {
|
||||
return urlStr;
|
||||
}
|
||||
}
|
||||
|
||||
function addToHistory(url) {
|
||||
const normalized = normalizeUrl(url);
|
||||
if (currentIndex >= 0 && normalizeUrl(historyStack[currentIndex]) === normalized) return;
|
||||
if (currentIndex < historyStack.length - 1) historyStack.splice(currentIndex + 1);
|
||||
historyStack.push(url);
|
||||
currentIndex++;
|
||||
updateNavButtons();
|
||||
updateDecodedSearchInput();
|
||||
const normalized = normalizeUrl(url);
|
||||
if (currentIndex >= 0 && normalizeUrl(historyStack[currentIndex]) === normalized) return;
|
||||
if (currentIndex < historyStack.length - 1) historyStack.splice(currentIndex + 1);
|
||||
historyStack.push(url);
|
||||
currentIndex++;
|
||||
updateNavButtons();
|
||||
updateDecodedSearchInput();
|
||||
}
|
||||
|
||||
function updateIframeSrc() {
|
||||
showLoadingScreen();
|
||||
elements.iframe.src = historyStack[currentIndex];
|
||||
updateNavButtons();
|
||||
updateDecodedSearchInput();
|
||||
showLoadingScreen();
|
||||
elements.iframe.src = historyStack[currentIndex];
|
||||
updateNavButtons();
|
||||
updateDecodedSearchInput();
|
||||
}
|
||||
|
||||
function updateNavButtons() {
|
||||
const isAtStart = currentIndex <= 0;
|
||||
const isAtEnd = currentIndex >= historyStack.length - 1;
|
||||
elements.backIcon.disabled = isAtStart;
|
||||
elements.forwardIcon.disabled = isAtEnd;
|
||||
elements.backIcon.classList.toggle('disabled', isAtStart);
|
||||
elements.forwardIcon.classList.toggle('disabled', isAtEnd);
|
||||
const isAtStart = currentIndex <= 0;
|
||||
const isAtEnd = currentIndex >= historyStack.length - 1;
|
||||
elements.backIcon.disabled = isAtStart;
|
||||
elements.forwardIcon.disabled = isAtEnd;
|
||||
elements.backIcon.classList.toggle('disabled', isAtStart);
|
||||
elements.forwardIcon.classList.toggle('disabled', isAtEnd);
|
||||
}
|
||||
|
||||
function updateDecodedSearchInput() {
|
||||
if (elements.searchInput2) {
|
||||
const url = historyStack[currentIndex] || elements.iframe.src;
|
||||
elements.searchInput2.value = decodeUrl(url);
|
||||
}
|
||||
if (elements.searchInput2) {
|
||||
const url = historyStack[currentIndex] || elements.iframe.src;
|
||||
elements.searchInput2.value = decodeUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
function decodeUrl(url) {
|
||||
try {
|
||||
return decodeURIComponent(url);
|
||||
} catch (e) {
|
||||
return url;
|
||||
}
|
||||
try {
|
||||
return decodeURIComponent(url);
|
||||
} catch (e) {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
window.addToHistory = addToHistory;
|
||||
|
@ -125,57 +133,51 @@ window.updateDecodedSearchInput = updateDecodedSearchInput;
|
|||
window.normalizeUrl = normalizeUrl;
|
||||
|
||||
function detectIframeNavigation() {
|
||||
try {
|
||||
const iframeWindow = elements.iframe.contentWindow;
|
||||
const pushState = iframeWindow.history.pushState;
|
||||
const replaceState = iframeWindow.history.replaceState;
|
||||
iframeWindow.history.pushState = function() {
|
||||
pushState.apply(this, arguments);
|
||||
handleIframeNavigation(iframeWindow.location.href);
|
||||
};
|
||||
iframeWindow.history.replaceState = function() {
|
||||
replaceState.apply(this, arguments);
|
||||
handleIframeNavigation(iframeWindow.location.href);
|
||||
};
|
||||
iframeWindow.addEventListener('popstate', () => handleIframeNavigation(iframeWindow.location.href));
|
||||
iframeWindow.addEventListener('hashchange', () => handleIframeNavigation(iframeWindow.location.href));
|
||||
} catch (error) {}
|
||||
try {
|
||||
const iframeWindow = elements.iframe.contentWindow;
|
||||
const pushState = iframeWindow.history.pushState;
|
||||
const replaceState = iframeWindow.history.replaceState;
|
||||
iframeWindow.history.pushState = function() {
|
||||
pushState.apply(this, arguments);
|
||||
handleIframeNavigation(iframeWindow.location.href);
|
||||
};
|
||||
iframeWindow.history.replaceState = function() {
|
||||
replaceState.apply(this, arguments);
|
||||
handleIframeNavigation(iframeWindow.location.href);
|
||||
};
|
||||
iframeWindow.addEventListener('popstate', () => handleIframeNavigation(iframeWindow.location.href));
|
||||
iframeWindow.addEventListener('hashchange', () => handleIframeNavigation(iframeWindow.location.href));
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
function handleIframeNavigation(rawUrl) {
|
||||
let urlStr = rawUrl;
|
||||
try {
|
||||
urlStr = decodeUrl(rawUrl);
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
const u = new URL(urlStr);
|
||||
if (u.hostname.endsWith('duckduckgo.com')) {
|
||||
if (typeof NProgress !== 'undefined') NProgress.done();
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
if (normalizeUrl(urlStr) !== normalizeUrl(historyStack[currentIndex] || '')) {
|
||||
showLoadingScreen();
|
||||
addToHistory(urlStr);
|
||||
} else {
|
||||
hideLoadingScreen();
|
||||
}
|
||||
}
|
||||
let urlStr = rawUrl;
|
||||
try {
|
||||
urlStr = decodeUrl(rawUrl);
|
||||
} catch {}
|
||||
try {
|
||||
const u = new URL(urlStr);
|
||||
if (u.hostname.endsWith('duckduckgo.com')) {
|
||||
if (typeof NProgress !== 'undefined') NProgress.done();
|
||||
return;
|
||||
}
|
||||
} catch (e) {}
|
||||
if (normalizeUrl(urlStr) !== normalizeUrl(historyStack[currentIndex] || '')) {
|
||||
showLoadingScreen();
|
||||
addToHistory(urlStr);
|
||||
} else {
|
||||
hideLoadingScreen();
|
||||
}
|
||||
}
|
||||
|
||||
elements.iframe.addEventListener('load', () => {
|
||||
try {
|
||||
detectIframeNavigation();
|
||||
if (historyStack.length === 0) {
|
||||
addToHistory(elements.iframe.contentWindow.location.href);
|
||||
} else {
|
||||
handleIframeNavigation(elements.iframe.contentWindow.location.href);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error during iframe load handling:', error);
|
||||
} finally {
|
||||
hideLoadingScreen();
|
||||
}
|
||||
try {
|
||||
detectIframeNavigation();
|
||||
if (historyStack.length === 0) {
|
||||
addToHistory(elements.iframe.contentWindow.location.href);
|
||||
} else {
|
||||
handleIframeNavigation(elements.iframe.contentWindow.location.href);
|
||||
}
|
||||
} catch (error) {}
|
||||
hideLoadingScreen();
|
||||
});
|
Loading…
Reference in New Issue
Block a user