aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralyx <alyx@aleteoryx.me>2022-06-02 00:26:49 +0000
committerAleteoryx <alyx@aleteoryx.me>2022-06-02 00:26:49 +0000
commitc1e64bf0ccdaeb1b676f1a53967b0d0448e1ca44 (patch)
tree923762a989184bb6a13054d0ca668c85c53db94e
parentb1ec23e3579b1528e6e7eb12f5c9f89793b5390e (diff)
downloadRRCUtils-c1e64bf0ccdaeb1b676f1a53967b0d0448e1ca44.tar.gz
RRCUtils-c1e64bf0ccdaeb1b676f1a53967b0d0448e1ca44.tar.bz2
RRCUtils-c1e64bf0ccdaeb1b676f1a53967b0d0448e1ca44.zip
basic PWA things, fixed the searcher again
-rw-r--r--favicon.icobin0 -> 1150 bytes
-rw-r--r--grapher/index.html1
-rw-r--r--grapher/pl/index.html2
-rw-r--r--index.html17
-rw-r--r--lib/chips.css1
-rw-r--r--lib/chips.js1
-rw-r--r--lib/types.js4
-rw-r--r--pwathings/appver.json3
-rw-r--r--pwathings/icons/100x.pngbin0 -> 2197 bytes
-rw-r--r--pwathings/icons/16x.pngbin0 -> 489 bytes
-rw-r--r--pwathings/icons/200x.pngbin0 -> 4419 bytes
-rw-r--r--pwathings/icons/32x.pngbin0 -> 891 bytes
-rw-r--r--pwathings/icons/400x.pngbin0 -> 6613 bytes
-rw-r--r--pwathings/icons/64x.pngbin0 -> 1757 bytes
-rw-r--r--pwathings/manifest.json54
-rw-r--r--searcher/index.html4
-rw-r--r--searcher/script.js4
-rw-r--r--worker.js116
18 files changed, 201 insertions, 6 deletions
diff --git a/favicon.ico b/favicon.ico
new file mode 100644
index 0000000..19886b4
--- /dev/null
+++ b/favicon.ico
Binary files differ
diff --git a/grapher/index.html b/grapher/index.html
index 26e4af8..9b05e23 100644
--- a/grapher/index.html
+++ b/grapher/index.html
@@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width">
<meta name="description" content="A simple utility to help you make CV2 graphs, out-of-game.">
<meta name="author" content="@✨Aleteoryx✨#1027">
+ <link rel="manifest" href="/pwathings/manifest.json" />
<title>CV2 Node Graph Generator</title>
<link crossorigin href="/oi.css" rel="stylesheet" type="text/css">
<link crossorigin href="style.css" rel="stylesheet" type="text/css" />
diff --git a/grapher/pl/index.html b/grapher/pl/index.html
index 3dc7119..7a728b9 100644
--- a/grapher/pl/index.html
+++ b/grapher/pl/index.html
@@ -4,6 +4,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Permalinked Graph</title>
+
+ <link rel="manifest" href="/pwathings/manifest.json" />
<link crossorigin href="style.css" rel="stylesheet" type="text/css" />
diff --git a/index.html b/index.html
index 9b24973..26592e1 100644
--- a/index.html
+++ b/index.html
@@ -2,9 +2,22 @@
<html>
<head>
<title>Placeholder</title>
+ <link rel="manifest" href="/pwathings/manifest.json" />
+ <link rel="manifest" href="/pwathings/manifest.json" />
+ <script>
+ var reg;
+ window.addEventListener("load", async function() {
+ reg = await navigator.serviceWorker.getRegistrations();
+ if (reg.length) document.getElementById("enabler").innerText = "Click to refresh the Service Worker!";
+ });
+ const reloader = () => Promise.all(reg.map(r => r.unregister())).then(() => navigator.serviceWorker.register('/worker.js', {scope: '/'}));
+ </script>
</head>
<body>
- <a href="/searcher">Chip Searcher</a>
- <a href="/grapher">Chip Grapher</a>
+ <ul>
+ <li><a href="/searcher">Chip Searcher</a></li>
+ <li><a href="/grapher">Chip Grapher</a></li>
+ <li><button id="enabler" onclick="reloader();">Click to enable offline use!</button></li>
+ </ul>
</body>
</html> \ No newline at end of file
diff --git a/lib/chips.css b/lib/chips.css
index 12a3704..9d944de 100644
--- a/lib/chips.css
+++ b/lib/chips.css
@@ -152,6 +152,7 @@ body {
z-index: 99;
top: calc(var(--mouse-y) + 10px - (var(--chipOffsetY) * 1px));
left: calc(var(--mouse-x) + 10px - (var(--chipOffsetX) * 1px));
+ user-select: none;
}
.input > .exec::before,
diff --git a/lib/chips.js b/lib/chips.js
index 0ba542e..d418061 100644
--- a/lib/chips.js
+++ b/lib/chips.js
@@ -6,7 +6,6 @@ if (window.location.pathname != '/grapher/')
root.style.setProperty('--mouse-y', e.clientY + "px");
});
-
const portColors = {
float: '#186adc',
int: '#0f6522',
diff --git a/lib/types.js b/lib/types.js
new file mode 100644
index 0000000..ed83f12
--- /dev/null
+++ b/lib/types.js
@@ -0,0 +1,4 @@
+//Gods-awful type-checking logic.
+
+//TypeName: string, Params: Array<string>|Object<string>
+function workOutType() \ No newline at end of file
diff --git a/pwathings/appver.json b/pwathings/appver.json
new file mode 100644
index 0000000..669fb74
--- /dev/null
+++ b/pwathings/appver.json
@@ -0,0 +1,3 @@
+{
+ "ver": 1
+} \ No newline at end of file
diff --git a/pwathings/icons/100x.png b/pwathings/icons/100x.png
new file mode 100644
index 0000000..b520f69
--- /dev/null
+++ b/pwathings/icons/100x.png
Binary files differ
diff --git a/pwathings/icons/16x.png b/pwathings/icons/16x.png
new file mode 100644
index 0000000..c6df0e1
--- /dev/null
+++ b/pwathings/icons/16x.png
Binary files differ
diff --git a/pwathings/icons/200x.png b/pwathings/icons/200x.png
new file mode 100644
index 0000000..a6d9541
--- /dev/null
+++ b/pwathings/icons/200x.png
Binary files differ
diff --git a/pwathings/icons/32x.png b/pwathings/icons/32x.png
new file mode 100644
index 0000000..bf0bb2c
--- /dev/null
+++ b/pwathings/icons/32x.png
Binary files differ
diff --git a/pwathings/icons/400x.png b/pwathings/icons/400x.png
new file mode 100644
index 0000000..f92bba7
--- /dev/null
+++ b/pwathings/icons/400x.png
Binary files differ
diff --git a/pwathings/icons/64x.png b/pwathings/icons/64x.png
new file mode 100644
index 0000000..0779747
--- /dev/null
+++ b/pwathings/icons/64x.png
Binary files differ
diff --git a/pwathings/manifest.json b/pwathings/manifest.json
new file mode 100644
index 0000000..2a7611b
--- /dev/null
+++ b/pwathings/manifest.json
@@ -0,0 +1,54 @@
+{
+ "name": "Aleteoryx's Circuit Utilities",
+ "short_name": "CV2Utils",
+ "description": "A set of tools for understanding and working with Rec Room's circuits, formerly CV2.",
+
+ "start_url": "/",
+ "display": "minimal-ui",
+
+ "background_color": "#082f41",
+
+ "shortcuts": [
+ {
+ "name": "Chip Searcher",
+ "url": "/searcher"
+ },
+ {
+ "name": "Chip Searcher",
+ "url": "/searcher"
+ }
+ ],
+
+ "icons": [
+ {
+ "src": "/pwathings/icons/400x.png",
+ "sizes": "400x400",
+ "type": "image/png"
+ },
+ {
+ "src": "/pwathings/icons/200x.png",
+ "sizes": "200x200",
+ "type": "image/png"
+ },
+ {
+ "src": "/pwathings/icons/100x.png",
+ "sizes": "100x100",
+ "type": "image/png"
+ },
+ {
+ "src": "/pwathings/icons/64x.png",
+ "sizes": "64x64",
+ "type": "image/png"
+ },
+ {
+ "src": "/pwathings/icons/32x.png",
+ "sizes": "32x32",
+ "type": "image/png"
+ },
+ {
+ "src": "/pwathings/icons/16x.png",
+ "sizes": "16x16",
+ "type": "image/png"
+ }
+ ]
+} \ No newline at end of file
diff --git a/searcher/index.html b/searcher/index.html
index f6ae0a1..e02fabb 100644
--- a/searcher/index.html
+++ b/searcher/index.html
@@ -6,6 +6,8 @@
<meta name="description" content="A simple utility to help you work out what chips do.">
<meta name="author" content="@✨Aleteoryx✨#1027">
<title>CV2 Chip Searcher</title>
+ <link rel="manifest" href="/pwathings/manifest.json" />
+
<link crossorigin href="style.css" rel="stylesheet" type="text/css" />
<link crossorigin href="/lib/chips.css" rel="stylesheet" type="text/css" />
@@ -88,7 +90,7 @@
</div>
<hr/>
<div id="resultslist"></div>
- <p id="grapherlink">Also check out <a href="/grapher">The graphing tool</a>!</p>
+ <!--<p id="grapherlink">Also check out <a href="/grapher">The graphing tool</a>!</p>-->
<p>Maintained by <a href="https://rec.net/user/winrg" target="_blank" rel="noopener noreferrer">@winrg</a>/<code>@✨Aleteoryx, Keeper of Names✨#1027</code></p>
<details id="helpbox">
<summary>?</summary>
diff --git a/searcher/script.js b/searcher/script.js
index d80cd8f..e8ffec3 100644
--- a/searcher/script.js
+++ b/searcher/script.js
@@ -52,7 +52,7 @@ window.addEventListener("load", async (e) => {
const form = document.getElementById("form");
const suggestions = document.getElementById("paletteSearch");
- if (isNested) document.getElementById("grapherlink").remove();
+ //if (isNested) document.getElementById("grapherlink").remove();
if (localStorage.length) {
form.depr.checked = localStorage.getItem("depr");
@@ -156,7 +156,7 @@ window.addEventListener("load", async (e) => {
//console.log(content2.nodes)
content = content.map(el => {
- if ((form.depr.checked || el.DeprecationStage == 0) && (form.beta.checked || !el.IsBetaChip)) {
+ if ((form.depr.checked || el.DeprecationStage == "Active") && (form.beta.checked || !el.IsBetaChip)) {
const ret = newEl("details", "returnedchip");
if (el.IsBetaChip) ret.classList.add("betaChip");
diff --git a/worker.js b/worker.js
new file mode 100644
index 0000000..39375e4
--- /dev/null
+++ b/worker.js
@@ -0,0 +1,116 @@
+var resolver;
+
+addEventListener("fetch", e => {
+ console.log("Fetch: ", e)
+ e.waitUntil(async () => {
+ const mc = await caches.open(main);
+ e.respondWith(await mc.match(e.request) ?? await fetch(e.request));
+ console.log(await mc.match(e.request));
+ })
+})
+
+addEventListener("install", async function(e) {
+ console.log('Install!');
+ e.waitUntil(new Promise((res) => {resolver=res}));
+ //auto halt after 5s
+ setTimeout(resolver, 10000);
+
+ setInterval(reload, 5*60*1000); //reload every hour, just in case.
+ await reload();
+
+ resolver();
+
+});
+
+addEventListener("activate", clients.claim.bind(clients));
+
+async function reload() {
+ const {ver} = await fetch("/pwathings/appver.json").then(v => v.json());
+ const cache = await caches.open(String(ver));
+
+ if ((await cache.keys()).length == 0) {
+ console.log("Reloading all resources...");
+ await recursiveLinkWalker("/", cache);
+ console.log("Done!");
+ console.log("Overwriting main cache.");
+ await caches.delete("main");
+ const mc = await caches.open("main");
+ for (const k of await cache.keys())
+ await mc.put(k, await cache.match(k));
+ console.log("Done!");
+ }
+}
+
+async function recursiveLinkWalker(url, cache, visits=[], constrain=["cv2.aleteoryx.me"]) {
+ const urlobj = new URL(url, "https://cv2.aleteoryx.me");
+ console.dir(urlobj, String(urlobj));
+ if (!constrain.includes(urlobj.hostname) || visits.includes(url))
+ return;
+
+ try {
+ const data = await fetch(url);
+ if (!data.ok) throw new Error("Failed to get the page!")
+ const blob = await data.blob();
+ await cache.put(url, new Response(blob));
+ visits.push(url);
+
+ const mime = blob.type;
+ const text = await blob.text();
+ console.log(url, mime);
+
+ switch (mime.split("/").at(-1)) {
+ case 'css':
+ const cssregex = /url\((?:'|"|)([^'")]+)(?:'|"|)\)/gm;
+ var match;
+ while (match = cssregex.exec(text)) {
+ await recursiveLinkWalker(match[1], cache, visits, constrain);
+ }
+ break;
+ case 'html':/*
+ Because the gods hate me, service workers lack this functionality below.
+ Regex time!
+
+ const doc = new Document();
+ doc.documentElement.innerHTML = text;
+
+ const HREFed = [...(["link", "a"].map(n => Array.from(doc.getElementsByTagName(n))))].flatten();
+ const SRCes = [...(["img", "script"].map(n => Array.from(doc.getElementsByTagName(n))))].flatten();
+
+ for (const h of HREFed) await recursiveLinkWalker(h.getAttribute('href'), cache, visits, constrain);
+ for (const s of SRCes) await recursiveLinkWalker(h.getAttribute('src'), cache, visits, constrain);
+ */
+ const hreftagre = /<\w+\s+(?:(?!href=)\w+(?:="[^"]*")?\s+)*href="([^"]*)"(?:\s+\w+(?:="[^"]*")?)*\s*\/?>/gm
+ const srctagre = /<\w+\s+(?:(?!src=)\w+(?:="[^"]*")?\s+)*src="([^"]*)"(?:\s+\w+(?:="[^"]*")?)*\s*\/?>/gm;
+
+ var match;
+ while (match = hreftagre.exec(text))
+ await recursiveLinkWalker(match[1], cache, visits, constrain);
+ while (match = srctagre.exec(text))
+ await recursiveLinkWalker(match[1], cache, visits, constrain);
+ break;
+
+ case 'json':
+ //to make sure we don't go rifling through all the fascinating URLs in 'circuitsv2.json'
+ const whitelist = ["/pwathings/manifest.json"]
+ if(!whitelist.map(m => url.endsWith(m)).reduce((a,b) => a||b)) break;
+ const walker = async (obj) => {
+ switch (typeof obj) {
+ case 'string':
+ await recursiveLinkWalker(obj, cache, visits, constrain);
+ break;
+ case 'object':
+ for (const k of Object.values(obj))
+ await walker(k);
+ break;
+ }
+ }
+ await walker(JSON.parse(text));
+ break;
+
+ }
+ } catch (e) {
+ console.log(e);
+ return;
+ }
+ console.log("returning naturally", url, visits);
+} \ No newline at end of file