From 54db92a082da7b5ceaffd4cad97d5f9a5bc91be4 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 31 Oct 2021 19:13:22 -0700 Subject: [PATCH] Add unroll worker --- README.md | 8 ++++++++ package.json | 3 ++- unroll/index.js | 11 +++++++++++ unroll/package.json | 20 ++++++++++++++++++++ unroll/wrangler.toml.example | 5 +++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 unroll/index.js create mode 100644 unroll/package.json create mode 100644 unroll/wrangler.toml.example diff --git a/README.md b/README.md index 475cc0b..a912d54 100644 --- 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. diff --git a/package.json b/package.json index 117ae00..b19e028 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "qr", "ip", "uuid", - "style" + "style", + "unroll" ] } diff --git a/unroll/index.js b/unroll/index.js new file mode 100644 index 0000000..e1a9a7f --- /dev/null +++ b/unroll/index.js @@ -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 index 0000000..a4d07bb --- /dev/null +++ b/unroll/package.json @@ -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 index 0000000..46e5246 --- /dev/null +++ b/unroll/wrangler.toml.example @@ -0,0 +1,5 @@ +name = 'unroll' +type = 'javascript' +account_id = '' +workers_dev = true +route = 'example.com/*' -- 2.47.3