@indextools/index-games 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -2
- package/index.svg +53 -0
- package/package.json +47 -5
- package/public/404.html +50 -0
- package/public/baremux/worker.js +2 -0
- package/public/config.js +27 -0
- package/public/games/agesofconflict.html +224 -0
- package/public/games/baldi.html +50 -0
- package/public/games/boi.html +132 -0
- package/public/games/brotato.html +142 -0
- package/public/games/fnae.html +153 -0
- package/public/games/games.json +122 -0
- package/public/games/gamesuggestion.html +12 -0
- package/public/games/geodash.html +274 -0
- package/public/games/kidchess.html +49 -0
- package/public/games/lebronclicker.html +763 -0
- package/public/games/monstertracks.html +31 -0
- package/public/games/nealfun.html +49 -0
- package/public/games/slitherio.html +186 -0
- package/public/games/slope.html +114 -0
- package/public/games/spacewaves.html +246 -0
- package/public/games/wheeliebike.html +50 -0
- package/public/icons/BNG-Favicon.png +0 -0
- package/public/icons/CGPT-Favicon.png +0 -0
- package/public/icons/CMG-Favicon.jpg +0 -0
- package/public/icons/CZG-Favicon.png +0 -0
- package/public/icons/DC-Favicon.png +0 -0
- package/public/icons/DDG-Favicon.png +0 -0
- package/public/icons/G-Favicon.png +0 -0
- package/public/icons/GH-Favicon.png +0 -0
- package/public/icons/GameSuggestions-Favicons.png +0 -0
- package/public/icons/MCTF-Favicon.png +0 -0
- package/public/icons/MP4-Favicon.webp +0 -0
- package/public/icons/NDF-Favicon.png +0 -0
- package/public/icons/NGG-Favicon.png +0 -0
- package/public/icons/RDT-Favicon.png +0 -0
- package/public/icons/RPT-Favicon.png +0 -0
- package/public/icons/S-Favicon.png +0 -0
- package/public/icons/TT-Favicon.png +0 -0
- package/public/icons/X-Favicon.jpg +0 -0
- package/public/icons/YT-Favicon.png +0 -0
- package/public/index.css +888 -0
- package/public/index.html +1132 -0
- package/public/index.js +72 -0
- package/public/index.svg +53 -0
- package/public/register-sw.js +25 -0
- package/public/search.js +32 -0
- package/public/sw.js +16 -0
- package/server.js +46 -0
- package/src/index.js +96 -0
package/public/index.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @type {HTMLFormElement}
|
|
4
|
+
*/
|
|
5
|
+
const form = document.getElementById("sj-form");
|
|
6
|
+
/**
|
|
7
|
+
* @type {HTMLInputElement}
|
|
8
|
+
*/
|
|
9
|
+
const address = document.getElementById("sj-address");
|
|
10
|
+
/**
|
|
11
|
+
* @type {HTMLInputElement}
|
|
12
|
+
*/
|
|
13
|
+
const searchEngine = document.getElementById("sj-search-engine");
|
|
14
|
+
/**
|
|
15
|
+
* @type {HTMLParagraphElement}
|
|
16
|
+
*/
|
|
17
|
+
const error = document.getElementById("sj-error");
|
|
18
|
+
/**
|
|
19
|
+
* @type {HTMLPreElement}
|
|
20
|
+
*/
|
|
21
|
+
const errorCode = document.getElementById("sj-error-code");
|
|
22
|
+
|
|
23
|
+
const cfg = (typeof window !== "undefined" && window.__INDEX_CONFIG) || {};
|
|
24
|
+
const scramjetFiles = cfg.scramjet || {
|
|
25
|
+
wasm: "https://unpkg.com/@mercuryworkshop/scramjet@2.0.0-alpha/dist/scramjet.wasm.wasm",
|
|
26
|
+
all: "https://unpkg.com/@mercuryworkshop/scramjet@2.0.0-alpha/dist/scramjet.all.js",
|
|
27
|
+
sync: "https://unpkg.com/@mercuryworkshop/scramjet@2.0.0-alpha/dist/scramjet.sync.js",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const { ScramjetController } = $scramjetLoadController();
|
|
31
|
+
|
|
32
|
+
const scramjet = new ScramjetController({
|
|
33
|
+
files: scramjetFiles,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
scramjet.init();
|
|
37
|
+
|
|
38
|
+
const workerPath = (cfg.baremux && cfg.baremux.worker) || "/baremux/worker.js";
|
|
39
|
+
const connection = new BareMux.BareMuxConnection(workerPath);
|
|
40
|
+
|
|
41
|
+
form.addEventListener("submit", async (event) => {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
await registerSW();
|
|
46
|
+
} catch (err) {
|
|
47
|
+
error.textContent = "Failed to register service worker.";
|
|
48
|
+
errorCode.textContent = err.toString();
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const url = search(address.value, searchEngine.value);
|
|
53
|
+
|
|
54
|
+
let wispUrl =
|
|
55
|
+
cfg.wispUrl ||
|
|
56
|
+
(location.host && location.host.includes("unpkg.com")
|
|
57
|
+
? "wss://wisp.mercurywork.shop/"
|
|
58
|
+
: (location.protocol === "https:" ? "wss" : "ws") +
|
|
59
|
+
"://" +
|
|
60
|
+
location.host +
|
|
61
|
+
"/wisp/");
|
|
62
|
+
const transportUrl = (cfg.libcurl && cfg.libcurl.transport) || "https://unpkg.com/@mercuryworkshop/libcurl-transport@1.5.2/dist/index.mjs";
|
|
63
|
+
if ((await connection.getTransport()) !== transportUrl) {
|
|
64
|
+
await connection.setTransport(transportUrl, [
|
|
65
|
+
{ websocket: wispUrl },
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
const frame = scramjet.createFrame();
|
|
69
|
+
frame.frame.id = "sj-frame";
|
|
70
|
+
document.body.appendChild(frame.frame);
|
|
71
|
+
frame.go(url);
|
|
72
|
+
});
|
package/public/index.svg
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 100 100">
|
|
3
|
+
<foreignObject width="100%" height="100%">
|
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" style="width:100%; height:100%; margin:0; padding:0;">
|
|
5
|
+
<head>
|
|
6
|
+
<title>Index</title>
|
|
7
|
+
<style>
|
|
8
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
9
|
+
html, body { width: 100%; height: 100%; overflow: hidden; background: #0b0c10; }
|
|
10
|
+
iframe { width: 100vw; height: 100vh; border: none; display: block; position: fixed; inset: 0; }
|
|
11
|
+
.fallback-link {
|
|
12
|
+
position: fixed;
|
|
13
|
+
top: 10px;
|
|
14
|
+
right: 10px;
|
|
15
|
+
z-index: 99999;
|
|
16
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
17
|
+
font-size: 13px;
|
|
18
|
+
color: #45f3ff;
|
|
19
|
+
background: rgba(11, 12, 16, 0.9);
|
|
20
|
+
border: 1px solid #45f3ff;
|
|
21
|
+
padding: 6px 14px;
|
|
22
|
+
border-radius: 6px;
|
|
23
|
+
text-decoration: none;
|
|
24
|
+
backdrop-filter: blur(4px);
|
|
25
|
+
}
|
|
26
|
+
</style>
|
|
27
|
+
</head>
|
|
28
|
+
<body>
|
|
29
|
+
<a id="index-link" class="fallback-link" href="index.html" target="_top">Launch Index</a>
|
|
30
|
+
<iframe id="index-frame" src="index.html" allowfullscreen="true" sandbox="allow-scripts allow-same-origin allow-forms allow-modals allow-downloads"></iframe>
|
|
31
|
+
</body>
|
|
32
|
+
</html>
|
|
33
|
+
</foreignObject>
|
|
34
|
+
<script type="text/javascript">
|
|
35
|
+
<![CDATA[
|
|
36
|
+
(function() {
|
|
37
|
+
try {
|
|
38
|
+
var frame = document.getElementById("index-frame");
|
|
39
|
+
var link = document.getElementById("index-link");
|
|
40
|
+
var path = (typeof window !== "undefined" && window.location && window.location.pathname) || "";
|
|
41
|
+
var target = "index.html";
|
|
42
|
+
if (path && !path.includes("/public/") && !path.endsWith("/public")) {
|
|
43
|
+
target = "public/index.html";
|
|
44
|
+
}
|
|
45
|
+
if (frame && !frame.getAttribute("src")) frame.src = target;
|
|
46
|
+
if (link) link.href = target;
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error(e);
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
]]>
|
|
52
|
+
</script>
|
|
53
|
+
</svg>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const stockSW = "./sw.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* List of hostnames that are allowed to run serviceworkers on http://
|
|
6
|
+
*/
|
|
7
|
+
const swAllowedHostnames = ["localhost", "127.0.0.1"];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Global util
|
|
11
|
+
* Used in 404.html and index.html
|
|
12
|
+
*/
|
|
13
|
+
async function registerSW() {
|
|
14
|
+
if (!navigator.serviceWorker) {
|
|
15
|
+
if (
|
|
16
|
+
location.protocol !== "https:" &&
|
|
17
|
+
!swAllowedHostnames.includes(location.hostname)
|
|
18
|
+
)
|
|
19
|
+
throw new Error("Service workers cannot be registered without https.");
|
|
20
|
+
|
|
21
|
+
throw new Error("Your browser doesn't support service workers.");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
await navigator.serviceWorker.register(stockSW);
|
|
25
|
+
}
|
package/public/search.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {string} input
|
|
5
|
+
* @param {string} template Template for a search query.
|
|
6
|
+
* @returns {string} Fully qualified URL
|
|
7
|
+
*/
|
|
8
|
+
function search(input, template) {
|
|
9
|
+
try {
|
|
10
|
+
// input is a valid URL:
|
|
11
|
+
// eg: https://example.com, https://example.com/test?q=param
|
|
12
|
+
return new URL(input).toString();
|
|
13
|
+
} catch (err) {
|
|
14
|
+
// input was not a valid URL
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// input is a valid URL when http:// is added to the start:
|
|
19
|
+
// eg: example.com, https://example.com/test?q=param
|
|
20
|
+
const url = new URL(`http://${input}`);
|
|
21
|
+
// only if the hostname has a TLD/subdomain
|
|
22
|
+
if (url.hostname.includes(".")) return url.toString();
|
|
23
|
+
} catch (err) {
|
|
24
|
+
// input was not valid URL
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// input may have been a valid URL, however the hostname was invalid
|
|
28
|
+
|
|
29
|
+
// Attempts to convert the input to a fully qualified URL have failed
|
|
30
|
+
// Treat the input as a search query
|
|
31
|
+
return template.replace("%s", encodeURIComponent(input));
|
|
32
|
+
}
|
package/public/sw.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
importScripts("https://unpkg.com/@mercuryworkshop/scramjet@2.0.0-alpha/dist/scramjet.all.js");
|
|
2
|
+
|
|
3
|
+
const { ScramjetServiceWorker } = $scramjetLoadWorker();
|
|
4
|
+
const scramjet = new ScramjetServiceWorker();
|
|
5
|
+
|
|
6
|
+
async function handleRequest(event) {
|
|
7
|
+
await scramjet.loadConfig();
|
|
8
|
+
if (scramjet.route(event)) {
|
|
9
|
+
return scramjet.fetch(event);
|
|
10
|
+
}
|
|
11
|
+
return fetch(event.request);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
self.addEventListener("fetch", (event) => {
|
|
15
|
+
event.respondWith(handleRequest(event));
|
|
16
|
+
});
|
package/server.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Fastify from "fastify";
|
|
2
|
+
import staticPlugin from "@fastify/static";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { createServer } from "http";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { BareServer } from "@tomphttp/bare-server-node";
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
|
|
10
|
+
const fastify = Fastify();
|
|
11
|
+
const bareServer = new BareServer("/bare/");
|
|
12
|
+
|
|
13
|
+
// Serve Scramjet files
|
|
14
|
+
fastify.register(staticPlugin, {
|
|
15
|
+
root: path.join(__dirname, "node_modules/@mercuryworkshop/scramjet/dist"),
|
|
16
|
+
prefix: "/scramjet/",
|
|
17
|
+
decorateReply: false,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Serve frontend
|
|
21
|
+
fastify.register(staticPlugin, {
|
|
22
|
+
root: path.join(__dirname, "public"),
|
|
23
|
+
prefix: "/",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const server = createServer((req, res) => {
|
|
27
|
+
if (bareServer.shouldRoute(req)) {
|
|
28
|
+
bareServer.routeRequest(req, res);
|
|
29
|
+
} else {
|
|
30
|
+
fastify.server.emit("request", req, res);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
server.on("upgrade", (req, socket, head) => {
|
|
35
|
+
if (bareServer.shouldRoute(req)) {
|
|
36
|
+
bareServer.routeUpgrade(req, socket, head);
|
|
37
|
+
} else {
|
|
38
|
+
socket.destroy();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
await fastify.ready();
|
|
43
|
+
|
|
44
|
+
server.listen(8080, () => {
|
|
45
|
+
console.log("Running at http://localhost:8080");
|
|
46
|
+
});
|
package/src/index.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { hostname } from "node:os";
|
|
4
|
+
import { server as wisp, logging } from "@mercuryworkshop/wisp-js/server";
|
|
5
|
+
import Fastify from "fastify";
|
|
6
|
+
import fastifyStatic from "@fastify/static";
|
|
7
|
+
|
|
8
|
+
import { scramjetPath } from "@mercuryworkshop/scramjet/path";
|
|
9
|
+
import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
|
|
10
|
+
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
|
|
11
|
+
|
|
12
|
+
const publicPath = fileURLToPath(new URL("../public/", import.meta.url));
|
|
13
|
+
|
|
14
|
+
// Wisp Configuration: Refer to the documentation at https://www.npmjs.com/package/@mercuryworkshop/wisp-js
|
|
15
|
+
|
|
16
|
+
logging.set_level(logging.NONE);
|
|
17
|
+
Object.assign(wisp.options, {
|
|
18
|
+
allow_udp_streams: false,
|
|
19
|
+
hostname_blacklist: [/example\.com/],
|
|
20
|
+
dns_servers: ["1.1.1.3", "1.0.0.3"],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const fastify = Fastify({
|
|
24
|
+
serverFactory: (handler) => {
|
|
25
|
+
return createServer()
|
|
26
|
+
.on("request", (req, res) => {
|
|
27
|
+
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
|
|
28
|
+
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
|
|
29
|
+
handler(req, res);
|
|
30
|
+
})
|
|
31
|
+
.on("upgrade", (req, socket, head) => {
|
|
32
|
+
if (req.url.endsWith("/wisp/")) wisp.routeRequest(req, socket, head);
|
|
33
|
+
else socket.end();
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
fastify.register(fastifyStatic, {
|
|
39
|
+
root: publicPath,
|
|
40
|
+
decorateReply: true,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
fastify.register(fastifyStatic, {
|
|
44
|
+
root: scramjetPath,
|
|
45
|
+
prefix: "/scram/",
|
|
46
|
+
decorateReply: false,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
fastify.register(fastifyStatic, {
|
|
50
|
+
root: libcurlPath,
|
|
51
|
+
prefix: "/libcurl/",
|
|
52
|
+
decorateReply: false,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
fastify.register(fastifyStatic, {
|
|
56
|
+
root: baremuxPath,
|
|
57
|
+
prefix: "/baremux/",
|
|
58
|
+
decorateReply: false,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
fastify.setNotFoundHandler((res, reply) => {
|
|
62
|
+
return reply.code(404).type("text/html").sendFile("404.html");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
fastify.server.on("listening", () => {
|
|
66
|
+
const address = fastify.server.address();
|
|
67
|
+
|
|
68
|
+
// by default we are listening on 0.0.0.0 (every interface)
|
|
69
|
+
// we just need to list a few
|
|
70
|
+
console.log("Listening on:");
|
|
71
|
+
console.log(`\thttp://localhost:${address.port}`);
|
|
72
|
+
console.log(`\thttp://${hostname()}:${address.port}`);
|
|
73
|
+
console.log(
|
|
74
|
+
`\thttp://${
|
|
75
|
+
address.family === "IPv6" ? `[${address.address}]` : address.address
|
|
76
|
+
}:${address.port}`
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
process.on("SIGINT", shutdown);
|
|
81
|
+
process.on("SIGTERM", shutdown);
|
|
82
|
+
|
|
83
|
+
function shutdown() {
|
|
84
|
+
console.log("SIGTERM signal received: closing HTTP server");
|
|
85
|
+
fastify.close();
|
|
86
|
+
process.exit(0);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let port = parseInt(process.env.PORT || "");
|
|
90
|
+
|
|
91
|
+
if (isNaN(port)) port = 8080;
|
|
92
|
+
|
|
93
|
+
fastify.listen({
|
|
94
|
+
port: port,
|
|
95
|
+
host: "0.0.0.0",
|
|
96
|
+
});
|