Merge pull request #99 from austinhuang0131/master

Improve Pleroma support
This commit is contained in:
rugk 2023-03-12 16:41:39 +01:00 committed by GitHub
commit 0f53bfff21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View file

@ -1,5 +1,6 @@
# Contributors # Contributors
- Austin Huang ([@austinhuang0131](https://github.com/austinhuang0131))
- [@ENT8R](https://github.com/ENT8R) - [@ENT8R](https://github.com/ENT8R)
- Chao Zhang ([@zhang1pr](https://github.com/zhang1pr)) - Chao Zhang ([@zhang1pr](https://github.com/zhang1pr))

View file

@ -135,7 +135,7 @@ async function handleError(error) {
function getInteractionType(url) { function getInteractionType(url) {
for (const fedType of Object.values(FEDIVERSE_TYPE)) { for (const fedType of Object.values(FEDIVERSE_TYPE)) {
for (const [checkRegEx, interactionType] of FEDIVERSE_MODULE[fedType].CATCH_URLS) { for (const [checkRegEx, interactionType] of FEDIVERSE_MODULE[fedType].CATCH_URLS) {
if (url.pathname.match(checkRegEx)) { if (url.href.match(checkRegEx)) {
return [fedType, interactionType]; return [fedType, interactionType];
} }
} }
@ -170,7 +170,7 @@ async function onTabUpdate(tabId, changeInfo) {
function init() { function init() {
NetworkTools.webRequestListen(["http://*/*", "https://*/*"], "onBeforeRequest", (requestDetails) => { NetworkTools.webRequestListen(["http://*/*", "https://*/*"], "onBeforeRequest", (requestDetails) => {
return handleWebRequest(requestDetails).catch(handleError).catch(console.error); return handleWebRequest(requestDetails).catch(handleError).catch(console.error);
}); }, ["requestBody"]);
browser.tabs.onUpdated.addListener(onTabUpdate, { browser.tabs.onUpdated.addListener(onTabUpdate, {
properties: ["url"] properties: ["url"]

View file

@ -5,7 +5,6 @@
*/ */
import * as NetworkTools from "/common/modules/NetworkTools.js"; import * as NetworkTools from "/common/modules/NetworkTools.js";
import {NotSupportedError} from "/common/modules/Errors.js";
import {INTERACTION_TYPE} from "../data/INTERACTION_TYPE.js"; import {INTERACTION_TYPE} from "../data/INTERACTION_TYPE.js";
import isString from "/common/modules/lodash/isString.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\/?$/; const REMOTE_FOLLOW_REGEX = /\/main\/ostatus\/?$/;
// https://regex101.com/r/fjPdgC/1 // https://regex101.com/r/fjPdgC/1
const USER_PAGE_URL_REGEX = /\/users\/(.+)\/?$/; 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. */ /** The URLs to intercept and pass to this module. */
export const CATCH_URLS = new Map(); 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); 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 * @public
* @param {URL} url
* @returns {Promise} * @returns {Promise}
*/ */
export function getTootUrl() { export function getTootUrl(url) {
throw new NotSupportedError("getTootUrl() is not supported"); 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) { export function getUsername(url, requestDetails) {
redirectSiteFinishedLoading = false; redirectSiteFinishedLoading = false;
try {
return requestDetails.requestBody.formData.nickname[0];
} catch (e) {
console.error("Could not get username from request body. Error: ", e);
}
try { try {
const originUrl = new URL(requestDetails.originUrl); const originUrl = new URL(requestDetails.originUrl);
const match = USER_PAGE_URL_REGEX.exec(originUrl.pathname); 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); console.error("Could not get valid username from request details. Got", originUrl, "from", requestDetails);
} }
} catch (e) { } 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 // fallback to HTML scraping