* Fix ImplicitRelationships * performance fixes * fix false pos * fix super reaction tweaks * Fix PermissionFreeWill * Fix AlwaysTrust * clean ups * Fix ImageLink * Fix ValidReply * Fix ShowHiddenChannels partially and race conditions related to exports * fix bucnh of webpack finds * Fix FriendsSince, RevealAllSpoilers * finish show hidden channels * read if cute * doomsday fix: ClientTheme (#2597) * fix friendinvites * fix extractAndLoadChunks * bleh * fix FakeNitro * fake nitro part 2 * and part 3 * bump to v1.9.0 * remove dead settings patch * fix ForceOwnerCrown * fix decor lazy load --------- Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Co-authored-by: rushii <33725716+rushiiMachine@users.noreply.github.com>
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
/*
|
|
* Vencord, a Discord client mod
|
|
* Copyright (c) 2023 Vendicated and contributors
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
import { Devs } from "@utils/constants.js";
|
|
import definePlugin from "@utils/types";
|
|
import { findByPropsLazy } from "@webpack";
|
|
|
|
const linkRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
|
|
|
const SlateTransforms = findByPropsLazy("insertText", "selectCommandOption");
|
|
|
|
export default definePlugin({
|
|
name: "MaskedLinkPaste",
|
|
authors: [Devs.TheSun],
|
|
description: "Pasting a link while having text selected will paste a hyperlink",
|
|
patches: [
|
|
{
|
|
find: ".selection,preventEmojiSurrogates:",
|
|
replacement: {
|
|
match: /(?<=\i.delete.{0,50})(\i)\.insertText\((\i)\)/,
|
|
replace: "$self.handlePaste($1, $2, () => $&)"
|
|
}
|
|
}
|
|
],
|
|
|
|
handlePaste(editor, content: string, originalBehavior: () => void) {
|
|
if (content && linkRegex.test(content) && editor.operations?.[0]?.type === "remove_text") {
|
|
SlateTransforms.insertText(
|
|
editor,
|
|
`[${editor.operations[0].text}](${content})`
|
|
);
|
|
}
|
|
else originalBehavior();
|
|
}
|
|
});
|