From: Ardis Lu Date: Mon, 1 Nov 2021 02:13:22 +0000 (-0700) Subject: Add unroll worker X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=54db92a082da7b5ceaffd4cad97d5f9a5bc91be4;p=cloudflare-workers Add unroll worker --- 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/*'