Skip to content

Commit

Permalink
Intercept __blank target links to open in about:blank, remove Ocean t…
Browse files Browse the repository at this point in the history
…heme
  • Loading branch information
DerpmanDev committed Aug 30, 2024
1 parent ddf3ff5 commit 46f7c3c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 122 deletions.
75 changes: 73 additions & 2 deletions static/assets/js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ const menu = document.getElementById('menu');
const frame = document.getElementById('siteurl');
const selectedTheme = localStorage.getItem('selectedOption');
const vercelCheck = localStorage.getItem('isVercel');
var leaveConf = localStorage.getItem("leaveConfirmation");

if (leaveConf === "enabled") {
// Immediately set up the onbeforeunload handler
window.onbeforeunload = function (e) {
const confirmationMessage = "Are you sure you want to leave this page?";
(e || window.event).returnValue = confirmationMessage; // Required for some browsers
return confirmationMessage; // Required for others
};

// Optional: Slight delay to ensure the handler is recognized by the browser
setTimeout(() => {
// Engage the onbeforeunload event even if there's no user interaction
console.log('onbeforeunload handler engaged after page load.');
}, 500);
}



searchBar.value = Ultraviolet.codec.xor.decode(localStorage.getItem('encodedUrl'));
lucide.createIcons();
Expand All @@ -14,7 +32,6 @@ const themeStyles = {
deepsea: { background: "rgb(6, 22, 35)" },
equinox: { backgroundImage: "url('/assets/img/topographic_splash.webp')" },
swamp: { background: "rgb(12, 43, 22)" },
ocean: { background: "rgb(2, 59, 57)" },
starry: { background: "rgb(63, 3, 53)" },
magma: { background: "rgb(31, 26, 26)" },
sunset: { background: "rgb(29, 21, 27)" },
Expand Down Expand Up @@ -142,7 +159,7 @@ function openWindow() {
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.style.margin = "0";
iframe.src = 'https://' + window.location.hostname + '/service/' + Ultraviolet.codec.xor.encode(document.getElementById('searchBar').value);
iframe.src = 'https://' + window.location.hostname + scope + Ultraviolet.codec.xor.encode(document.getElementById('searchBar').value);
win.document.body.appendChild(iframe);
}

Expand Down Expand Up @@ -237,6 +254,60 @@ function toggleFs() {
menu.style.display = 'none';
}
}

function handleOpen(url) {
const newWindow = window.open('about:blank', '_blank');
if (newWindow) {
newWindow.document.open();
newWindow.document.write(`
<!DOCTYPE html>
<html>
<head>
<title>Genesis Quick Login</title>
<style>
body { margin: 0; height: 100vh; }
iframe { border: none; width: 100%; height: 100%; margin: 0; }
</style>
</head>
<body>
<iframe src="${'https://' + window.location.hostname + '/sv/' + Ultraviolet.codec.xor.encode(url)}" frameborder="0"></iframe>
</body>
</html>
`);
newWindow.document.close();
} else {
console.error('Failed to open Genesis Quick Login!');
}

return null;
}

function interceptFrame() {
if (frame.contentWindow) {
frame.contentWindow.open = function(url, target) {
handleOpen(url);
return null;
};

frame.contentWindow.document.addEventListener('click', event => {
const target = event.target;
if (target.tagName === 'A' && target.getAttribute('target') === '_blank') {
event.preventDefault();
const href = target.getAttribute('href');
if (href) {
window.parent.handleOpen(href);
}
}
});

frame.contentWindow.addEventListener('submit', event => {
event.preventDefault();
});
}
}

frame.addEventListener('load', interceptFrame);

document.addEventListener('DOMContentLoaded', function() {
onFrameClick();
setInterval(onFrameClick, 1000);
Expand Down
118 changes: 3 additions & 115 deletions static/assets/js/particles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,118 +8,7 @@
document.body.insertBefore(particlesDiv, document.body.firstChild);
var selectedTheme = localStorage.getItem("selectedOption");

if (selectedTheme === "ocean") {
particlesJS("particles-js", {
particles: {
number: {
value: 30,
density: {
enable: true,
value_area: 750,
},
},
color: {
value: "#ffffff",
},
shape: {
type: "circle",
stroke: {
width: 0,
color: "#000000",
},
polygon: {
nb_sides: 7,
},
image: {
src: "img/github.svg",
width: 100,
height: 100,
},
},
opacity: {
value: 0.5,
random: false,
anim: {
enable: false,
speed: 1,
opacity_min: 0.1,
sync: false,
},
},
size: {
value: 10,
random: true,
anim: {
enable: false,
speed: 20,
size_min: 0.1,
sync: false,
},
},
line_linked: {
enable: false,
distance: 150,
color: "#ffffff",
opacity: 0.4,
width: 1,
},
move: {
enable: true,
speed: 6,
direction: "top",
random: false,
straight: false,
out_mode: "out",
bounce: false,
attract: {
enable: false,
rotateX: 600,
rotateY: 1200,
},
},
},
interactivity: {
detect_on: "canvas",
events: {
onhover: {
enable: false,
mode: "repulse",
},
onclick: {
enable: true,
mode: "push",
},
resize: true,
},
modes: {
grab: {
distance: 400,
line_linked: {
opacity: 1,
},
},
bubble: {
distance: 400,
size: 40,
duration: 2,
opacity: 8,
speed: 3,
},
repulse: {
distance: 200,
duration: 0.4,
},
push: {
particles_nb: 4,
},
remove: {
particles_nb: 2,
},
},
},
retina_detect: true,
});
} else if (selectedTheme === "starry") {
if (selectedTheme === "starry") {
particlesJS("particles-js", {
particles: {
number: {
Expand Down Expand Up @@ -902,8 +791,8 @@

// Check if Particles are enabled
var particles = localStorage.getItem("particles");
if (particles === "disabled" || particles === null || particles === "") {
console.log("[✔️] Particles");
if (particles === "disabled" || !particles) {
return '';
} else {
particlesJS("particles-js", {
"particles": {
Expand All @@ -919,7 +808,6 @@
},
},
});
console.log("[✔️] Particles");
}
}

Expand Down
14 changes: 13 additions & 1 deletion static/assets/js/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ window.onload = function() {
const swAllowedHostnames = ["localhost", "127.0.0.1"];
const wispUrl = (location.protocol === "https:" ? "wss" : "ws") + "://" + location.host + "/wisp/";
const connection = new BareMux.BareMuxConnection("/baremux/worker.js");
function isMobile() {
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
if (/iPhone|iPad|iPod|android|Mobile|webOS|BlackBerry|IEMobile|Opera Mini/i.test(userAgent)) {
return true;
}
return false;
}

async function registerSW() {
if (!navigator.serviceWorker) {
if (location.protocol !== "https:" && !swAllowedHostnames.includes(location.hostname)) throw new Error("Service workers cannot be registered without https.");
Expand Down Expand Up @@ -31,7 +39,10 @@ window.onload = function() {
const domains = await fetchDomains();
const domainRegex = createDomainRegex(domains);
const searchValue = Ultraviolet.codec.xor.decode(localStorage.getItem("encodedUrl"));
if (vercelCheck !== 'true') {

if (isMobile()) {
scope = '/sv/';
} else if (!vercelCheck) {
if (domainRegex.test(searchValue)) {
scope = '/sv/';
} else {
Expand All @@ -40,6 +51,7 @@ window.onload = function() {
} else {
scope = '/sv/';
}

let encodedUrl = localStorage.getItem("encodedUrl");
encodedUrl = scope + encodedUrl;
document.querySelector("#siteurl").src = encodedUrl;
Expand Down
3 changes: 0 additions & 3 deletions static/assets/js/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ function live() {
case 'swamp':
applyTheme('rgba(22, 46, 23, 0.705)', "linear-gradient(to bottom, rgb(33, 116, 47), rgb(0, 0, 0))");
break;
case 'ocean':
applyTheme('rgba(84, 137, 161, 0.637)', "linear-gradient(to bottom, rgb(70, 173, 214), rgb(99, 84, 36))");
break;
case 'starry':
applyTheme('rgba(39, 81, 109, 0.521)', "linear-gradient(to right, rgb(14, 132, 211), rgb(113, 11, 209))");
break;
Expand Down
1 change: 0 additions & 1 deletion static/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
<option disabled value="placeholder" selected>Select a theme</option>
<option value="deepsea" class="option" style="color:black;">Deep Sea (Default)</option>
<option value="swamp" class="option" style="color:black;">Swamp</option>
<option value="ocean" class="option" style="color:black;">Ocean</option>
<option value="starry" class="option" style="color:black;">Starry</option>
<option value="magma" class="option" style="color:black;">Magma</option>
<option value="sunset" class="option" style="color:black;">Sunset</option>
Expand Down

0 comments on commit 46f7c3c

Please sign in to comment.