This commit is contained in:
ewin 2025-09-22 10:18:29 -04:00
parent 725cae593c
commit b9b71ebf56
Signed by: erin
SSH key fingerprint: SHA256:swjoHhREbZPbWe+gyJNi24d4NAxJSyUIm3fpZj4z3wc

14
fix.mjs
View file

@ -2,11 +2,11 @@ import {createServer} from 'node:http';
const sites = [
{
pattern: /^(?:https?:\/\/)?(?:www\.)pixiv\.net\/\w+\/artworks\/(\d+)(?:#(\d+))?/i,
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: /^(?:https?:\/\/)?(?:www\.)?(?:twitter\.com|x\.com)\/(.+)/,
pattern: /^(?:www\.)?(?:twitter\.com|x\.com)\/(.+)/,
redirect: match => `https://fxtwitter.com/${match[1]}`,
},
// idk send me more of these
@ -15,8 +15,14 @@ const sites = [
createServer(async (request, response) => {
const error = () => response.writeHead(400).end('whar');
if (request.method !== 'GET') return error();
const input = request.url.slice(1);
console.log(input);
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).end('https://git.ewin.moe/erin/fix-my-shit');
}
for (const site of sites) {
let match = input.match(site.pattern);
if (!match) continue;