├── wrangler.toml ├── package.json ├── .github └── workflows │ └── deploy.yml ├── README.md ├── src ├── index.ts └── html.ts ├── .gitignore └── tsconfig.json /wrangler.toml: -------------------------------------------------------------------------------- 1 | name = "toot-linker" 2 | main = "src/index.ts" 3 | compatibility_date = "2022-12-16" 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "toot-linker", 3 | "version": "0.0.0", 4 | "devDependencies": { 5 | "@cloudflare/workers-types": "^4.20221111.1", 6 | "typescript": "^4.9.4", 7 | "wrangler": "2.6.2" 8 | }, 9 | "private": true, 10 | "scripts": { 11 | "start": "wrangler dev", 12 | "deploy": "wrangler publish" 13 | }, 14 | "dependencies": { 15 | "itty-router": "^2.6.6", 16 | "itty-router-extras": "^0.4.2" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | push: 4 | pull_request: 5 | repository_dispatch: 6 | jobs: 7 | deploy: 8 | runs-on: ubuntu-latest 9 | timeout-minutes: 60 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Publish 13 | uses: cloudflare/wrangler-action@2.0.0 14 | with: 15 | apiToken: ${{ secrets.CF_API_TOKEN }} 16 | preCommands: npm install 17 | command: publish 18 | env: 19 | CF_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Toot Linker 2 | 3 | Toot Linker is a tool that allows you to share your Mastodon posts on Twitter while still showing the preview on Twitter. Twitter has started blocking all Mastodon links, but Toot Linker provides a solution by creating a redirect website that Twitter's bots will not block as malicious. 4 | 5 | ## How to use Toot Linker 6 | 7 | To use Toot Linker, you will need to provide your Mastodon server URL and your Mastodon username. Toot Linker will then create a redirect link that you can share on Twitter. When someone clicks on the link, they will be taken to the original Mastodon post, but the preview will still be displayed on Twitter. 8 | 9 | You can either deploy Toot Linker to Cloudflare Workers or use the hosted version at https://toot-linker.altryne.workers.dev. 10 | 11 | ## Example 12 | 13 | Here is an example of how you might use Toot Linker: 14 | 15 | Write a new Mastodon post on your Mastodon server. 16 | Copy the URL of the post. 17 | Go to Toot Linker and enter your Mastodon server URL and your Mastodon username. 18 | Paste the URL of the Mastodon post into the Toot Linker input field. 19 | Click "Generate Link". 20 | Copy the generated link and share it on Twitter. 21 | 22 | ## Notes 23 | 24 | - Toot Linker is intended for personal use only. Please do not use it to spam or engage in any other unethical behavior. 25 | - Toot Linker is provided as-is, without any warranties or guarantees. Use at your own risk. 26 | - Toot Linker is not affiliated with Mastodon or Twitter. 27 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { Router } from 'itty-router' 2 | import { html } from './html' 3 | const router = Router() 4 | 5 | export interface Env { 6 | // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/ 7 | // MY_KV_NAMESPACE: KVNamespace; 8 | // 9 | // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/ 10 | // MY_DURABLE_OBJECT: DurableObjectNamespace; 11 | // 12 | // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/ 13 | // MY_BUCKET: R2Bucket; 14 | } 15 | 16 | class ElementHandler { 17 | element(element) { 18 | if(element.tagName == 'body') { 19 | element.replace(`
Hello, world!`); 20 | } 21 | } 22 | 23 | comments(comment) { 24 | // An incoming comment 25 | } 26 | 27 | text(text) { 28 | // An incoming piece of text 29 | } 30 | } 31 | 32 | 33 | router.get('/m/:server/:user', async(req, env, ctx) => { 34 | const { params, query, headers } = req 35 | 36 | // If the useragent is User-agent: Twitterbot/1.0, fetch the passed parameter and return its meta tags 37 | // If the useragent is not Twitterbot, return a redirect to the passed parameter url 38 | console.log(req.headers.get('User-Agent')) 39 | let userAgent = req.headers.get('User-Agent') 40 | if (userAgent.includes('Twitterbot') || userAgent.includes('Iframely')) { 41 | // @ts-ignore 42 | const toot_url = `https://${params.server}/${params.user}` 43 | const res = await fetch(toot_url) 44 | const only_meta = new HTMLRewriter().on('meta', new ElementHandler()).transform(res) 45 | const removed_body = new HTMLRewriter().on('body', new ElementHandler()).transform(only_meta) 46 | return removed_body; 47 | }else{ 48 | // redirect to tooting 49 | return Response.redirect(`https://${params.server}/${params.user}`, 302) 50 | } 51 | 52 | 53 | }) 54 | // 404 for everything else 55 | router.all('*', (request, args) => { 56 | // print the request url host 57 | console.log(`Request URL: ${request.url}`) 58 | return new Response(html(request.url), { 59 | headers: { 60 | 'content-type': 'text/html;charset=UTF-8', 61 | }, 62 | }); 63 | }) 64 | 65 | export default { 66 | async fetch( 67 | request: Request, 68 | env: Env, 69 | ctx: ExecutionContext 70 | ): Promise
65 | What is this?
66 | Well, if you are new to Mastodon, and want to share your new profile on certain social media websites, some of them are now marking mastodon domains as malicious. Talk about freedom of speech eh?
67 |
68 | Share this link instead, and Twitter will show the SEO tags from your mastodon profile, but without the ban!
69 |
Click "copy" and an unbannable link will be generated
108 |