@indextools/index-games 0.0.0-stage → 1.0.1

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.
Files changed (50) hide show
  1. package/README.md +73 -2
  2. package/index.svg +53 -0
  3. package/package.json +47 -5
  4. package/public/404.html +50 -0
  5. package/public/baremux/worker.js +2 -0
  6. package/public/config.js +27 -0
  7. package/public/games/agesofconflict.html +224 -0
  8. package/public/games/baldi.html +50 -0
  9. package/public/games/boi.html +132 -0
  10. package/public/games/brotato.html +142 -0
  11. package/public/games/fnae.html +153 -0
  12. package/public/games/games.json +122 -0
  13. package/public/games/gamesuggestion.html +12 -0
  14. package/public/games/geodash.html +274 -0
  15. package/public/games/kidchess.html +52 -0
  16. package/public/games/lebronclicker.html +763 -0
  17. package/public/games/monstertracks.html +31 -0
  18. package/public/games/nealfun.html +52 -0
  19. package/public/games/slitherio.html +186 -0
  20. package/public/games/slope.html +114 -0
  21. package/public/games/spacewaves.html +246 -0
  22. package/public/games/wheeliebike.html +50 -0
  23. package/public/icons/BNG-Favicon.png +0 -0
  24. package/public/icons/CGPT-Favicon.png +0 -0
  25. package/public/icons/CMG-Favicon.jpg +0 -0
  26. package/public/icons/CZG-Favicon.png +0 -0
  27. package/public/icons/DC-Favicon.png +0 -0
  28. package/public/icons/DDG-Favicon.png +0 -0
  29. package/public/icons/G-Favicon.png +0 -0
  30. package/public/icons/GH-Favicon.png +0 -0
  31. package/public/icons/GameSuggestions-Favicons.png +0 -0
  32. package/public/icons/MCTF-Favicon.png +0 -0
  33. package/public/icons/MP4-Favicon.webp +0 -0
  34. package/public/icons/NDF-Favicon.png +0 -0
  35. package/public/icons/NGG-Favicon.png +0 -0
  36. package/public/icons/RDT-Favicon.png +0 -0
  37. package/public/icons/RPT-Favicon.png +0 -0
  38. package/public/icons/S-Favicon.png +0 -0
  39. package/public/icons/TT-Favicon.png +0 -0
  40. package/public/icons/X-Favicon.jpg +0 -0
  41. package/public/icons/YT-Favicon.png +0 -0
  42. package/public/index.css +888 -0
  43. package/public/index.html +1141 -0
  44. package/public/index.js +76 -0
  45. package/public/index.svg +53 -0
  46. package/public/register-sw.js +29 -0
  47. package/public/search.js +32 -0
  48. package/public/sw.js +16 -0
  49. package/server.js +46 -0
  50. package/src/index.js +96 -0
@@ -0,0 +1,76 @@
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 baseDir = new URL("./", location.href).pathname;
31
+ const workerPath = (cfg.baremux && cfg.baremux.worker) || new URL("baremux/worker.js", location.href).pathname;
32
+ const scramjetPrefix = baseDir + "service/";
33
+
34
+ const { ScramjetController } = $scramjetLoadController();
35
+
36
+ const scramjet = new ScramjetController({
37
+ files: scramjetFiles,
38
+ prefix: scramjetPrefix,
39
+ });
40
+
41
+ scramjet.init();
42
+
43
+ const connection = new BareMux.BareMuxConnection(workerPath);
44
+
45
+ form.addEventListener("submit", async (event) => {
46
+ event.preventDefault();
47
+
48
+ try {
49
+ await registerSW();
50
+ } catch (err) {
51
+ error.textContent = "Failed to register service worker.";
52
+ errorCode.textContent = err.toString();
53
+ throw err;
54
+ }
55
+
56
+ const url = search(address.value, searchEngine.value);
57
+
58
+ let wispUrl =
59
+ cfg.wispUrl ||
60
+ (location.host && location.host.includes("unpkg.com")
61
+ ? "wss://wisp.mercurywork.shop/"
62
+ : (location.protocol === "https:" ? "wss" : "ws") +
63
+ "://" +
64
+ location.host +
65
+ "/wisp/");
66
+ const transportUrl = (cfg.libcurl && cfg.libcurl.transport) || "https://unpkg.com/@mercuryworkshop/libcurl-transport@1.5.2/dist/index.mjs";
67
+ if ((await connection.getTransport()) !== transportUrl) {
68
+ await connection.setTransport(transportUrl, [
69
+ { websocket: wispUrl },
70
+ ]);
71
+ }
72
+ const frame = scramjet.createFrame();
73
+ frame.frame.id = "sj-frame";
74
+ document.body.appendChild(frame.frame);
75
+ frame.go(url);
76
+ });
@@ -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,29 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * List of hostnames that are allowed to run serviceworkers on http://
5
+ */
6
+ const swAllowedHostnames = ["localhost", "127.0.0.1"];
7
+
8
+ /**
9
+ * Global util
10
+ * Used in index.html, 404.html, and games
11
+ */
12
+ async function registerSW() {
13
+ if (!navigator.serviceWorker) {
14
+ if (
15
+ location.protocol !== "https:" &&
16
+ !swAllowedHostnames.includes(location.hostname)
17
+ )
18
+ throw new Error("Service workers cannot be registered without https.");
19
+
20
+ throw new Error("Your browser doesn't support service workers.");
21
+ }
22
+
23
+ let publicDir = new URL("./", location.href).pathname;
24
+ if (publicDir.endsWith("/games/")) {
25
+ publicDir = new URL("../", location.href).pathname;
26
+ }
27
+ const swUrl = publicDir + "sw.js";
28
+ await navigator.serviceWorker.register(swUrl, { scope: publicDir });
29
+ }
@@ -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
+ });