]> git.ardis.lu - cloudflare-workers/commitdiff
Add unroll worker
authorArdis Lu <ardisglu@gmail.com>
Mon, 1 Nov 2021 02:13:22 +0000 (19:13 -0700)
committerArdis Lu <ardisglu@gmail.com>
Mon, 1 Nov 2021 02:13:22 +0000 (19:13 -0700)
README.md
package.json
unroll/index.js [new file with mode: 0644]
unroll/package.json [new file with mode: 0644]
unroll/wrangler.toml.example [new file with mode: 0644]

index 475cc0bd626b026d3b902bc04903ebbebd3211b2..a912d5460883f40302967d236870927d5f9f2213 100644 (file)
--- a/README.md
+++ b/README.md
@@ -191,3 +191,11 @@ Reverse proxy which injects a basic CSS style sheet.
 ### Usage
 
 Same as `proxy`.
+
+## unroll
+
+Redirects a tweet thread to the corresponding Threadreader thread.
+
+### Usage
+
+Same as `proxy`, but only works on tweet URLs.
index 117ae00f98a0f2c595edc12cc01b4762d32cf8ef..b19e028648c4cf6f55b57774eceb8543c2acd9f8 100644 (file)
@@ -27,6 +27,7 @@
     "qr",
     "ip",
     "uuid",
-    "style"
+    "style",
+    "unroll"
   ]
 }
diff --git a/unroll/index.js b/unroll/index.js
new file mode 100644 (file)
index 0000000..e1a9a7f
--- /dev/null
@@ -0,0 +1,11 @@
+async function handleRequest(request) {
+  const url = new URL(request.url);
+  const queryString = decodeURIComponent(url.search.substring(1));
+  const tweet = queryString.split('/').pop();
+
+  return Response.redirect(`https://threadreaderapp.com/thread/${tweet}`);
+}
+
+addEventListener('fetch', event => {
+  event.respondWith(handleRequest(event.request));
+})
diff --git a/unroll/package.json b/unroll/package.json
new file mode 100644 (file)
index 0000000..a4d07bb
--- /dev/null
@@ -0,0 +1,20 @@
+{
+  "name": "unroll",
+  "version": "0.1.0",
+  "description": "Redirects a tweet thread to the corresponding Threadreader thread.",
+  "private": true,
+  "main": "index.js",
+  "scripts": {
+    "login": "wrangler login",
+    "dev": "wrangler dev",
+    "preview": "wrangler preview",
+    "build": "wrangler build",
+    "publish": "wrangler publish"
+  },
+  "author": "Ardis Lu",
+  "license": "ISC",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/ardislu/cloudflare-workers.git"
+  }
+}
diff --git a/unroll/wrangler.toml.example b/unroll/wrangler.toml.example
new file mode 100644 (file)
index 0000000..46e5246
--- /dev/null
@@ -0,0 +1,5 @@
+name = 'unroll'
+type = 'javascript'
+account_id = ''
+workers_dev = true
+route = 'example.com/*'
This page took 0.037207 seconds and 4 git commands to generate.