From c1e64bf0ccdaeb1b676f1a53967b0d0448e1ca44 Mon Sep 17 00:00:00 2001 From: alyx Date: Thu, 2 Jun 2022 00:26:49 +0000 Subject: basic PWA things, fixed the searcher again --- favicon.ico | Bin 0 -> 1150 bytes grapher/index.html | 1 + grapher/pl/index.html | 2 + index.html | 17 ++++++- lib/chips.css | 1 + lib/chips.js | 1 - lib/types.js | 4 ++ pwathings/appver.json | 3 ++ pwathings/icons/100x.png | Bin 0 -> 2197 bytes pwathings/icons/16x.png | Bin 0 -> 489 bytes pwathings/icons/200x.png | Bin 0 -> 4419 bytes pwathings/icons/32x.png | Bin 0 -> 891 bytes pwathings/icons/400x.png | Bin 0 -> 6613 bytes pwathings/icons/64x.png | Bin 0 -> 1757 bytes pwathings/manifest.json | 54 ++++++++++++++++++++++ searcher/index.html | 4 +- searcher/script.js | 4 +- worker.js | 116 +++++++++++++++++++++++++++++++++++++++++++++++ 18 files changed, 201 insertions(+), 6 deletions(-) create mode 100644 favicon.ico create mode 100644 lib/types.js create mode 100644 pwathings/appver.json create mode 100644 pwathings/icons/100x.png create mode 100644 pwathings/icons/16x.png create mode 100644 pwathings/icons/200x.png create mode 100644 pwathings/icons/32x.png create mode 100644 pwathings/icons/400x.png create mode 100644 pwathings/icons/64x.png create mode 100644 pwathings/manifest.json create mode 100644 worker.js diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..19886b4 Binary files /dev/null and b/favicon.ico 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 @@ + CV2 Node Graph Generator 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 @@ Permalinked Graph + + diff --git a/index.html b/index.html index 9b24973..26592e1 100644 --- a/index.html +++ b/index.html @@ -2,9 +2,22 @@ Placeholder + + + - Chip Searcher - Chip Grapher + \ 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|Object +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 Binary files /dev/null and b/pwathings/icons/100x.png differ diff --git a/pwathings/icons/16x.png b/pwathings/icons/16x.png new file mode 100644 index 0000000..c6df0e1 Binary files /dev/null and b/pwathings/icons/16x.png differ diff --git a/pwathings/icons/200x.png b/pwathings/icons/200x.png new file mode 100644 index 0000000..a6d9541 Binary files /dev/null and b/pwathings/icons/200x.png differ diff --git a/pwathings/icons/32x.png b/pwathings/icons/32x.png new file mode 100644 index 0000000..bf0bb2c Binary files /dev/null and b/pwathings/icons/32x.png differ diff --git a/pwathings/icons/400x.png b/pwathings/icons/400x.png new file mode 100644 index 0000000..f92bba7 Binary files /dev/null and b/pwathings/icons/400x.png differ diff --git a/pwathings/icons/64x.png b/pwathings/icons/64x.png new file mode 100644 index 0000000..0779747 Binary files /dev/null and b/pwathings/icons/64x.png 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 @@ CV2 Chip Searcher + + @@ -88,7 +90,7 @@
- +

Maintained by @winrg/@✨Aleteoryx, Keeper of Names✨#1027

? 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 -- cgit v1.2.3-54-g00ecf