phanpy/src/utils/isMastodonLinkMaybe.jsx

16 lines
572 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-06-14 03:34:50 +03:00
const { pathname, hash } = 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
/^\/@[^/]+\/post\/[a-z0-9]+$/i.test(pathname) || // Threads
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
}