Add support for redirecting GNU Social
This commit is contained in:
parent
21d4a1d4ef
commit
ba4b781c31
2 changed files with 65 additions and 3 deletions
|
@ -5,13 +5,20 @@
|
|||
*/
|
||||
|
||||
import {INTERACTION_TYPE} from "./data/INTERACTION_TYPE.js";
|
||||
|
||||
import * as MastodonDetect from "./Detect/Mastodon.js";
|
||||
import * as GnuSocialDetect from "./Detect/GnuSocial.js";
|
||||
|
||||
import * as MastodonRedirect from "./MastodonRedirect.js";
|
||||
|
||||
const FEDIVERSE_TYPE = Object.freeze({
|
||||
MASTODON: Symbol("mastodon"),
|
||||
GNU_SOCIAL: Symbol("GNU Social")
|
||||
});
|
||||
const FEDIVERSE_MODULE = Object.freeze({
|
||||
[FEDIVERSE_TYPE.MASTODON]: MastodonDetect,
|
||||
[FEDIVERSE_TYPE.GNU_SOCIAL]: GnuSocialDetect
|
||||
});
|
||||
|
||||
/**
|
||||
* Listens for Mastodon requests at tab update.
|
||||
|
@ -42,6 +49,9 @@ async function handleTabUpdate(tabId, changeInfo) {
|
|||
case FEDIVERSE_TYPE.MASTODON:
|
||||
detectModule = MastodonDetect;
|
||||
break;
|
||||
case FEDIVERSE_TYPE.GNU_SOCIAL:
|
||||
detectModule = GnuSocialDetect;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`unknown fediverse type: ${software.toString()}`);
|
||||
}
|
||||
|
@ -73,9 +83,11 @@ async function handleTabUpdate(tabId, changeInfo) {
|
|||
* @returns {[FEDIVERSE_TYPE, Symbol]|null}
|
||||
*/
|
||||
function getInteractionType(url) {
|
||||
for (const [checkRegEx, interactionType] of MastodonDetect.CATCH_URLS) {
|
||||
if (url.pathname.match(checkRegEx)) {
|
||||
return [FEDIVERSE_TYPE.MASTODON, interactionType];
|
||||
for (const fedType of Object.values(FEDIVERSE_TYPE)) {
|
||||
for (const [checkRegEx, interactionType] of FEDIVERSE_MODULE[fedType].CATCH_URLS) {
|
||||
if (url.pathname.match(checkRegEx)) {
|
||||
return [fedType, interactionType];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
50
src/background/modules/Detect/GnuSocial.js
Normal file
50
src/background/modules/Detect/GnuSocial.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Module, that detects a GNU Social instance and returns the required values.
|
||||
*
|
||||
* @module Detect/GnuSocial
|
||||
*/
|
||||
|
||||
import {NotSupportedError} from "/common/modules/Errors.js";
|
||||
import {INTERACTION_TYPE} from "../data/INTERACTION_TYPE.js";
|
||||
|
||||
// https://regex101.com/r/8vTzty/1
|
||||
const REMOTE_FOLLOW_REGEX = /\/main\/ostatus\/nickname\/(.+)\/?$/;
|
||||
|
||||
/** The URLs to intercept and pass to this module. */
|
||||
export const CATCH_URLS = new Map();
|
||||
CATCH_URLS.set(REMOTE_FOLLOW_REGEX, INTERACTION_TYPE.FOLLOW);
|
||||
|
||||
/**
|
||||
* Find the follow URL.
|
||||
*
|
||||
* @function
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function getTootUrl() {
|
||||
throw new NotSupportedError("getTootUrl() is not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username of the given OStatus page.
|
||||
*
|
||||
* @private
|
||||
* @function
|
||||
* @param {URL} url
|
||||
* @returns {string|undefined}
|
||||
*/
|
||||
export function getUsername(url) {
|
||||
const match = REMOTE_FOLLOW_REGEX.exec(url.pathname);
|
||||
return match[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the server from the required URL.
|
||||
*
|
||||
* @function
|
||||
* @param {URL} url
|
||||
* @returns {string|undefined}
|
||||
*/
|
||||
export function getServer(url) {
|
||||
return url.host;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue