Skip to content

Commit

Permalink
Implemented the rest of the functionality for the settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
00Fjongl committed Jul 20, 2024
1 parent 3c4c0e9 commit 7bc777c
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 46 deletions.
13 changes: 8 additions & 5 deletions views/assets/css/styles-1644738239.css
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ details[open] summary {
position: relative;
}

.brand-logo-container {
.brand-logo-container, .new {
display: flex;
align-items: center; /* Align items vertically */
}
Expand Down Expand Up @@ -497,8 +497,8 @@ details[open] summary {
}

.navbar-1 {
justify-content: flex-start; /* Align navbar-1 to the left on smaller screens */
flex: 0 0 100%; /* Force navbar-1 to be on a new row */
justify-content: flex-end; /* Align navbar-1 to the right on larger screens */
flex-grow: 1; /* Allow navbar-1 to take up remaining space */
}

.navbar-1 > li {
Expand Down Expand Up @@ -651,10 +651,13 @@ details[open] summary {
#header {
height: auto;
}
.navbar-1 {
justify-content: flex-start; /* Align navbar-1 to the left on smaller screens */
flex: 0 0 100%; /* Force navbar-1 to be on a new row */
}
.navbar {
display: none;
margin: 0px;
width: 100%;
height: auto;
}
.navbar > li {
Expand Down Expand Up @@ -986,7 +989,7 @@ details[open] summary {
text-decoration: underline;
}

#csel #hideads {
#hideads, #useonion {
cursor: pointer;
margin-left: 0px;
}
Expand Down
8 changes: 3 additions & 5 deletions views/assets/js/common-16451543478.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ const RammerheadEncode = async baseUrl => {
* goProx.searx();
*/
addEventListener("DOMContentLoaded", () => {
self.goProx = {
// Object.freeze prevents goProx from being edited.
self.goProx = Object.freeze({
// `location.protocol + "//" + getDomain()` more like `location.origin`
// setAuthCookie("__cor_auth=1", false);
ultraviolet: urlHandler(uvUrl),
Expand Down Expand Up @@ -395,10 +396,7 @@ addEventListener("DOMContentLoaded", () => {
speed: urlHandler(uvUrl("https://captain4lk.itch.io/what-the-road-brings")),

heli: urlHandler(uvUrl("https://benjames171.itch.io/helo-storm"))
};

// Prevent goProx from being edited.
Object.freeze(goProx);
});
});

(async () => {
Expand Down
112 changes: 92 additions & 20 deletions views/assets/js/csel.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,80 +54,152 @@ pageShowAds = () => {
// Remove the stylesheet made by the function above, if it exists.
pageHideAds = () => {
(document.getElementById("advertising")||new Text()).remove();
};
},

// These titles and icons are used as autofill templates by settings.html.
// The icon URLs and tab titles may need to be updated over time.
presetIcons = Object.freeze({
"": " \n ",
"Google": "Google \n https://www.google.com/favicon.ico",
"Bing": "Bing \n https://www.bing.com/sa/simg/favicon-trans-bg-blue-mg-28.ico",
"Google Drive": "Home - Google Drive \n https://ssl.gstatic.com/images/branding/product/2x/drive_2020q4_48dp.png",
"Gmail": "Inbox - Gmail \n https://ssl.gstatic.com/ui/v1/icons/mail/rfr/gmail.ico"
});


// Load a custom page title and favicon if it was previously stored.
readCookie("HBTitle").then(s => (s != undefined) && pageTitle(s));
readCookie("HBIcon").then(s => (s != undefined) && pageIcon(s));
readCookie("HBTitle").then(s => {(s != undefined) && pageTitle(s)});
readCookie("HBIcon").then(s => {(s != undefined) && pageIcon(s)});

// Load the UV transport mode that was last used, or use the default.
readCookie("HBTransport").then(s => {
let list = document.getElementById("transport-list");
if (list != undefined && list.options.length)
list.selectedIndex =
([...list.options].findIndex(e => e.value === s) + 1 || 1) - 1;
});

// Ads are disabled by default. Load ads if ads were enabled previously.
readCookie("HBHideAds").then(s => (s != "false") ? pageHideAds() : pageShowAds((document.getElementById("hideads") || {}).checked = 0));
readCookie("HBHideAds").then(s => {(s !== "false") ? pageHideAds() : pageShowAds((document.getElementById("hideads") || {}).checked = 0)});

// Tor is disabled by default. Enable Tor if it was enabled previously.
readCookie("HBUseOnion").then(s => {if (s === "true") {
let torCheck = document.getElementById("useonion") ||
{dispatchEvent: () => {}};
torCheck.checked = 1;
torCheck.dispatchEvent(new Event("change"));
}});


// All code below is used by the Settings UI in the navigation bar.
if (document.getElementById("csel")) {
const attachEventListener = (selector, ...args) => (
document.getElementById(selector) ||
document.querySelector(selector)
).addEventListener(...args);

let closeBtn = document.querySelector(".dropdown-settings .close-settings-btn");
closeBtn.addEventListener("click", () => {document.activeElement.blur()});
attachEventListener(".dropdown-settings .close-settings-btn", "click",
() => {document.activeElement.blur()}
);

// Allow users to set a custom title with the UI.
let titleform = document.getElementById("titleform");
titleform.addEventListener("submit", e => {
attachEventListener("titleform", "submit", e => {
e.preventDefault();
e = titleform.firstElementChild;
e = e.target.firstElementChild;
if (e.value) {
pageTitle(e.value);
setCookie("HBTitle", e.value);
e.value = "";
} else {
alert("Please provide a title.");
}
}, false);
});

// Allow users to set a custom favicon with the UI.
let iconform = document.getElementById("iconform");
iconform.addEventListener("submit", e => {
attachEventListener("iconform", "submit", e => {
e.preventDefault();
e = iconform.firstElementChild;
e = e.target.firstElementChild;
if (e.value) {
pageIcon(e.value);
setCookie("HBIcon", e.value);
e.value = "";
} else {
alert("Please provide an icon URL.");
}
}, false);
});

// Allow users to reset the title and favicon to default with the UI.
document.getElementById("cselreset").addEventListener("click", () => {
attachEventListener("cselreset", "click", () => {
if (confirm("Reset the title and icon to default?")) {
removeCookie("HBTitle");
removeCookie("HBIcon");
pageTitle("Holy Unblocker");
pageIcon("assets/img/icon.png");
}
}, false);
});

// Allow users to make a new about:blank tab and view the site from there.
// An iframe of the current page is inserted into the new tab.
document.getElementById("cselab").addEventListener("click", () => {
attachEventListener("cselab", "click", () => {
let win = window.open();
let iframe = win.document.createElement("iframe");
iframe.style = "width: 100%; height: 100%; border: none; overflow: hidden; margin: 0; padding: 0; position: fixed; top: 0; left: 0";
iframe.src = location.href;
win.document.body.appendChild(iframe);
});

// Allow users to enable or disable ads with the UI.
document.getElementById("hideads").addEventListener("change", e => {
// Provides users with a handy set of title and icon autofill options.
attachEventListener("icon-list", "change", e => {
let titleform = document.getElementById("titleform"),
iconform = document.getElementById("iconform");
[titleform.firstElementChild.value,
iconform.firstElementChild.value] =
(presetIcons[e.target.value] || " \n ").split(" \n ");
});

// Allow users to change the UV transport mode, for proxying, with the UI.
attachEventListener("transport-list", "change", e => {
e.target.selectedIndex < 1
? removeCookie("HBTransport")
: setCookie("HBTransport", e.target.value);

// Only the libcurl transport mode supports Tor at the moment.
let torCheck = document.getElementById("useonion");
if(e.target.value !== "libcurl" && torCheck.checked)
torCheck.click();
});

// Allow users to toggle ads with the UI.
attachEventListener("hideads", "change", e => {
if (e.target.checked) {
pageHideAds();
setCookie("HBHideAds", "true");
} else {
pageShowAds();
setCookie("HBHideAds", "false");
}
}, false);
});

// Allow users to toggle onion routing in Ultraviolet with the UI. Only
// the libcurl transport mode supports Tor at the moment, so ensure that
// users are aware that they cannot use Tor with other modes.
attachEventListener("useonion", "change", e => {
let list = document.getElementById("transport-list");
let options = [...list.options];
if (e.target.checked) {
list.selectedIndex =
(options.findIndex(e => e.value === "libcurl") + 1
|| 1) - 1;
options.splice(list.selectedIndex, 1);
options.forEach(e => {e.setAttribute("disabled", "true")});
list.dispatchEvent(new Event("change"));
setCookie("HBUseOnion", "true");
} else {
options.splice(list.selectedIndex, 1);
options.forEach(e => {e.removeAttribute("disabled")});
setCookie("HBUseOnion", "false");
}
});
}


Expand Down
48 changes: 39 additions & 9 deletions views/assets/js/register-sw.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
const stockSW = "/uv/sw.js";
const swAllowedHostnames = ["localhost", "127.0.0.1"];
const connection = new BareMux.BareMuxConnection("/baremux/worker.js");
const wispUrl = (location.protocol === "https:" ? "wss" : "ws") + "://" + location.host + "/wisp/";
const stockSW = "/uv/sw.js",
swAllowedHostnames = ["localhost", "127.0.0.1"],
connection = new BareMux.BareMuxConnection("/baremux/worker.js"),
wispUrl = (location.protocol === "https:" ? "wss" : "ws") + "://" + location.host + "/wisp/",

// Proxy configuration
const proxyUrl = "socks5h://localhost:9050"; // Replace with your proxy URL
// Proxy configuration
proxyUrl = "socks5h://localhost:9050", // Replace with your proxy URL
transports = {
epoxy: "/epoxy/index.mjs",
libcurl: "/libcurl/index.mjs",
bare: "/baremux/index.mjs"
};

// Set epoxy as the default transport mode.
transports.default = transports.epoxy;
// Prevent the transports object from being edited.
Object.freeze(transports);

async function registerSW() {
if (!navigator.serviceWorker) {
Expand All @@ -17,20 +27,40 @@ async function registerSW() {
throw new Error("Your browser doesn't support service workers.");
}

// Update the transport setup to include the proxy option
await connection.setTransport("/libcurl/index.mjs", [{ wisp: wispUrl /* proxy: proxyUrl */ }]);

let transportMode = transports.default,
transportOptions = { wisp: wispUrl };
try {
// If the user has changed the transport mode, use that over the default.
transportMode = transports[await readCookie("HBTransport")] ||
transports.default;

// Only use Tor with the proxy if the user has enabled it in settings.
if (await readCookie("HBUseOnion") === "true")
transportOptions.proxy = proxyUrl;

// Errors here are likely caused by this script failing to access csel.js.
} catch (e) {console.log(e)}

await connection.setTransport(transportMode, [transportOptions]);
await navigator.serviceWorker.register(stockSW);
}

/*
Commented out upon discovering that a duplicate BareMux connection may be
unnecessary; previously thought to have prevented issues with refreshing.
async function setupTransportOnLoad() {
const conn = new BareMux.BareMuxConnection("/baremux/worker.js");
if (await conn.getTransport() !== "/baremux/module.js") {
await conn.setTransport("/libcurl/index.mjs", [{ wisp: wispUrl /* proxy: proxyUrl */ }]);
await conn.setTransport("/libcurl/index.mjs", [{ wisp: wispUrl, proxy: proxyUrl }]);
}
}
// Run transport setup on page load
setupTransportOnLoad();
*/

// Register service worker
registerSW();
2 changes: 1 addition & 1 deletion views/pages/misc/deobf/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<li class="pulse" style="margin-left: 0; "><a href="/?browse">Web Proxies</a></li>
<li class="pulse"><a href="/?g">Games</a></li>
<li class="pulse"><a href="/?y">YouTube</a></li>
<li class="brand-logo-container pulse new">
<li class="pulse new">
<a href="/?apps">Applications</a>
</li>
</ul>
Expand Down
12 changes: 6 additions & 6 deletions views/pages/misc/deobf/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@
<p class=cseltitle>Browser Tab Config</p>
<p class=csellabel>Change the universal tab title:</p>
<form class=cselform id=titleform>
<input type=text placeholder=Tab Title spellcheck=false><input class="cselbutton cselmargin" type=submit value=Apply>
<input type=text placeholder="Tab Title" spellcheck=false><input class="cselbutton cselmargin" type=submit value=Apply>
</form>
<p class=csellabel>Change the universal tab <a href=/?i>icon</a>:</p>
<form class=cselform id=iconform>
<input type=text placeholder=Icon URL spellcheck=false><input class="cselbutton cselmargin" type=submit value=Apply>
<input type=text placeholder="Icon URL" spellcheck=false><input class="cselbutton cselmargin" type=submit value=Apply>
</form>
<input id=cselreset class="cselbutton" type=button value=Reset>
<input id=cselab class="cselbutton" type=button value="Open Stealth Frame">
<p class=csellabel>Icon Presets:</p>
<select>
<select id=icon-list>
<option></option>
<option>Google</option>
<option>Bing</option>
<option>Google Drive</option>
<option>Gmail</option>
</select>
<p class=csellabel>Default Ultraviolet Transport:</p>
<select>
<select id=transport-list>
<option>epoxy</option>
<option>libcurl</option>
<option>bare</option>
<option>other</option>
</select>
<p class=csellabel>Network Options:</p>
<p class=csellabel>
<input id=hideads type=checkbox checked>
<span>Hide Ads</span>
</p>
<p class=csellabel>
<input id=hideads type=checkbox checked>
<input id=useonion type=checkbox>
<span>Enable Tor</span>
</p>
<p><br>Holy Unblocker LTS v6.3.x</p>
Expand Down

0 comments on commit 7bc777c

Please sign in to comment.