phanpy/src/utils/isMastodonLinkMaybe.jsx

18 lines
749 B
React
Raw Normal View History

2023-04-22 19:55:47 +03:00
export default function isMastodonLinkMaybe(url) {
2023-12-03 15:40:00 +03:00
try {
2024-07-21 14:06:38 +03:00
const { pathname, hash, hostname } = URL.parse(url);
2023-12-03 15:40:00 +03:00
return (
/^\/.*\/\d+$/i.test(pathname) ||
/^\/(@[^/]+|users\/[^/]+)\/(statuses|posts)\/\w+\/?$/i.test(pathname) || // GoToSocial, Takahe
2023-12-03 15:40:00 +03:00
/^\/notes\/[a-z0-9]+$/i.test(pathname) || // Misskey, Firefish
/^\/(notice|objects)\/[a-z0-9-]+$/i.test(pathname) || // Pleroma
2024-09-02 16:00:10 +03:00
/^\/@[^/]+\/post\/[a-z0-9\-_]+$/i.test(pathname) || // Threads
2024-07-05 11:19:04 +03:00
/^\/@[^/]+\/[a-z0-9]+[a-z0-9\-]+[a-z0-9]+$/i.test(pathname) || // Hollo
2024-07-21 14:06:38 +03:00
(hostname === 'fed.brid.gy' && pathname.startsWith('/r/http')) || // Bridgy Fed
2023-12-03 15:40:00 +03:00
/#\/[^\/]+\.[^\/]+\/s\/.+/i.test(hash) // Phanpy 🫣
);
} catch (e) {
return false;
}
2023-04-22 19:55:47 +03:00
}