mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-12 11:30:01 -04:00
chore: remove old code, minor changes
This commit is contained in:
parent
e9aa87d1e2
commit
f139eb63c8
5 changed files with 9 additions and 319 deletions
135
src/express.mjs
135
src/express.mjs
|
@ -1,135 +0,0 @@
|
||||||
import { paintSource, tryReadFile } from './randomization.mjs';
|
|
||||||
import loadTemplates from './templates.mjs';
|
|
||||||
import pkg from './routes.mjs';
|
|
||||||
import { readFile } from 'fs/promises';
|
|
||||||
import path from 'path';
|
|
||||||
import express from 'express';
|
|
||||||
import helmet from 'helmet';
|
|
||||||
import http from 'http';
|
|
||||||
import createRammerhead from 'rammerhead/src/server/index.js';
|
|
||||||
import wisp from 'wisp-server-node';
|
|
||||||
import { epoxyPath } from '@mercuryworkshop/epoxy-transport';
|
|
||||||
import { libcurlPath } from '@mercuryworkshop/libcurl-transport';
|
|
||||||
import { bareModulePath } from '@mercuryworkshop/bare-as-module3';
|
|
||||||
import { baremuxPath } from '@mercuryworkshop/bare-mux/node';
|
|
||||||
import { uvPath } from '@titaniumnetwork-dev/ultraviolet';
|
|
||||||
// import { createBareServer } from "@tomphttp/bare-server-node";
|
|
||||||
|
|
||||||
const config = JSON.parse(
|
|
||||||
await readFile(new URL('../config.json', import.meta.url))
|
|
||||||
),
|
|
||||||
{ pages, text404 } = pkg,
|
|
||||||
__dirname = path.resolve(),
|
|
||||||
port = process.env.PORT || config.port,
|
|
||||||
app = express(),
|
|
||||||
router = express.Router(),
|
|
||||||
// bare = createBareServer("/bare/"),
|
|
||||||
rh = createRammerhead();
|
|
||||||
|
|
||||||
const rammerheadScopes = [
|
|
||||||
'/rammerhead.js',
|
|
||||||
'/hammerhead.js',
|
|
||||||
'/transport-worker.js',
|
|
||||||
'/task.js',
|
|
||||||
'/iframe-task.js',
|
|
||||||
'/worker-hammerhead.js',
|
|
||||||
'/messaging',
|
|
||||||
'/sessionexists',
|
|
||||||
'/deletesession',
|
|
||||||
'/newsession',
|
|
||||||
'/editsession',
|
|
||||||
'/needpassword',
|
|
||||||
'/syncLocalStorage',
|
|
||||||
'/api/shuffleDict',
|
|
||||||
'/mainport',
|
|
||||||
];
|
|
||||||
|
|
||||||
const rammerheadSession = /^\/[a-z0-9]{32}/,
|
|
||||||
shouldRouteRh = (req) => {
|
|
||||||
const url = new URL(req.url, 'http://0.0.0.0');
|
|
||||||
return (
|
|
||||||
rammerheadScopes.includes(url.pathname) ||
|
|
||||||
rammerheadSession.test(url.pathname)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
routeRhRequest = (req, res) => {
|
|
||||||
rh.emit('request', req, res);
|
|
||||||
},
|
|
||||||
routeRhUpgrade = (req, socket, head) => {
|
|
||||||
rh.emit('upgrade', req, socket, head);
|
|
||||||
},
|
|
||||||
server = http.createServer((req, res) => {
|
|
||||||
/*
|
|
||||||
if (bare.shouldRoute(req)) {
|
|
||||||
bare.routeRequest(req, res);
|
|
||||||
} else
|
|
||||||
*/
|
|
||||||
if (shouldRouteRh(req)) {
|
|
||||||
routeRhRequest(req, res);
|
|
||||||
} else {
|
|
||||||
app(req, res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
server.on('upgrade', (req, socket, head) => {
|
|
||||||
/*
|
|
||||||
if (bare.shouldRoute(req)) {
|
|
||||||
bare.routeUpgrade(req, socket, head);
|
|
||||||
} else
|
|
||||||
*/
|
|
||||||
if (shouldRouteRh(req)) {
|
|
||||||
routeRhUpgrade(req, socket, head);
|
|
||||||
} else if (req.url.endsWith('/wisp/')) {
|
|
||||||
wisp.routeRequest(req, socket, head);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Apply Helmet middleware for security.
|
|
||||||
app.use(
|
|
||||||
helmet({
|
|
||||||
contentSecurityPolicy: false, // Disable CSP
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
/* All website files are stored in the /views directory.
|
|
||||||
* This takes one of those files and displays it for a site visitor.
|
|
||||||
* Query strings like /?j are converted into paths like /views/hidden.html
|
|
||||||
* back here. Which query string converts to what is defined in routes.mjs.
|
|
||||||
*/
|
|
||||||
router.get('/', async (req, res) =>
|
|
||||||
res.send(
|
|
||||||
paintSource(
|
|
||||||
loadTemplates(
|
|
||||||
tryReadFile(
|
|
||||||
path.join(
|
|
||||||
__dirname,
|
|
||||||
'views',
|
|
||||||
// Return the error page if the query is not found in
|
|
||||||
// routes.mjs. Also set index as the default page.
|
|
||||||
'/?'.indexOf(req.url)
|
|
||||||
? pages[Object.keys(req.query)[0]] || 'error.html'
|
|
||||||
: pages.index
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
app.use(router);
|
|
||||||
app.use(express.static(path.join(__dirname, 'views')));
|
|
||||||
app.use('/uv/', express.static(uvPath));
|
|
||||||
app.use('/epoxy/', express.static(epoxyPath));
|
|
||||||
app.use('/libcurl/', express.static(libcurlPath));
|
|
||||||
app.use('/bareasmodule/', express.static(bareModulePath));
|
|
||||||
app.use('/baremux/', express.static(baremuxPath));
|
|
||||||
|
|
||||||
app.disable('x-powered-by');
|
|
||||||
|
|
||||||
// Redundant code since 404 is handled elsewhere; left here as insurance.
|
|
||||||
app.use((req, res) => {
|
|
||||||
res.status(404).send(paintSource(loadTemplates(text404)));
|
|
||||||
});
|
|
||||||
|
|
||||||
server.listen(port);
|
|
||||||
console.log('Holy Unblocker is listening on port ' + port + '.');
|
|
|
@ -79,7 +79,7 @@ const config = Object.freeze(
|
||||||
insertCharset(hutaoInsert(versionInsert(insertCooking(cacheBusting(str))))),
|
insertCharset(hutaoInsert(versionInsert(insertCooking(cacheBusting(str))))),
|
||||||
// Use this instead of text404 for a preloaded error page.
|
// Use this instead of text404 for a preloaded error page.
|
||||||
preloaded404 = paintSource(text404),
|
preloaded404 = paintSource(text404),
|
||||||
// Grab the text content of a file. Uses the root directory if no base is supplied.
|
// Grab the text content of a file. Use the root directory if no base is supplied.
|
||||||
tryReadFile = (file, baseUrl = new URL('../', import.meta.url)) => {
|
tryReadFile = (file, baseUrl = new URL('../', import.meta.url)) => {
|
||||||
file = new URL(file, baseUrl);
|
file = new URL(file, baseUrl);
|
||||||
return existsSync(file)
|
return existsSync(file)
|
||||||
|
@ -89,41 +89,3 @@ const config = Object.freeze(
|
||||||
)
|
)
|
||||||
: preloaded404;
|
: preloaded404;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
All of this is now old code.
|
|
||||||
The newer versions of these functions are directly above.
|
|
||||||
|
|
||||||
function randomListItem(lis) {
|
|
||||||
return lis[Math.floor(Math.random() * lis.length)];
|
|
||||||
}
|
|
||||||
|
|
||||||
function insertCharset(str) {
|
|
||||||
return str.replace(/­|​|­|<wbr>/g, function() { return randomListItem(charRandom); });
|
|
||||||
}
|
|
||||||
|
|
||||||
function hutaoInsert(str) {
|
|
||||||
return str.replace(/<!--HUTAOWOA-->/g, function() { return randomListItem(splashRandom); });
|
|
||||||
}
|
|
||||||
|
|
||||||
function insertCooking(str) {
|
|
||||||
return str.replace(/<!-- IMPORTANT-HUCOOKINGINSERT-DONOTDELETE -->/g, function() { return '<span style="display: none;" data-fact="' + randomListItem(vegetables) + '" data-type="' + randomListItem(vegetables) + '">' + randomListItem(cookingInserts) + '</span>'; }); // this needs to be inside a function, so that not every string is the same
|
|
||||||
}
|
|
||||||
|
|
||||||
function cacheBusting(str) {
|
|
||||||
for (var item of Object.entries(cacheBustList)) {
|
|
||||||
str = str.replace(new RegExp(item[0], "g"), item[1]);
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function paintSource(str) {
|
|
||||||
return insertCharset(hutaoInsert(insertCooking(cacheBusting(str))));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function tryReadFile(file) {
|
|
||||||
return existsSync(file) ? readFileSync(file, 'utf8') : text404;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'node:fs';
|
||||||
|
|
||||||
const pages = {
|
const pages = {
|
||||||
// If you are trying to add pages or assets in the root folder and
|
// If you are trying to add pages or assets in the root folder and
|
||||||
|
|
|
@ -61,7 +61,7 @@ const setAuthCookie = (s, lax) => {
|
||||||
|
|
||||||
/* OMNIBOX */
|
/* OMNIBOX */
|
||||||
|
|
||||||
// Search engine is set to Bing. Intended to work just like the usual
|
// Search engine is set to DuckDuckGo. Intended to work just like the usual
|
||||||
// bar at the top of a browser.
|
// bar at the top of a browser.
|
||||||
const sx = 'duckduckgo.com/?q=',
|
const sx = 'duckduckgo.com/?q=',
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -240,140 +240,3 @@ if (document.getElementById('csel')) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/* -----------------------------------------------
|
|
||||||
/* Original code written by OlyB
|
|
||||||
/* -----------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
let date = new Date();
|
|
||||||
date.setFullYear(date.getFullYear() + 100);
|
|
||||||
date = date.toUTCString();
|
|
||||||
|
|
||||||
let csel = document.getElementById("csel");
|
|
||||||
|
|
||||||
function setCookie(name, value) {
|
|
||||||
document.cookie = name + "=" + encodeURIComponent(value) + "; expires=" + date + "; ";
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeCookie(name) {
|
|
||||||
document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:01 GMT; ";
|
|
||||||
}
|
|
||||||
|
|
||||||
async function readCookie(name) {
|
|
||||||
let cookie = document.cookie.split("; ");
|
|
||||||
let cookies = {};
|
|
||||||
for (let i = 0; i < cookie.length; i++) {
|
|
||||||
let p = cookie[i].split("=");
|
|
||||||
cookies[p[0]] = p[1];
|
|
||||||
}
|
|
||||||
return decodeURIComponent(cookies[name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function pageTitle(value) {
|
|
||||||
let tag = document.getElementsByTagName("title")[0] || document.createElement("title");
|
|
||||||
tag.innerHTML = value;
|
|
||||||
document.head.appendChild(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
function pageIcon(value) {
|
|
||||||
let tag = document.querySelector("link[rel*='icon']") || document.createElement("link");
|
|
||||||
tag.rel = "icon";
|
|
||||||
tag.href = value;
|
|
||||||
document.head.appendChild(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setTitle(value) {
|
|
||||||
pageTitle(value);
|
|
||||||
setCookie("HBTitle", value);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setIcon(value) {
|
|
||||||
pageIcon(value);
|
|
||||||
setCookie("HBIcon", value);
|
|
||||||
}
|
|
||||||
|
|
||||||
function pageHideAds() {
|
|
||||||
document.querySelectorAll(".ad").forEach(n => n.style.display = "none");
|
|
||||||
}
|
|
||||||
|
|
||||||
function pageShowAds() {
|
|
||||||
document.querySelectorAll(".ad").forEach(n => n.style.display = "block");
|
|
||||||
}
|
|
||||||
|
|
||||||
function hideAds() {
|
|
||||||
pageHideAds();
|
|
||||||
setCookie("HBHideAds", "true");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ghetto Default Disable Ads
|
|
||||||
setCookie("HBHideAds", "true");
|
|
||||||
|
|
||||||
function showAds() {
|
|
||||||
pageShowAds();
|
|
||||||
removeCookie("HBHideAds");
|
|
||||||
}
|
|
||||||
|
|
||||||
readCookie("HBTitle").then(s => (s != "undefined") && pageTitle(s));
|
|
||||||
readCookie("HBIcon").then(s => (s != "undefined") && pageIcon(s));
|
|
||||||
|
|
||||||
readCookie("HBHideAds").then(s => (s != "undefined") && (function() { pageHideAds(); (document.getElementById("hideads") || {}).checked = "true"; })());
|
|
||||||
|
|
||||||
if (csel) {
|
|
||||||
csel.innerHTML =
|
|
||||||
decodeURIComponent(atob("JTNDcCUyMGNsYXNzJTNEJTIyY3NlbHRpdGxlJTIyJTNFVGFiJTIwQ2xvYWslM0MlMkZwJTN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CUyMmJ1dHRvbiUyMiUyMHZhbHVlJTNEJTIyUmVzZXQlMjIlM0UlMEElM0NpbnB1dCUyMGlkJTNEJTIyY3NlbGFiJTIyJTIwY2xhc3MlM0QlMjJjc2VsYnV0dG9uJTIyJTIwdHlwZSUzRCUyMmJ1dHRvbiUyMiUyMHZhbHVlJTNEJTIyYWJvdXQlM0FibGFuayUyMiUzRSUwQSUzQ3AlMjBjbGFzcyUzRCUyMmNzZWxsYWJlbCUyMiUzRSUwQSUyMCUyMCUyMCUyMCUzQ2lucHV0JTIwaWQlM0QlMjJoaWRlYWRzJTIyJTIwdHlwZSUzRCUyMmNoZWNrYm94JTIyJTNFJTBBJTIwJTIwJTIwJTIwJTNDc3BhbiUzRUhpZGUlMjBBZHMlM0MlMkZzcGFuJTNFJTBBJTNDJTJGcCUzRSUwQSUzQ3AlM0VBZHMlMjBoZWxwJTIwc3VwcG9ydCUyMEglMjYlMjMxNzMlM0JvJTI2JTIzMTczJTNCbHklMjBVJTI2JTIzMTczJTNCbmIlMjYlMjMxNzMlM0Jsb2NrJTI2JTIzMTczJTNCZXIhJTNDJTJGcCUzRQ=="));
|
|
||||||
document.getElementById("titleform").addEventListener("submit", function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
if (this.firstElementChild.value) {
|
|
||||||
setTitle(this.firstElementChild.value);
|
|
||||||
this.firstElementChild.value = "";
|
|
||||||
} else {
|
|
||||||
alert("Please provide a title.");
|
|
||||||
}
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
document.getElementById("iconform").addEventListener("submit", function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
if (this.firstElementChild.value) {
|
|
||||||
setIcon(this.firstElementChild.value);
|
|
||||||
this.firstElementChild.value = "";
|
|
||||||
} else {
|
|
||||||
alert("Please provide an icon URL.");
|
|
||||||
}
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
document.getElementById("cselreset").addEventListener("click", function() {
|
|
||||||
if (confirm("Reset the title and icon to default?")) {
|
|
||||||
removeCookie("HBTitle");
|
|
||||||
removeCookie("HBIcon");
|
|
||||||
pageTitle("H­o­ly Un­blo­ck­er");
|
|
||||||
pageIcon("assets/img/icon.png");
|
|
||||||
}
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
document.getElementById("cselab").addEventListener("click", function () {
|
|
||||||
var win = window.open()
|
|
||||||
var url = `${window.location.href}`
|
|
||||||
var iframe = win.document.createElement('iframe')
|
|
||||||
iframe.style.width = "100%";
|
|
||||||
iframe.style.height = "100%";
|
|
||||||
iframe.style.border = "none";
|
|
||||||
iframe.style.overflow = "hidden";
|
|
||||||
iframe.style.margin = "0";
|
|
||||||
iframe.style.padding = "0";
|
|
||||||
iframe.style.position = "fixed";
|
|
||||||
iframe.style.top = "0";
|
|
||||||
iframe.style.bottom = "0";
|
|
||||||
iframe.style.left = "0";
|
|
||||||
iframe.style.right = "0";
|
|
||||||
iframe.src = url;
|
|
||||||
win.document.body.appendChild(iframe)
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById("hideads").addEventListener("change", function(e) {
|
|
||||||
e.target.checked ? hideAds() : showAds();
|
|
||||||
}, false);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
*/
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue