fix-my-shit/fix.mjs
2025-09-23 15:13:20 +00:00

33 lines
1.1 KiB
JavaScript

import {createServer} from 'node:http';
const sites = [
{
pattern: /^(?:www\.)pixiv\.net\/\w+\/artworks\/(\d+)(?:#(\d+))?/i,
redirect: match => `https://pixiv.kmn5.li/${match[1]}${match[2] ? `_${parseInt(match[2], 10) - 1}` : ''}`,
},
{
pattern: /^(?:www\.)?(?:twitter\.com|x\.com)\/(.+)/,
redirect: match => `https://fxtwitter.com/${match[1]}`,
},
// idk send me more of these
];
createServer(async (request, response) => {
const error = () => response.writeHead(400).end('whar');
if (request.method !== 'GET') return error();
let input = request.url.slice(1); // leading slash
if (input.startsWith('https://')) {
input = input.slice(8);
} else if (input.startsWith('http://')) {
input = input.slice(7);
} else if (!input) { // "homepage"
return response.writeHead(301, {'Location': 'https://git.ewin.moe/erin/fix-my-shit'}).end();
}
for (const site of sites) {
let match = input.match(site.pattern);
if (!match) continue;
response.writeHead(302, {'Location': site.redirect(match)}).end();
return;
}
return error();
}).listen(process.env.PORT || 80);