Skip to content

Commit

Permalink
ClickableBioLinks -> BetterBios: Now makes bio selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
Vendicated committed May 6, 2023
1 parent a6de431 commit dd6b1a9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
8 changes: 4 additions & 4 deletions plugins/ClickableBioLinks/manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "ClickableBioLinks",
"description": "Makes links in bios clickable",
"name": "BetterBios",
"description": "Makes bio text selectable and links in them clickable",
"authors": [
{
"name": "Vendicated",
"id": "343383572805058560"
}
],
"main": "src/index.ts",
"main": "src/index.tsx",
"vendetta": {
"icon": "ic_link"
"icon": "ic_profile_24px"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { findByNameAll, findByProps } from "@vendetta/metro";
import { url as URLOpener } from "@vendetta/metro/common";
import { ReactNative, url as URLOpener, clipboard } from "@vendetta/metro/common";
import { after } from "@vendetta/patcher";
import { storage } from "@vendetta/plugin";
import { getAssetIDByName } from "@vendetta/ui/assets";
import { showToast } from "@vendetta/ui/toasts";

function lazy<T>(fn: () => T) {
let v: T;
return () => v ??= fn();
}

const findActionShitter = lazy(() => findByProps("hideActionSheet"));
const findClipboardAsset = lazy(() => getAssetIDByName("ic_message_copy"));

const ActionShitter = findByProps("hideActionSheet");
const ups = [];

function walkReactTree(root: any, visit: (node: any) => void) {
Expand All @@ -23,9 +32,12 @@ function walkReactTree(root: any, visit: (node: any) => void) {

// WHY DOES DISCORD HAVE TWO OF THESE IM GONNA EXPLODE
for (const BioText of findByNameAll("BioText", false)) {
const up = after("default", BioText, (_, res) => {
const up = after("default", BioText, ([props], res) => {
if (!res?.props?.children) return;

// make bio text selectable
res.props.selectable = true;

walkReactTree(res, node => {
if (node.props?.accessibilityRole === "link") {
const url = node.props.children?.[0];
Expand All @@ -34,10 +46,21 @@ for (const BioText of findByNameAll("BioText", false)) {
node.props.onPress = () => {
URLOpener.openURL(url);
if (storage.dismiss !== false)
ActionShitter.hideActionSheet();
findActionShitter().hideActionSheet();
};
}
});

return;
// explode
return (
<ReactNative.Pressable onLongPress={() => {
clipboard.setString(props.bio);
showToast("Copied bio to clipboard", findClipboardAsset());
}}>
{res}
</ReactNative.Pressable>
);
});

ups.push(up);
Expand Down

0 comments on commit dd6b1a9

Please sign in to comment.