From be372c55f3534f86dac4af91a999770adec5655b Mon Sep 17 00:00:00 2001 From: 00Fjongl <65314359+00Fjongl@users.noreply.github.com> Date: Thu, 25 Jul 2024 17:35:18 -0500 Subject: [PATCH] Blacklist functionality incorporated into settings menu --- README.md | 15 ++++-- TODO.md | 5 +- proxyServiceValidator.js | 13 +++-- views/assets/js/register-sw.js | 18 ++++++- views/assets/json/blacklist.json | 1 + views/uv/sw-blacklist.js | 84 ++++++++++++++++++++++++++++++++ views/uv/sw.js | 70 +------------------------- 7 files changed, 125 insertions(+), 81 deletions(-) create mode 100644 views/uv/sw-blacklist.js diff --git a/README.md b/README.md index 19199f8b..6bfbc1a9 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ This will be our nonexhaustive todo list for Holy Unblocker LTS v6.x.x and above - [x] XSS and fingerprinting protection (may need updates) - done - [x] Update games navigation JS and page/change to JSON object system - done - [ ] Ensure all the original submodules get added back to HU-Archive - - [ ] Mobile support + - [x] Mobile support - (welcome screen only, partial/needs work) - [ ] SEO overhaul adapted from the v2 SEO Guide format ## Proxy/Site Functionality @@ -146,15 +146,18 @@ This will be our nonexhaustive todo list for Holy Unblocker LTS v6.x.x and above - [x] Fix Ultraviolet on Firefox - (partial/needs work) - [ ] Adapt Applications page to use either Rammerhead or UV (for Reddit, YouTube, Discord) - [x] libcurl, epoxy and all that fun stuff - done - - [ ] socks5/tor routing option that can be configured (enabled) via either a cookie or pathname as a settings meny option + - [x] socks5/tor routing option that can be configured (enabled) via either a cookie or pathname as a settings meny option - done - [ ] Update games page content - - [ ] Update csel.js (after Setting menu redesign) to support custom transports, icon swap, routing + - [ ] Update settings menu again to make more room for more features + - [x] Update csel.js (after Setting menu redesign) to support custom transports, icon swap, routing - done + - [x] Update csel.js to support network based adblocking (partial/needs work) + - [ ] Update sw.js to support workerware (https://github.com/MercuryWorkshop/workerware) - [ ] Omnibox autoupdate script (for the Google/Bing style auto suggest feature) - [ ] Games library will feature 10000 items; 5000 flash games and 5000 other game types ## Site Redesign - [x] Landing Cards - done - - [ ] Change fonts to cleaner look + - [x] Change fonts to cleaner look - [ ] Add more AOS interactions on scroll or hover - [ ] Add subtle noise to background elements - [ ] Update colors + add themes @@ -196,12 +199,14 @@ This will be our nonexhaustive todo list for Holy Unblocker LTS v6.x.x and above - Improved component handling via templates.mjs along with deletion of obsolete files that previously handled this standard in a poor format - Fixed oddly slow speeds with Ultraviolet (as well as a general version bump to support epoxy-tls and bare-mux) - Implemented testing scripts for an improved GitHub actions workflow by doing a quick test on proxy + site functionality - - Greatly optimized client-side scripts across the site with a new standard + - Greatly optimized client-side scripts across the site with a new standard, and generally reworked to no longer leave global variables - Changes to server.mjs with path logic and error handling - Updated standards for common scripts - libcurl and bare-as-module support added - Deleted 5 JS scripts and moved lots of data into JSON files. Big reorganization. Games menu core scripts now nested inside of common.js utilizing a JSON system - Massive updates to the Settings menu visually and functionality wise; added Bare-Mux support for swapping transports to work with Ultraviolet, default icons and selective adblocking + Tor on any proxy instances + - CSS Has been partially restructured for mobile support, and is now properly arranged into clearly labeled sections (for the most part) + - Incorporated makeshift domain blacklisting functionality into Ultraviolet, currently used for blocking ads if ads are disabled in settings ## Vague Explanation for Beginners With External Proxies and Hosting You will first want to host your proxies locally or externally. OUTDATED diff --git a/TODO.md b/TODO.md index 6d225ff0..0d0ac205 100644 --- a/TODO.md +++ b/TODO.md @@ -24,8 +24,10 @@ This will be our nonexhaustive todo list for Holy Unblocker LTS v6.x.x and above - [x] libcurl, epoxy and all that fun stuff - done - [x] socks5/tor routing option that can be configured (enabled) via either a cookie or pathname as a settings meny option - done - [ ] Update games page content + - [ ] Update settings menu again to make more room for more features - [x] Update csel.js (after Setting menu redesign) to support custom transports, icon swap, routing - done - - [x] Update csel.js to support network based adblocking and workerware (https://github.com/MercuryWorkshop/workerware) + - [x] Update csel.js to support network based adblocking (partial/needs work) + - [ ] Update sw.js to support workerware (https://github.com/MercuryWorkshop/workerware) - [ ] Omnibox autoupdate script (for the Google/Bing style auto suggest feature) - [ ] Games library will feature 10000 items; 5000 flash games and 5000 other game types @@ -80,3 +82,4 @@ This will be our nonexhaustive todo list for Holy Unblocker LTS v6.x.x and above - Deleted 5 JS scripts and moved lots of data into JSON files. Big reorganization. Games menu core scripts now nested inside of common.js utilizing a JSON system - Massive updates to the Settings menu visually and functionality wise; added Bare-Mux support for swapping transports to work with Ultraviolet, default icons and selective adblocking + Tor on any proxy instances - CSS Has been partially restructured for mobile support, and is now properly arranged into clearly labeled sections (for the most part) + - Incorporated makeshift domain blacklisting functionality into Ultraviolet, currently used for blocking ads if ads are disabled in settings \ No newline at end of file diff --git a/proxyServiceValidator.js b/proxyServiceValidator.js index eff55eb1..a49742d5 100644 --- a/proxyServiceValidator.js +++ b/proxyServiceValidator.js @@ -47,10 +47,14 @@ const testServerResponse = async () => { "http://localhost:8080/?fg", "http://localhost:8080/?eg", "http://localhost:8080/?vos", + "http://localhost:8080/assets/js/particlesjs/particles.js", + "http://localhost:8080/assets/js/bareTransport.js", + "http://localhost:8080/assets/js/card.js", "http://localhost:8080/assets/js/common-16451543478.js", "http://localhost:8080/assets/js/csel.js", - "http://localhost:8080/assets/js/particlesjs/particles.js", + "http://localhost:8080/assets/js/register-sw.js", "http://localhost:8080/assets/json/emu-nav.json", + "http://localhost:8080/assets/json/blacklist.json", "http://localhost:8080/assets/json/emulib-nav.json", "http://localhost:8080/assets/json/flash-nav.json", "http://localhost:8080/assets/json/h5-nav.json", @@ -59,11 +63,10 @@ const testServerResponse = async () => { "http://localhost:8080/baremux/worker.js", "http://localhost:8080/epoxy/index.mjs", "http://localhost:8080/uv/uv.bundle.js", - "http://localhost:8080/uv/uv.config.js", - "http://localhost:8080/assets/js/register-sw.js", - "http://localhost:8080/assets/js/card.js", "http://localhost:8080/uv/sw.js", - "http://localhost:8080/uv/uv.config.js" + "http://localhost:8080/uv/uv.config.js", + "http://localhost:8080/uv/workerware.js", + "http://localhost:8080/uv/WWError.js" ]; const results = await Promise.all(endpoints.map(testEndpoint)); diff --git a/views/assets/js/register-sw.js b/views/assets/js/register-sw.js index 8191171b..0e9fbe2a 100644 --- a/views/assets/js/register-sw.js +++ b/views/assets/js/register-sw.js @@ -3,6 +3,7 @@ (() => { const stockSW = "/uv/sw.js", + blacklistSW = "/uv/sw-blacklist.js", swAllowedHostnames = ["localhost", "127.0.0.1"], connection = new BareMux.BareMuxConnection("/baremux/worker.js"), wispUrl = (location.protocol === "https:" ? "wss" : "ws") + "://" + location.host + "/wisp/", @@ -56,7 +57,22 @@ const registerSW = async () => { transportOptions.proxy = proxyUrl; await connection.setTransport(transportMode, [transportOptions]); - await navigator.serviceWorker.register(stockSW); + +// Choose a service worker to register based on whether or not the user +// has ads enabled. If the user changes this setting, this script needs +// to be reloaded for this to update, such as by refreshing the page. + const registrations = await navigator.serviceWorker.getRegistrations(), + usedSW = await readCookie("HBHideAds") !== "false" + ? blacklistSW + : stockSW; + +// Unregister a service worker if it isn't the one being used. + for (const registration of registrations) + if (registration.active && + new URL(registration.active.scriptURL).pathname !== usedSW) + await registration.unregister(); + + await navigator.serviceWorker.register(usedSW); } /* diff --git a/views/assets/json/blacklist.json b/views/assets/json/blacklist.json index 5d7fc3c4..ee6a1cc0 100644 --- a/views/assets/json/blacklist.json +++ b/views/assets/json/blacklist.json @@ -1,4 +1,5 @@ [ + "*.google.com", "*.1-1ads.com", "*.101com.com", "*.101order.com", diff --git a/views/uv/sw-blacklist.js b/views/uv/sw-blacklist.js new file mode 100644 index 00000000..5665602b --- /dev/null +++ b/views/uv/sw-blacklist.js @@ -0,0 +1,84 @@ +importScripts("uv.bundle.js"); +importScripts("uv.config.js"); +importScripts(__uv$config.sw || "uv.sw.js"); + +/* + +Workerware does not work yet due to one of the following possibilities: + +1. UV or the bare client is not updated to support workerware yet. +2. Workerware is unfinished. +3. We are doofuses and do not know how to use workerware properly. + +Going to implement a ghetto domain blacklist for now. + +importScripts("./workerware.js"); + +const ww = new WorkerWare({ + debug: true, + randomNames: true, + timing: true +}); + + +ww.use({ + function: event => console.log(event), + events: ["fetch", "message"] +}); + +*/ + + +const uv = new UVServiceWorker(); + +// Get list of blacklisted domains. +const blacklist = {}; +fetch("/assets/json/blacklist.json").then(request => { + request.json().then(jsonData => { + +// Organize each domain by their tld (top level domain) ending. + jsonData.forEach(domain => { + const domainTld = domain.replace(/.+(?=\.\w)/, ""); + if (!blacklist.hasOwnProperty(domainTld)) + blacklist[domainTld] = []; + +// Store each entry in an array. Each tld has its own array, which will +// later be concatenated into a regular expression. + blacklist[domainTld].push( + encodeURIComponent(domain.slice(0, -domainTld.length)) + .replace(/([()])/g, "\\$1") + .replace(/(\*\.)|\./g, (match, firstExpression) => + firstExpression ? "(?:.+\\.)?" : "\\" + match) + ); + }); + +// Turn each domain list into a regular expression and prevent this +// from being accidentally modified afterward. + for (let [domainTld, domainList] of Object.entries(blacklist)) + blacklist[domainTld] = new RegExp(`^(?:${domainList.join("|")})$`); + Object.freeze(blacklist); + }); +}); + +self.addEventListener("fetch", (event) => { + event.respondWith( + (async () => { + if (uv.route(event)) { +// The one and only ghetto domain blacklist. + const domain = new URL(uv.config.decodeUrl( + new URL(event.request.url).pathname + .replace(uv.config.prefix, "") + )).hostname, + domainTld = domain.replace(/.+(?=\.\w)/, ""); + +// If the domain is in the blacklist, return a 406 response code. + if (blacklist.hasOwnProperty(domainTld) && + blacklist[domainTld].test(domain.slice(0, -domainTld.length))) + return new Response(new Blob(), {status: 406}); + + return await uv.fetch(event); + } + return await fetch(event.request); + })() + ); +}); \ No newline at end of file diff --git a/views/uv/sw.js b/views/uv/sw.js index 0c87aea2..899423e6 100644 --- a/views/uv/sw.js +++ b/views/uv/sw.js @@ -2,82 +2,14 @@ importScripts("uv.bundle.js"); importScripts("uv.config.js"); importScripts(__uv$config.sw || "uv.sw.js"); -/* - -Workerware does not work yet due to one of the following possibilities: - -1. UV or the bare client is not updated to support workerware yet. -2. Workerware is unfinished. -3. We are doofuses and do not know how to use workerware properly. - -Going to implement a ghetto domain blacklist for now. - -importScripts("./workerware.js"); - -const ww = new WorkerWare({ - debug: true, - randomNames: true, - timing: true -}); - - -ww.use({ - function: event => console.log(event), - events: ["fetch", "message"] -}); - -*/ - const uv = new UVServiceWorker(); -// Get list of blacklisted domains. -const blacklist = {}; -fetch("/assets/json/blacklist.json").then(request => { - request.json().then(jsonData => { - -// Organize each domain by their tld (top level domain) ending. - jsonData.forEach(domain => { - const domainTld = domain.replace(/.+(?=\.\w)/, ""); - if (!blacklist.hasOwnProperty(domainTld)) - blacklist[domainTld] = []; - -// Store each entry in an array. Each tld has its own array, which will -// later be concatenated into a regular expression. - blacklist[domainTld].push( - encodeURIComponent(domain.slice(0, -domainTld.length)) - .replace(/([()])/g, "\\$1") - .replace(/(\*\.)|\./g, (match, firstExpression) => - firstExpression ? "(?:.+\\.)?" : "\\" + match) - ); - }); - -// Turn each domain list into a regular expression and prevent this -// from being accidentally modified afterward. - for (let [domainTld, domainList] of Object.entries(blacklist)) - blacklist[domainTld] = new RegExp(`^(?:${domainList.join("|")})$`); - Object.freeze(blacklist); - }); -}); - self.addEventListener("fetch", (event) => { event.respondWith( (async () => { - if (uv.route(event)) { -// The one and only ghetto domain blacklist. - const domain = new URL(uv.config.decodeUrl( - new URL(event.request.url).pathname - .replace(uv.config.prefix, "") - )).hostname, - domainTld = domain.replace(/.+(?=\.\w)/, ""); + if (uv.route(event)) return await uv.fetch(event); -// If the domain is in the blacklist, return a 406 response code. - if (blacklist.hasOwnProperty(domainTld) && - blacklist[domainTld].test(domain.slice(0, -domainTld.length)) - ) return new Response(new Blob(), {status: 406}); - - return await uv.fetch(event); - } return await fetch(event.request); })() );