vfsjs-test 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.
Files changed (3) hide show
  1. package/index.html +67 -0
  2. package/package.json +13 -0
  3. package/sw.js +28 -0
package/index.html ADDED
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Infrared GitHack VFS Engine</title>
6
+
7
+ <link rel="stylesheet" href="live-theme.css">
8
+ </head>
9
+ <body style="background: #0f172a; color: #38bdf8; font-family: monospace; padding: 20px;">
10
+
11
+ <h2>Infrared Native Network Pipeline</h2>
12
+ <div id="status" style="background: #020617; border: 1px solid #334155; padding: 15px; height: 120px; color: #f1f5f9; line-height: 1.6;">
13
+ > Initializing same-origin network worker...
14
+ </div>
15
+
16
+ <script src="live-alert.js"></script>
17
+
18
+ <script>
19
+ async function bootEngine() {
20
+ const display = document.getElementById('status');
21
+
22
+ try {
23
+ // Since index.html and sw.js live in the same repo, we can use a relative path!
24
+ // This completely bypasses the Same-Origin Policy check in Firefox.
25
+ const registration = await navigator.serviceWorker.register('./sw.js', { scope: './' });
26
+ display.innerHTML += "<br>> Service worker registered successfully.";
27
+
28
+ // Wait until the Service Worker has complete control of the page
29
+ if (!navigator.serviceWorker.controller) {
30
+ display.innerHTML += "<br>> Activating worker routing link... (Please refresh if stuck)";
31
+ await new Promise(r => navigator.serviceWorker.addEventListener('controllerchange', r, { once: true }));
32
+ }
33
+ display.innerHTML += "<br>> Link secured. Writing virtual assets to thread...";
34
+
35
+ // 3. Write your assets directly into the active worker's virtual RAM
36
+ const encoder = new TextEncoder();
37
+
38
+ navigator.serviceWorker.controller.postMessage({
39
+ type: 'VFS_WRITE',
40
+ filename: 'live-theme.css',
41
+ content: encoder.encode(`body { background: #011627 !important; color: #82aaff !important; }`)
42
+ });
43
+
44
+ navigator.serviceWorker.controller.postMessage({
45
+ type: 'VFS_WRITE',
46
+ filename: 'live-alert.js',
47
+ content: encoder.encode(`
48
+ console.log("SUCCESS: Native script tag caught by Service Worker intercept loop!");
49
+ document.getElementById('status').innerHTML += "<br>> Virtual script execution confirmed.";
50
+ `)
51
+ });
52
+
53
+ // Give the worker a tiny fraction of a second to map the files
54
+ await new Promise(r => setTimeout(r, 100));
55
+
56
+ display.innerHTML += "<br>> Matrix deployment complete.";
57
+
58
+ } catch (err) {
59
+ display.innerHTML += `<br>><span style="color: #ef4444;"> Error: ${err.message}</span>`;
60
+ console.error(err);
61
+ }
62
+ }
63
+
64
+ bootEngine();
65
+ </script>
66
+ </body>
67
+ </html>
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "vfsjs-test",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.html",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "type": "commonjs"
13
+ }
package/sw.js ADDED
@@ -0,0 +1,28 @@
1
+
2
+ const files = new Map();
3
+ const defaultMimes = { 'js': 'text/javascript', 'css': 'text/css', 'html': 'text/html' };
4
+
5
+ self.addEventListener('install', e => e.waitUntil(self.skipWaiting()));
6
+ self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));
7
+
8
+ self.addEventListener('fetch', (event) => {
9
+ const url = new URL(event.request.url);
10
+ const filename = url.pathname.split('/').pop().split('?')[0];
11
+
12
+ // Intercept matching virtual files from local memory
13
+ if (files.has(filename)) {
14
+ const content = files.get(filename);
15
+ const ext = filename.split('.').pop().toLowerCase();
16
+
17
+ event.respondWith(new Response(content, {
18
+ status: 200,
19
+ headers: { 'Content-Type': defaultMimes[ext] || 'application/octet-stream' }
20
+ }));
21
+ }
22
+ });
23
+
24
+ self.addEventListener('message', (event) => {
25
+ if (event.data && event.data.type === 'VFS_WRITE') {
26
+ files.set(event.data.filename, event.data.content);
27
+ }
28
+ });