Merge pull request #99 from austinhuang0131/master
Improve Pleroma support
This commit is contained in:
commit
0f53bfff21
3 changed files with 19 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
|||
# Contributors
|
||||
|
||||
- Austin Huang ([@austinhuang0131](https://github.com/austinhuang0131))
|
||||
- [@ENT8R](https://github.com/ENT8R)
|
||||
- Chao Zhang ([@zhang1pr](https://github.com/zhang1pr))
|
||||
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue