diff --git a/src/Mastodon.ts b/src/Mastodon.ts index 755725e..39b57e4 100644 --- a/src/Mastodon.ts +++ b/src/Mastodon.ts @@ -186,16 +186,12 @@ ${text.split("\n").map(txt => " > " + txt).join("\n")}`) return overview.length + rest.join("\n").length + 1 } - private static notMastodon = ["wiki.openstreetmap.org", "hdyc.neis-one.org", "matrix.to","facebook.com","github", "tasks.hotosm.org","community.openstreetmap.org","mapillary.com","wikimedia.org","wikipedia.org","wikidata.org"] - private static isMastodon = ["en.osm.town", ".social", "mstdn", "mastodon", "mapstodon","masto"] + // Fediverse profiles look like this: + // Mastodon, Akkoma, etc.: https://foo.bar/@user + // Friendica: https://foo.bar/profile/user + private static isProbablyMastodon = new RegExp("^https?://[^/]+/(profile/|@)[^/]+/?$") static isProbablyMastodonLink(link: string) { - if (this.isMastodon.some(white => link.indexOf(white) >= 0)) { - return true - } - if (this.notMastodon.some(black => link.indexOf(black) >= 0)) { - return false - } - return true; // probably? + return this.isProbablyMastodon.test(link) } -} \ No newline at end of file +} diff --git a/src/test.ts b/src/test.ts index 7996b27..9b1731b 100644 --- a/src/test.ts +++ b/src/test.ts @@ -3,10 +3,21 @@ import MastodonPoster from "./Mastodon"; console.log("Hello world") +const uids = [ + 1214300, // tornooc + 4685130, // contrapunctus + 8404193, // queerthoughts + 153277, // rompe +] -new OsmUserInfo(1214300).getMeLinks().then(links => { - console.log("Got links:", links); +for (const uid of uids) { + new OsmUserInfo(uid).getMeLinks().then((links) => { + console.log("Got links for uid", uid, ":", links); for (const link of links) { - console.log(link, MastodonPoster.isProbablyMastodonLink(link) ? "Mastodon" : "NOT mastodon") + console.log( + link, + MastodonPoster.isProbablyMastodonLink(link) ? "Mastodon" : "NOT mastodon" + ); } -}) \ No newline at end of file + }); +}