├── 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 { 71 | return await router.handle(request, env, ctx) 72 | }, 73 | }; 74 | 75 | 76 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | .idea 3 | logs 4 | _.log 5 | npm-debug.log_ 6 | yarn-debug.log* 7 | yarn-error.log* 8 | lerna-debug.log* 9 | .pnpm-debug.log* 10 | 11 | # Diagnostic reports (https://nodejs.org/api/report.html) 12 | 13 | report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json 14 | 15 | # Runtime data 16 | 17 | pids 18 | _.pid 19 | _.seed 20 | \*.pid.lock 21 | 22 | # Directory for instrumented libs generated by jscoverage/JSCover 23 | 24 | lib-cov 25 | 26 | # Coverage directory used by tools like istanbul 27 | 28 | coverage 29 | \*.lcov 30 | 31 | # nyc test coverage 32 | 33 | .nyc_output 34 | 35 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 36 | 37 | .grunt 38 | 39 | # Bower dependency directory (https://bower.io/) 40 | 41 | bower_components 42 | 43 | # node-waf configuration 44 | 45 | .lock-wscript 46 | 47 | # Compiled binary addons (https://nodejs.org/api/addons.html) 48 | 49 | build/Release 50 | 51 | # Dependency directories 52 | 53 | node_modules/ 54 | jspm_packages/ 55 | 56 | # Snowpack dependency directory (https://snowpack.dev/) 57 | 58 | web_modules/ 59 | 60 | # TypeScript cache 61 | 62 | \*.tsbuildinfo 63 | 64 | # Optional npm cache directory 65 | 66 | .npm 67 | 68 | # Optional eslint cache 69 | 70 | .eslintcache 71 | 72 | # Optional stylelint cache 73 | 74 | .stylelintcache 75 | 76 | # Microbundle cache 77 | 78 | .rpt2_cache/ 79 | .rts2_cache_cjs/ 80 | .rts2_cache_es/ 81 | .rts2_cache_umd/ 82 | 83 | # Optional REPL history 84 | 85 | .node_repl_history 86 | 87 | # Output of 'npm pack' 88 | 89 | \*.tgz 90 | 91 | # Yarn Integrity file 92 | 93 | .yarn-integrity 94 | 95 | # dotenv environment variable files 96 | 97 | .env 98 | .env.development.local 99 | .env.test.local 100 | .env.production.local 101 | .env.local 102 | 103 | # parcel-bundler cache (https://parceljs.org/) 104 | 105 | .cache 106 | .parcel-cache 107 | 108 | # Next.js build output 109 | 110 | .next 111 | out 112 | 113 | # Nuxt.js build / generate output 114 | 115 | .nuxt 116 | dist 117 | 118 | # Gatsby files 119 | 120 | .cache/ 121 | 122 | # Comment in the public line in if your project uses Gatsby and not Next.js 123 | 124 | # https://nextjs.org/blog/next-9-1#public-directory-support 125 | 126 | # public 127 | 128 | # vuepress build output 129 | 130 | .vuepress/dist 131 | 132 | # vuepress v2.x temp and cache directory 133 | 134 | .temp 135 | .cache 136 | 137 | # Docusaurus cache and generated files 138 | 139 | .docusaurus 140 | 141 | # Serverless directories 142 | 143 | .serverless/ 144 | 145 | # FuseBox cache 146 | 147 | .fusebox/ 148 | 149 | # DynamoDB Local files 150 | 151 | .dynamodb/ 152 | 153 | # TernJS port file 154 | 155 | .tern-port 156 | 157 | # Stores VSCode versions used for testing VSCode extensions 158 | 159 | .vscode-test 160 | 161 | # yarn v2 162 | 163 | .yarn/cache 164 | .yarn/unplugged 165 | .yarn/build-state.yml 166 | .yarn/install-state.gz 167 | .pnp.\* 168 | 169 | # wrangler project 170 | 171 | .dev.vars 172 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, 15 | "lib": [ 16 | "es2021" 17 | ] /* Specify a set of bundled library declaration files that describe the target runtime environment. */, 18 | "jsx": "react" /* Specify what JSX code is generated. */, 19 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 20 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 21 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ 22 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 23 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ 24 | // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ 25 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 26 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 27 | 28 | /* Modules */ 29 | "module": "es2022" /* Specify what module code is generated. */, 30 | // "rootDir": "./", /* Specify the root folder within your source files. */ 31 | "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, 32 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 33 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 34 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 35 | // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ 36 | "types": [ 37 | "@cloudflare/workers-types", 38 | "jest" 39 | ] /* Specify type package names to be included without being referenced in a source file. */, 40 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 41 | "resolveJsonModule": true /* Enable importing .json files */, 42 | // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ 43 | 44 | /* JavaScript Support */ 45 | "allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */, 46 | "checkJs": false /* Enable error reporting in type-checked JavaScript files. */, 47 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ 48 | 49 | /* Emit */ 50 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 51 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 52 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 53 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 54 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ 55 | // "outDir": "./", /* Specify an output folder for all emitted files. */ 56 | // "removeComments": true, /* Disable emitting comments. */ 57 | "noEmit": true /* Disable emitting files from a compilation. */, 58 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 59 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ 60 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 61 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 62 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 63 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 64 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 65 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 66 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 67 | // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ 68 | // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ 69 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 70 | // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ 71 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 72 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 73 | 74 | /* Interop Constraints */ 75 | "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */, 76 | "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */, 77 | // "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, 78 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 79 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, 80 | 81 | /* Type Checking */ 82 | "strict": true /* Enable all strict type-checking options. */, 83 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ 84 | // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ 85 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 86 | // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ 87 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 88 | // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ 89 | // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ 90 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 91 | // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ 92 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ 93 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 94 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 95 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 96 | // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ 97 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 98 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ 99 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 100 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 101 | 102 | /* Completeness */ 103 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 104 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/html.ts: -------------------------------------------------------------------------------- 1 | //create an exportable string 2 | export const html = (url: String) =>{ 3 | return ` 4 | 5 | 6 | 7 | Tut Linker - Generate SEO friendly mastodon links 8 | 9 | 10 | 11 | 12 | 43 | 54 | 55 | 56 |
57 | 58 |
59 |
60 |
61 |

Tut Linker

62 |
63 |
64 |

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 |

70 |
    71 |
  • 72 | 73 | 74 | 75 | 76 |
    77 | 78 |
    79 | http:// 80 | 81 |
    82 |
    83 |
  • 84 |
  • 85 | 86 | 87 | 88 | 89 |
    90 | 91 |
    92 |
    93 | 94 | 95 | 96 | 97 |
    98 | 99 |
    100 |
    101 |
  • 102 |
  • 103 | 104 | 105 | 106 | 107 |

    Click "copy" and an unbannable link will be generated

    108 |
  • 109 |
110 |
111 | 112 |
113 |
114 |
115 | 116 | 117 | 118 | 119 |
120 | 121 |
122 | 129 | 136 |
137 |
138 | 139 |
140 | 143 |
144 | About 145 |
146 |
147 |
Built with cloudflare workers so anyone can Deploy to CloudFlare their own version, on their own domain if they want to.
148 | Twitter Follow 149 | Mastodon Follow 150 | Github 151 |
152 |
153 |
154 |
155 |
156 | 157 | 158 | 159 | 160 | 161 | ` 162 | } --------------------------------------------------------------------------------