diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 705b19c..5e81fe0 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,5 +1,6 @@ # Contributors +- Austin Huang ([@austinhuang0131](https://github.com/austinhuang0131)) - [@ENT8R](https://github.com/ENT8R) - Chao Zhang ([@zhang1pr](https://github.com/zhang1pr)) diff --git a/src/background/modules/AutoRemoteFollow.js b/src/background/modules/AutoRemoteFollow.js index b06a5be..abac24f 100644 --- a/src/background/modules/AutoRemoteFollow.js +++ b/src/background/modules/AutoRemoteFollow.js @@ -135,7 +135,7 @@ async function handleError(error) { function getInteractionType(url) { for (const fedType of Object.values(FEDIVERSE_TYPE)) { for (const [checkRegEx, interactionType] of FEDIVERSE_MODULE[fedType].CATCH_URLS) { - if (url.pathname.match(checkRegEx)) { + if (url.href.match(checkRegEx)) { return [fedType, interactionType]; } } @@ -170,7 +170,7 @@ async function onTabUpdate(tabId, changeInfo) { function init() { NetworkTools.webRequestListen(["http://*/*", "https://*/*"], "onBeforeRequest", (requestDetails) => { return handleWebRequest(requestDetails).catch(handleError).catch(console.error); - }); + }, ["requestBody"]); browser.tabs.onUpdated.addListener(onTabUpdate, { properties: ["url"] diff --git a/src/background/modules/Detect/Pleroma.js b/src/background/modules/Detect/Pleroma.js index 07275b9..cf894d4 100644 --- a/src/background/modules/Detect/Pleroma.js +++ b/src/background/modules/Detect/Pleroma.js @@ -5,7 +5,6 @@ */ import * as NetworkTools from "/common/modules/NetworkTools.js"; -import {NotSupportedError} from "/common/modules/Errors.js"; import {INTERACTION_TYPE} from "../data/INTERACTION_TYPE.js"; import isString from "/common/modules/lodash/isString.js"; @@ -13,9 +12,12 @@ import isString from "/common/modules/lodash/isString.js"; const REMOTE_FOLLOW_REGEX = /\/main\/ostatus\/?$/; // https://regex101.com/r/fjPdgC/1 const USER_PAGE_URL_REGEX = /\/users\/(.+)\/?$/; +// really just REMOTE_FOLLOW_REGEX with status_id query +const REMOTE_INTERACT_REGEX = /\/main\/ostatus\/?\?status_id=\w+$/; /** The URLs to intercept and pass to this module. */ export const CATCH_URLS = new Map(); +CATCH_URLS.set(REMOTE_INTERACT_REGEX, INTERACTION_TYPE.TOOT_INTERACT); CATCH_URLS.set(REMOTE_FOLLOW_REGEX, INTERACTION_TYPE.FOLLOW); /** @@ -84,13 +86,16 @@ export function getTabToModify(requestDetails) { } /** - * Find the follow URL. + * Find the status URL. * * @public + * @param {URL} url * @returns {Promise} */ -export function getTootUrl() { - throw new NotSupportedError("getTootUrl() is not supported"); +export function getTootUrl(url) { + return new Promise((resolve, reject) => { + resolve(`https://${url.host}/notice/{url.searchParams.get("status_id")}`); + }); } /** @@ -105,6 +110,12 @@ export function getTootUrl() { export function getUsername(url, requestDetails) { redirectSiteFinishedLoading = false; + try { + return requestDetails.requestBody.formData.nickname[0]; + } catch (e) { + console.error("Could not get username from request body. Error: ", e); + } + try { const originUrl = new URL(requestDetails.originUrl); const match = USER_PAGE_URL_REGEX.exec(originUrl.pathname); @@ -117,7 +128,7 @@ export function getUsername(url, requestDetails) { console.error("Could not get valid username from request details. Got", originUrl, "from", requestDetails); } } catch (e) { - console.error("Could not get username from request details. Error: ", e); + console.error("Could not get username from request origin. Error: ", e); } // fallback to HTML scraping