lartsch 2022-12-03 05:43:07 -05:00
commit 877c074434
2 zmienionych plików z 14 dodań i 20 usunięć

Wyświetl plik

@ -31,7 +31,7 @@ A Chrome/Firefox extension that simplifies following and post interactions on ot
[link-chrome]: https://chrome.google.com/webstore/detail/fedifollow/lmpcajpkjcclkjbliapfjfolocffednm 'Version published on Chrome Web Store'
[link-firefox]: https://addons.mozilla.org/en-US/firefox/addon/fedifollow/ 'Version published on Mozilla Add-ons'
[<img src="https://raw.githubusercontent.com/alrra/browser-logos/90fdf03c/src/chrome/chrome.svg" width="48" alt="Chrome" valign="middle">][link-chrome] [<img valign="middle" src="https://img.shields.io/chrome-web-store/v/lmpcajpkjcclkjbliapfjfolocffednm.svg?label=%20">][link-chrome] and other Chromium browsers
[<img src="https://raw.githubusercontent.com/alrra/browser-logos/90fdf03c/src/chrome/chrome.svg" width="48" alt="Chrome" valign="middle">][link-chrome] [<img valign="middle" src="https://img.shields.io/chrome-web-store/v/lmpcajpkjcclkjbliapfjfolocffednm.svg?label=%20">][link-chrome] and other Chromium browsers (v0.8.0 in review)
[<img src="https://raw.githubusercontent.com/alrra/browser-logos/90fdf03c/src/firefox/firefox.svg" width="48" alt="Firefox" valign="middle">][link-firefox] [<img valign="middle" src="https://img.shields.io/amo/v/fedifollow.svg?label=%20">][link-firefox] including Firefox for Android
@ -93,7 +93,7 @@ I included all of the default add-ons in the custom collection, so you will not
## Additional notes
1. Currently supports external Mastodon instances v3 + v4
- I have not tested if Mastodon v3 works as home instance! In general, Mastodon v4 support is the main objective.
- **I have not tested if Mastodon v3 works as home instance! In general, Mastodon v4 support is the main objective.**
- Support for other Fedi software is still planned
2. The whitelist mode can be useful if you do not want the extension to run basic checks on every site (since it needs to determine if it is a Mastodon site). Not sure if the blacklist feature is good for anything but I still included it.
3. It can have several reasons why resolving/executing actions/redirection might not work:
@ -107,6 +107,7 @@ I included all of the default add-ons in the custom collection, so you will not
7. If the extension fails to resolve content, the affected buttons will behave like usually
## Todos / Planned features
- Add support for bookmarking, replying
- Fix last remaining resolve fails
- General performance improvements
- Improve 429 prevention and add fallbacks

Wyświetl plik

@ -2,8 +2,6 @@
// =-=-=-=-=-= CONSTANTS =-==-=-=-=
// =-=-=-=-==-=-=-=-==-=-=-=-==-=-=
//const tootButtonsPaths = ["div.status__action-bar button:not(.disabled):not(:has(i.fa-share-alt))","div.detailed-status__action-bar button:not(.disabled):not(:has(i.fa-share-alt))","div.status__action-bar a.modal-button","a.detailed-status__link"];
//const appHolderPaths = ["body > div.app-holder", "body > div.public-layout"];
const followButtonPaths = ["div.account__header button.logo-button","div.public-account-header a.logo-button","div.account-card a.logo-button","div.directory-card a.icon-button", "div.detailed-status a.logo-button"];
const profileNamePaths = ["div.account__header__tabs__name small", "div.public-account-header__tabs__name small", "div.detailed-status span.display-name__account", "div.display-name > span"];
const domainRegex = /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/;
@ -36,7 +34,7 @@ const settingsDefaults = {
fedifollow_enabledelay: true
}
// fix for cross-browser storage api compatibility and global settings var
// fix for cross-browser storage api compatibility and other global vars
var browser, chrome, lasthomerequest;
var lastUrl = window.location.href;
@ -52,6 +50,9 @@ function log(text) {
}
}
// Custom solution for detecting inserted nodes
// Works in combination with nodeinserted.css (fixes Firefox blocking addon-inserted <style> elements for sites with CSP)
// Is more reliable in certain situation than mutationobserver
(function($) {
$.fn.DOMNodeAppear = function(callback, selector) {
var $this = $(this)
@ -111,27 +112,17 @@ async function makeRequest(method, url, extraheaders) {
});
}
// extract given url parameter value
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'), sParameterName, i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
return false;
};
// Escape characters used for regex
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
// Replace all occurrences of a substring
function replaceAll(str, find, replace) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}
// handles redirects to home instance
function redirectTo(url) {
if (settings.fedifollow_redirects) {
if (settings.fedifollow_alert) {
@ -312,6 +303,7 @@ async function isFollowingHomeInstance(ids) {
// =-=-=-=-=-= RESOLVING =-=-==-=-=
// =-=-=-=-==-=-=-=-==-=-=-=-==-=-=
// Return the user id on the home instance
async function resolveHandleToHome(handle) {
var requestUrl = 'https://' + settings.fedifollow_homeinstance + accountsApi + "/search?q=" + handle
var searchResponse = await makeRequest("GET",requestUrl,settings.tokenheader)
@ -324,6 +316,7 @@ async function resolveHandleToHome(handle) {
return false
}
// Get a toot's (external) home instance url
function resolveTootToExternalHome(tooturl) {
if (tooturl) {
return new Promise(resolve => {
@ -969,4 +962,4 @@ async function run() {
}
}
run()
run()