This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for /explore redirect, fixes #3
- Loading branch information
Showing
4 changed files
with
58 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ var chrome; | |
// If someone knows a better way to detect Mastodon4 instances, please send me a message! | ||
// [email protected] | ||
const MASTODON_DIV = document.getElementById("mastodon"); | ||
const EXTERNAL_USER_REGEX = /(@[a-zA-Z0-9_]+)(?!.*@)/; // @username matches, @[email protected] doesn't | ||
const EXTERNAL_USER_REGEX = /^(@[a-zA-Z0-9_]+)(?!.*@)(?!\/.+)$/; // @username matches, @[email protected] @username/following doesn't | ||
const EXTERNAL_POST_REGEX = /(@[a-zA-Z0-9_]+)(?!.*@)\/(\d+)/; // @username matches, @[email protected] doesn't | ||
|
||
if (MASTODON_DIV) { | ||
|
@@ -29,7 +29,23 @@ if (MASTODON_DIV) { | |
) { | ||
return; // Disabled | ||
} | ||
// Match users and posts and redirect if needed | ||
// Lets first parse some generic URLs out of the way | ||
// For example: /explore -> /home | ||
// Using switch case if there comes more pages that this should be done to | ||
if ( | ||
item.redirectExplore == null && | ||
item.redirectExplore == "true" && | ||
item.redirectExplore === true | ||
) { | ||
switch (window.location.pathname) { | ||
case "/explore": | ||
url.pathname = "/home"; | ||
window.location.replace(url.toString()); | ||
break; | ||
} | ||
} | ||
|
||
// Then use Regex to find if a page is a user or a post | ||
if (window.location.pathname.match(EXTERNAL_POST_REGEX)) { | ||
url.pathname = `/authorize_interaction`; | ||
url.searchParams.set("uri", window.location.href); | ||
|
@@ -61,6 +77,10 @@ if (MASTODON_DIV) { | |
); | ||
} | ||
|
||
const getting = (browser || chrome).storage.sync.get(["url", "enabled"]); | ||
const getting = (browser || chrome).storage.sync.get([ | ||
"url", | ||
"enabled", | ||
"redirectExplore", | ||
]); | ||
getting.then(onGot, onError); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ var chrome; | |
// If someone knows a better way to detect Mastodon4 instances, please send me a message! | ||
// [email protected] | ||
const MASTODON_DIV = document.getElementById("mastodon"); | ||
const EXTERNAL_USER_REGEX = /(@[a-zA-Z0-9_]+)(?!.*@)/; // @username matches, @[email protected] doesn't | ||
const EXTERNAL_USER_REGEX = /^(@[a-zA-Z0-9_]+)(?!.*@)(?!\/.+)$/; // @username matches, @[email protected] @username/following doesn't | ||
const EXTERNAL_POST_REGEX = /(@[a-zA-Z0-9_]+)(?!.*@)\/(\d+)/; // @username matches, @[email protected] doesn't | ||
|
||
if (MASTODON_DIV) { | ||
|
@@ -29,7 +29,23 @@ if (MASTODON_DIV) { | |
) { | ||
return; // Disabled | ||
} | ||
// Match users and posts and redirect if needed | ||
// Lets first parse some generic URLs out of the way | ||
// For example: /explore -> /home | ||
// Using switch case if there comes more pages that this should be done to | ||
if ( | ||
item.redirectExplore == null && | ||
item.redirectExplore == "true" && | ||
item.redirectExplore === true | ||
) { | ||
switch (window.location.pathname) { | ||
case "/explore": | ||
url.pathname = "/home"; | ||
window.location.replace(url.toString()); | ||
break; | ||
} | ||
} | ||
|
||
// Then use Regex to find if a page is a user or a post | ||
if (window.location.pathname.match(EXTERNAL_POST_REGEX)) { | ||
url.pathname = `/authorize_interaction`; | ||
url.searchParams.set("uri", window.location.href); | ||
|
@@ -61,6 +77,10 @@ if (MASTODON_DIV) { | |
); | ||
} | ||
|
||
const getting = (browser || chrome).storage.sync.get(["url", "enabled"]); | ||
const getting = (browser || chrome).storage.sync.get([ | ||
"url", | ||
"enabled", | ||
"redirectExplore", | ||
]); | ||
getting.then(onGot, onError); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters