forked from sent/waves
❕❕❕❕
This commit is contained in:
parent
b1047929f9
commit
9479504cc9
|
@ -1,331 +1,327 @@
|
|||
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 loadingFallbackTimeout;
|
||||
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;
|
||||
let loadingHidden = false;
|
||||
|
||||
function showLoadingScreen(withToast = true, showEruda = false) {
|
||||
loadingHidden = false;
|
||||
const loadingScreen = document.querySelector(".loading-screen");
|
||||
if (!loadingScreen) return;
|
||||
if (erudaLoadingScreen) {
|
||||
erudaLoadingScreen.style.display = showEruda ? 'block' : 'none';
|
||||
}
|
||||
typeof NProgress !== 'undefined' && NProgress.start();
|
||||
loadingScreen.style.display = 'flex';
|
||||
loadingScreen.style.transition = '';
|
||||
setTimeout(() => {
|
||||
loadingScreen.style.transition = 'opacity 0.3s ease';
|
||||
loadingScreen.style.opacity = 1;
|
||||
}, 10);
|
||||
const loadingText = loadingScreen.querySelector(".loading-text");
|
||||
if (loadingText) {
|
||||
loadingText.innerHTML = "We're getting your content ready, please wait...";
|
||||
}
|
||||
if (withToast) {
|
||||
showToast('Consider joining our <a href="https://discord.gg/dJvdkPRheV" target="_blank" class="hover-link">Discord</a> <3');
|
||||
}
|
||||
loadingFallbackTimeout = setTimeout(() => { hideLoadingScreen(); }, 10000);
|
||||
}
|
||||
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'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function hideLoadingScreen() {
|
||||
if (loadingHidden) return;
|
||||
loadingHidden = true;
|
||||
const loadingScreen = document.querySelector(".loading-screen");
|
||||
if (!loadingScreen) return;
|
||||
typeof NProgress !== 'undefined' && NProgress.done();
|
||||
loadingScreen.style.transition = 'opacity 0.3s ease';
|
||||
loadingScreen.style.opacity = 0;
|
||||
clearTimeout(loadingFallbackTimeout);
|
||||
setTimeout(() => {
|
||||
loadingScreen.style.display = 'none';
|
||||
}, 500);
|
||||
}
|
||||
function hideLoadingScreen() {
|
||||
if (loadingHidden) return;
|
||||
loadingHidden = true;
|
||||
NProgress.done();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
iframe.contentWindow.location.reload(true);
|
||||
}
|
||||
setTimeout(() => { refreshIcon.classList.remove('spin'); }, 300);
|
||||
});
|
||||
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);
|
||||
}
|
||||
iframe.contentWindow.location.reload(true);
|
||||
}
|
||||
setTimeout(() => refreshIcon.classList.remove('spin'), 300);
|
||||
});
|
||||
|
||||
fullscreenIcon.addEventListener('click', () => {
|
||||
if (iframe.tagName === 'IFRAME') {
|
||||
if (iframe.requestFullscreen) iframe.requestFullscreen();
|
||||
else if (iframe.mozRequestFullScreen) iframe.mozRequestFullScreen();
|
||||
else if (iframe.webkitRequestFullscreen) iframe.webkitRequestFullscreen();
|
||||
else if (iframe.msRequestFullscreen) iframe.msRequestFullscreen();
|
||||
}
|
||||
});
|
||||
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();
|
||||
});
|
||||
|
||||
backIcon.addEventListener('click', () => {
|
||||
if (currentIndex > 0) {
|
||||
currentIndex--;
|
||||
iframe.src = historyStack[currentIndex];
|
||||
showLoadingScreen(false, false);
|
||||
updateNavButtons();
|
||||
updateDecodedSearchInput();
|
||||
}
|
||||
});
|
||||
backIcon.addEventListener('click', () => {
|
||||
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();
|
||||
}
|
||||
});
|
||||
forwardIcon.addEventListener('click', () => {
|
||||
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; }
|
||||
}
|
||||
function normalizeUrl(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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
function updateDecodedSearchInput() {
|
||||
const searchInput2 = document.getElementById('searchInputt');
|
||||
let url = "";
|
||||
if (searchInput2) {
|
||||
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 = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
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 = '';
|
||||
}
|
||||
}
|
||||
|
||||
iframe.addEventListener('load', () => {
|
||||
try {
|
||||
hideLoadingScreen();
|
||||
} catch (error) {
|
||||
console.error("Error during iframe load:", error);
|
||||
hideLoadingScreen();
|
||||
} finally {
|
||||
if (erudaLoadingScreen) erudaLoadingScreen.style.display = 'none';
|
||||
}
|
||||
});
|
||||
iframe.addEventListener('load', () => {
|
||||
try {
|
||||
hideLoadingScreen();
|
||||
} catch (error) {
|
||||
console.error('Error during iframe load:', error);
|
||||
hideLoadingScreen();
|
||||
} finally {
|
||||
if (erudaLoadingScreen) erudaLoadingScreen.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
iframe.addEventListener('error', () => {
|
||||
console.error('Error loading iframe content.');
|
||||
hideLoadingScreen();
|
||||
});
|
||||
iframe.addEventListener('error', () => {
|
||||
console.error('Error loading iframe content.');
|
||||
hideLoadingScreen();
|
||||
});
|
||||
|
||||
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");
|
||||
iframe.addEventListener('loadstart', () => {
|
||||
if (navbarToggle && navbarToggle.checked && navBar) {
|
||||
navBar.style.display = 'block';
|
||||
}
|
||||
showLoadingScreen(false, false);
|
||||
});
|
||||
|
||||
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 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');
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
movies && movies.addEventListener("click", (e) => { e.preventDefault(); handleSearch("https://movies.usewaves.site/"); });
|
||||
ai && ai.addEventListener("click", (e) => { e.preventDefault(); handleSearch("https://ai.usewaves.site/"); });
|
||||
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';
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
iframe.style.display = 'none';
|
||||
window.addEventListener('load', hideLoadingScreen);
|
||||
|
||||
async function handleSearch(query) {
|
||||
clearBackground();
|
||||
const searchURL = generateSearchUrl(query);
|
||||
if (searchInput2) {
|
||||
searchInput2.value = searchURL;
|
||||
}
|
||||
preloadResources(searchURL);
|
||||
showLoadingScreen(true, false);
|
||||
iframe.style.display = "block";
|
||||
if (topBar) {
|
||||
topBar.style.display = "none";
|
||||
}
|
||||
backIcon.disabled = true;
|
||||
forwardIcon.disabled = true;
|
||||
try {
|
||||
iframe.src = await getUrl(searchURL);
|
||||
} catch (error) {}
|
||||
historyStack.length = 0;
|
||||
currentIndex = -1;
|
||||
iframe.onload = () => {
|
||||
hideLoadingScreen();
|
||||
if (navbarToggle && navbarToggle.checked && navBar) {
|
||||
navBar.style.display = "block";
|
||||
}
|
||||
generateSubject();
|
||||
updateDecodedSearchInput();
|
||||
try {
|
||||
if (iframe.contentDocument && !iframe.contentDocument.getElementById('uv-postmessage-hook')) {
|
||||
const script = iframe.contentDocument.createElement('script');
|
||||
script.id = 'uv-postmessage-hook';
|
||||
script.textContent = `(function(){
|
||||
const origPush=history.pushState;
|
||||
const origReplace=history.replaceState;
|
||||
function notify(){
|
||||
window.parent.postMessage({type:'uv-url-change',url:location.href},'*');
|
||||
}
|
||||
history.pushState=function(){origPush.apply(history,arguments);notify();};
|
||||
history.replaceState=function(){origReplace.apply(history,arguments);notify();};
|
||||
window.addEventListener('popstate',notify);
|
||||
window.addEventListener('hashchange',notify);
|
||||
notify();
|
||||
})();`;
|
||||
iframe.contentDocument.head.appendChild(script);
|
||||
}
|
||||
} catch (e) {}
|
||||
};
|
||||
iframe.onerror = () => {
|
||||
console.error('Failed to load content.');
|
||||
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/');
|
||||
});
|
||||
|
||||
window.handleSearch = handleSearch;
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
function generateSearchUrl(query) {
|
||||
try {
|
||||
const url = new URL(query);
|
||||
return url.toString();
|
||||
} catch {
|
||||
try {
|
||||
const url = new URL(`https://${query}`);
|
||||
if (url.hostname.includes(".")) return url.toString();
|
||||
} catch {}
|
||||
}
|
||||
return `https://duckduckgo.com/?q=${encodeURIComponent(query)}`;
|
||||
}
|
||||
async function handleSearch(query) {
|
||||
clearBackground();
|
||||
|
||||
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);
|
||||
}
|
||||
let searchURL;
|
||||
if (
|
||||
query.startsWith('/assets/g/') ||
|
||||
query.startsWith(window.location.origin + '/assets/g/')
|
||||
) {
|
||||
searchURL = query;
|
||||
} else {
|
||||
searchURL = generateSearchUrl(query);
|
||||
}
|
||||
|
||||
function preloadResources(url) {
|
||||
const link = document.createElement("link");
|
||||
link.rel = "preload";
|
||||
link.href = url;
|
||||
link.as = "fetch";
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
if (searchInput2) searchInput2.value = searchURL;
|
||||
|
||||
function getUrl(url) {
|
||||
return Promise.resolve(__uv$config.prefix + __uv$config.encodeUrl(url));
|
||||
}
|
||||
historyStack.length = 0;
|
||||
currentIndex = -1;
|
||||
showLoadingScreen(true, false);
|
||||
iframe.style.display = 'block';
|
||||
if (topBar) topBar.style.display = 'none';
|
||||
backIcon.disabled = forwardIcon.disabled = true;
|
||||
|
||||
function generateSubject() {
|
||||
const subjects = ['math', 'science', 'history', 'art', 'programming', 'philosophy'];
|
||||
const randomSubject = subjects[Math.floor(Math.random() * subjects.length)];
|
||||
history.replaceState({}, '', '/learning?subject=' + randomSubject);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
function decodeUrl(encodedUrl) {
|
||||
try {
|
||||
const urlObj = new URL(encodedUrl, window.location.origin);
|
||||
const proxyPrefix = (__uv$config && __uv$config.prefix) ? __uv$config.prefix : '/wa/a/';
|
||||
if (urlObj.pathname.startsWith(proxyPrefix)) {
|
||||
const encodedPart = urlObj.pathname.substring(proxyPrefix.length);
|
||||
return (__uv$config && typeof __uv$config.decodeUrl === 'function') ?
|
||||
__uv$config.decodeUrl(encodedPart) : decodeURIComponent(encodedPart);
|
||||
}
|
||||
} catch (e) {}
|
||||
return encodedUrl;
|
||||
}
|
||||
iframe.src = finalUrl;
|
||||
iframe.onload = () => {
|
||||
hideLoadingScreen();
|
||||
if (navbarToggle && navbarToggle.checked && navBar) navBar.style.display = 'block';
|
||||
generateSubject();
|
||||
updateDecodedSearchInput();
|
||||
};
|
||||
iframe.onerror = () => {
|
||||
console.error('Failed to load content.');
|
||||
hideLoadingScreen();
|
||||
};
|
||||
}
|
||||
|
||||
window.decodeUrl = decodeUrl;
|
||||
window.addEventListener('message', (event) => {
|
||||
if (event.data && event.data.type === 'uv-url-change' && event.data.url) {
|
||||
if (normalizeUrl(event.data.url) !== normalizeUrl(historyStack[currentIndex] || '')) {
|
||||
addToHistory(event.data.url);
|
||||
}
|
||||
}
|
||||
});
|
||||
window.handleSearch = handleSearch;
|
||||
|
||||
window.addToHistory = addToHistory;
|
||||
window.updateDecodedSearchInput = updateDecodedSearchInput;
|
||||
window.normalizeUrl = normalizeUrl;
|
||||
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://search.brave.com/search?q=${encodeURIComponent(query)}`;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function preloadResources(url) {
|
||||
if (!url) {
|
||||
console.error('Preload failed: URL is undefined or empty.');
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
function getUrl(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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
window.decodeUrl = decodeUrl;
|
||||
window.addToHistory = addToHistory;
|
||||
window.updateDecodedSearchInput = updateDecodedSearchInput;
|
||||
window.normalizeUrl = normalizeUrl;
|
||||
});
|
Loading…
Reference in New Issue
Block a user