]> git.ardis.lu - cloudflare-workers/commitdiff
Add eruda
authorArdis Lu <ardisglu@gmail.com>
Tue, 27 Jun 2023 02:59:47 +0000 (19:59 -0700)
committerArdis Lu <ardisglu@gmail.com>
Tue, 27 Jun 2023 02:59:47 +0000 (19:59 -0700)
README.md
eruda/index.js [new file with mode: 0644]
eruda/package.json [new file with mode: 0644]
eruda/wrangler.toml.example [new file with mode: 0644]
package.json

index 71470e9cf1d9278248d9539014e2081238830916..ced9e0d6d7440d7702c86929e9227bf9be5a1635 100644 (file)
--- a/README.md
+++ b/README.md
@@ -116,6 +116,15 @@ https://x.y.workers.dev?https://en.wikipedia.org/wiki/Bitcoin
 
 <img alt="Snippet of the Wikipedia page for 'Bitcoin' but all instances of the word 'bitcoin' are replaced with 'buttcoin'." src="./buttcoin.png">
 
+## eruda
+
+This reverse proxy injects [eruda](https://github.com/liriliri/eruda) into a
+webpage. Good for quickly injecting DevTools into a webpage.
+
+```
+https://x.y.workers.dev?https://example.com
+```
+
 <h1 align="center">Web Utilities</h1>
 
 ## qr
diff --git a/eruda/index.js b/eruda/index.js
new file mode 100644 (file)
index 0000000..25085ad
--- /dev/null
@@ -0,0 +1,15 @@
+class InjectEruda {
+  element(element) {
+    element.prepend('<script src="//cdn.jsdelivr.net/npm/eruda"></script><script>eruda.init();</script>', { html: true });
+  }
+}
+
+export default {
+  async fetch(request) {
+    const url = /^http(s)?:\/\//i.test(request.url) ? new URL(request.url) : new URL(`https://${request.url}`);
+    const queryString = decodeURIComponent(url.search.substring(1));
+
+    const response = await fetch(queryString);
+    return new HTMLRewriter().on('body', new InjectEruda()).transform(response);
+  }
+}
diff --git a/eruda/package.json b/eruda/package.json
new file mode 100644 (file)
index 0000000..c6d5eff
--- /dev/null
@@ -0,0 +1,16 @@
+{
+  "name": "eruda",
+  "version": "0.3.0",
+  "description": "Reverse proxy which injects eruda into a webpage.",
+  "license": "ISC",
+  "author": "Ardis Lu",
+  "private": true,
+  "scripts": {
+    "dev": "wrangler dev",
+    "deploy": "wrangler deploy"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/ardislu/cloudflare-workers.git"
+  }
+}
diff --git a/eruda/wrangler.toml.example b/eruda/wrangler.toml.example
new file mode 100644 (file)
index 0000000..1f9675a
--- /dev/null
@@ -0,0 +1,4 @@
+name = 'eruda'
+main = 'index.js'
+compatibility_date = '2023-06-26'
+route = { pattern = 'eruda.example.com', custom_domain = true }
index eaae19ea26dc88d9267c2ce1fad81eb636ba3a20..d86c310bf640d1995fce8769c577016209fcf79f 100644 (file)
@@ -28,6 +28,7 @@
     "style",
     "unroll",
     "buttcoin",
-    "archive"
+    "archive",
+    "eruda"
   ]
 }
This page took 0.037846 seconds and 4 git commands to generate.