Compare commits
No commits in common. "0e701a06d0bc593b2f21d2b37905296647ece0fd" and "605f0fd9f3c9b4f252b18019153515c7ad4c7c75" have entirely different histories.
0e701a06d0
...
605f0fd9f3
29 changed files with 467 additions and 534 deletions
|
@ -1,12 +1,6 @@
|
||||||
{
|
{
|
||||||
"extends": "stylelint-config-standard",
|
"extends": "stylelint-config-standard",
|
||||||
"rules": {
|
"rules": {
|
||||||
"indentation": 4,
|
"indentation": 4
|
||||||
"selector-class-pattern": [
|
|
||||||
"^[a-z][a-zA-Z0-9]*(-[a-z0-9][a-zA-Z0-9]*)*$",
|
|
||||||
{
|
|
||||||
"message": "Expected class selector to be kebab-case with camelCase segments"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "vencord",
|
"name": "vencord",
|
||||||
"private": "true",
|
"private": "true",
|
||||||
"version": "1.9.4",
|
"version": "1.9.3",
|
||||||
"description": "The cutest Discord client mod",
|
"description": "The cutest Discord client mod",
|
||||||
"homepage": "https://github.com/Vendicated/Vencord#readme",
|
"homepage": "https://github.com/Vendicated/Vencord#readme",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
|
|
@ -392,21 +392,6 @@ export function PaintbrushIcon(props: IconProps) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PencilIcon(props: IconProps) {
|
|
||||||
return (
|
|
||||||
<Icon
|
|
||||||
{...props}
|
|
||||||
className={classes(props.className, "vc-pencil-icon")}
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
fill="currentColor"
|
|
||||||
d="m13.96 5.46 4.58 4.58a1 1 0 0 0 1.42 0l1.38-1.38a2 2 0 0 0 0-2.82l-3.18-3.18a2 2 0 0 0-2.82 0l-1.38 1.38a1 1 0 0 0 0 1.42ZM2.11 20.16l.73-4.22a3 3 0 0 1 .83-1.61l7.87-7.87a1 1 0 0 1 1.42 0l4.58 4.58a1 1 0 0 1 0 1.42l-7.87 7.87a3 3 0 0 1-1.6.83l-4.23.73a1.5 1.5 0 0 1-1.73-1.73Z"
|
|
||||||
/>
|
|
||||||
</Icon>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const WebsiteIconDark = "/assets/e1e96d89e192de1997f73730db26e94f.svg";
|
const WebsiteIconDark = "/assets/e1e96d89e192de1997f73730db26e94f.svg";
|
||||||
const WebsiteIconLight = "/assets/730f58bcfd5a57a5e22460c445a0c6cf.svg";
|
const WebsiteIconLight = "/assets/730f58bcfd5a57a5e22460c445a0c6cf.svg";
|
||||||
const GithubIconLight = "/assets/3ff98ad75ac94fa883af5ed62d17c459.svg";
|
const GithubIconLight = "/assets/3ff98ad75ac94fa883af5ed62d17c459.svg";
|
||||||
|
|
|
@ -16,26 +16,24 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Settings, useSettings } from "@api/Settings";
|
import { useSettings } from "@api/Settings";
|
||||||
import { classNameFactory } from "@api/Styles";
|
import { classNameFactory } from "@api/Styles";
|
||||||
import { Flex } from "@components/Flex";
|
import { Flex } from "@components/Flex";
|
||||||
import { DeleteIcon, FolderIcon, PaintbrushIcon, PencilIcon, PlusIcon, RestartIcon } from "@components/Icons";
|
import { DeleteIcon } from "@components/Icons";
|
||||||
import { Link } from "@components/Link";
|
import { Link } from "@components/Link";
|
||||||
import { openPluginModal } from "@components/PluginSettings/PluginModal";
|
import PluginModal from "@components/PluginSettings/PluginModal";
|
||||||
import type { UserThemeHeader } from "@main/themes";
|
import type { UserThemeHeader } from "@main/themes";
|
||||||
import { openInviteModal } from "@utils/discord";
|
import { openInviteModal } from "@utils/discord";
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import { classes } from "@utils/misc";
|
import { classes } from "@utils/misc";
|
||||||
|
import { openModal } from "@utils/modal";
|
||||||
import { showItemInFolder } from "@utils/native";
|
import { showItemInFolder } from "@utils/native";
|
||||||
import { useAwaiter } from "@utils/react";
|
import { useAwaiter } from "@utils/react";
|
||||||
import { findByPropsLazy, findLazy } from "@webpack";
|
import { findByPropsLazy, findLazy } from "@webpack";
|
||||||
import { Card, Forms, React, showToast, TabBar, TextArea, useEffect, useRef, useState } from "@webpack/common";
|
import { Button, Card, Forms, React, showToast, TabBar, TextArea, useEffect, useRef, useState } from "@webpack/common";
|
||||||
import type { ComponentType, Ref, SyntheticEvent } from "react";
|
import type { ComponentType, Ref, SyntheticEvent } from "react";
|
||||||
|
|
||||||
import Plugins from "~plugins";
|
|
||||||
|
|
||||||
import { AddonCard } from "./AddonCard";
|
import { AddonCard } from "./AddonCard";
|
||||||
import { QuickAction, QuickActionCard } from "./quickActions";
|
|
||||||
import { SettingsTab, wrapTab } from "./shared";
|
import { SettingsTab, wrapTab } from "./shared";
|
||||||
|
|
||||||
type FileInput = ComponentType<{
|
type FileInput = ComponentType<{
|
||||||
|
@ -215,13 +213,14 @@ function ThemesTab() {
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Forms.FormSection title="Local Themes">
|
<Forms.FormSection title="Local Themes">
|
||||||
<QuickActionCard>
|
<Card className="vc-settings-quick-actions-card">
|
||||||
<>
|
<>
|
||||||
{IS_WEB ?
|
{IS_WEB ?
|
||||||
(
|
(
|
||||||
<QuickAction
|
<Button
|
||||||
text={
|
size={Button.Sizes.SMALL}
|
||||||
<span style={{ position: "relative" }}>
|
disabled={themeDirPending}
|
||||||
|
>
|
||||||
Upload Theme
|
Upload Theme
|
||||||
<FileInput
|
<FileInput
|
||||||
ref={fileInputRef}
|
ref={fileInputRef}
|
||||||
|
@ -229,38 +228,45 @@ function ThemesTab() {
|
||||||
multiple={true}
|
multiple={true}
|
||||||
filters={[{ extensions: ["css"] }]}
|
filters={[{ extensions: ["css"] }]}
|
||||||
/>
|
/>
|
||||||
</span>
|
</Button>
|
||||||
}
|
|
||||||
Icon={PlusIcon}
|
|
||||||
/>
|
|
||||||
) : (
|
) : (
|
||||||
<QuickAction
|
<Button
|
||||||
text="Open Themes Folder"
|
onClick={() => showItemInFolder(themeDir!)}
|
||||||
action={() => showItemInFolder(themeDir!)}
|
size={Button.Sizes.SMALL}
|
||||||
disabled={themeDirPending}
|
disabled={themeDirPending}
|
||||||
Icon={FolderIcon}
|
>
|
||||||
/>
|
Open Themes Folder
|
||||||
|
</Button>
|
||||||
)}
|
)}
|
||||||
<QuickAction
|
<Button
|
||||||
text="Load missing Themes"
|
onClick={refreshLocalThemes}
|
||||||
action={refreshLocalThemes}
|
size={Button.Sizes.SMALL}
|
||||||
Icon={RestartIcon}
|
>
|
||||||
/>
|
Load missing Themes
|
||||||
<QuickAction
|
</Button>
|
||||||
text="Edit QuickCSS"
|
<Button
|
||||||
action={() => VencordNative.quickCss.openEditor()}
|
onClick={() => VencordNative.quickCss.openEditor()}
|
||||||
Icon={PaintbrushIcon}
|
size={Button.Sizes.SMALL}
|
||||||
/>
|
>
|
||||||
|
Edit QuickCSS
|
||||||
|
</Button>
|
||||||
|
|
||||||
{Settings.plugins.ClientTheme.enabled && (
|
{Vencord.Settings.plugins.ClientTheme.enabled && (
|
||||||
<QuickAction
|
<Button
|
||||||
text="Edit ClientTheme"
|
onClick={() => openModal(modalProps => (
|
||||||
action={() => openPluginModal(Plugins.ClientTheme)}
|
<PluginModal
|
||||||
Icon={PencilIcon}
|
{...modalProps}
|
||||||
|
plugin={Vencord.Plugins.plugins.ClientTheme}
|
||||||
|
onRestartNeeded={() => { }}
|
||||||
/>
|
/>
|
||||||
|
))}
|
||||||
|
size={Button.Sizes.SMALL}
|
||||||
|
>
|
||||||
|
Edit ClientTheme
|
||||||
|
</Button>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
</QuickActionCard>
|
</Card>
|
||||||
|
|
||||||
<div className={cl("grid")}>
|
<div className={cl("grid")}>
|
||||||
{userThemes?.map(theme => (
|
{userThemes?.map(theme => (
|
||||||
|
|
|
@ -21,16 +21,15 @@ import { useSettings } from "@api/Settings";
|
||||||
import { classNameFactory } from "@api/Styles";
|
import { classNameFactory } from "@api/Styles";
|
||||||
import DonateButton from "@components/DonateButton";
|
import DonateButton from "@components/DonateButton";
|
||||||
import { openPluginModal } from "@components/PluginSettings/PluginModal";
|
import { openPluginModal } from "@components/PluginSettings/PluginModal";
|
||||||
import { gitRemote } from "@shared/vencordUserAgent";
|
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import { identity } from "@utils/misc";
|
import { identity } from "@utils/misc";
|
||||||
import { relaunch, showItemInFolder } from "@utils/native";
|
import { relaunch, showItemInFolder } from "@utils/native";
|
||||||
import { useAwaiter } from "@utils/react";
|
import { useAwaiter } from "@utils/react";
|
||||||
import { Button, Card, Forms, React, Select, Switch } from "@webpack/common";
|
import { Button, Card, Forms, React, Select, Switch, TooltipContainer } from "@webpack/common";
|
||||||
|
import { ComponentType } from "react";
|
||||||
|
|
||||||
import { Flex, FolderIcon, GithubIcon, LogIcon, PaintbrushIcon, RestartIcon } from "..";
|
import { Flex, FolderIcon, GithubIcon, LogIcon, PaintbrushIcon, RestartIcon } from "..";
|
||||||
import { openNotificationSettingsModal } from "./NotificationSettings";
|
import { openNotificationSettingsModal } from "./NotificationSettings";
|
||||||
import { QuickAction, QuickActionCard } from "./quickActions";
|
|
||||||
import { SettingsTab, wrapTab } from "./shared";
|
import { SettingsTab, wrapTab } from "./shared";
|
||||||
|
|
||||||
const cl = classNameFactory("vc-settings-");
|
const cl = classNameFactory("vc-settings-");
|
||||||
|
@ -42,6 +41,17 @@ type KeysOfType<Object, Type> = {
|
||||||
[K in keyof Object]: Object[K] extends Type ? K : never;
|
[K in keyof Object]: Object[K] extends Type ? K : never;
|
||||||
}[keyof Object];
|
}[keyof Object];
|
||||||
|
|
||||||
|
const iconWithTooltip = (Icon: ComponentType<{ className?: string; }>, tooltip: string) => () => (
|
||||||
|
<TooltipContainer text={tooltip}>
|
||||||
|
<Icon className={cl("quick-actions-img")} />
|
||||||
|
</TooltipContainer>
|
||||||
|
);
|
||||||
|
|
||||||
|
const NotificationLogIcon = iconWithTooltip(LogIcon, "Open Notification Log");
|
||||||
|
const QuickCssIcon = iconWithTooltip(PaintbrushIcon, "Edit QuickCSS");
|
||||||
|
const RelaunchIcon = iconWithTooltip(RestartIcon, "Relaunch Discord");
|
||||||
|
const OpenSettingsDirIcon = iconWithTooltip(FolderIcon, "Open Settings Directory");
|
||||||
|
const OpenGithubIcon = iconWithTooltip(GithubIcon, "View Vencord's GitHub Repository");
|
||||||
|
|
||||||
function VencordSettings() {
|
function VencordSettings() {
|
||||||
const [settingsDir, , settingsDirPending] = useAwaiter(VencordNative.settings.getSettingsDir, {
|
const [settingsDir, , settingsDirPending] = useAwaiter(VencordNative.settings.getSettingsDir, {
|
||||||
|
@ -101,37 +111,44 @@ function VencordSettings() {
|
||||||
<SettingsTab title="Vencord Settings">
|
<SettingsTab title="Vencord Settings">
|
||||||
<DonateCard image={donateImage} />
|
<DonateCard image={donateImage} />
|
||||||
<Forms.FormSection title="Quick Actions">
|
<Forms.FormSection title="Quick Actions">
|
||||||
<QuickActionCard>
|
<Card className={cl("quick-actions-card")}>
|
||||||
<QuickAction
|
<Button
|
||||||
Icon={LogIcon}
|
onClick={openNotificationLogModal}
|
||||||
text="Notification Log"
|
look={Button.Looks.BLANK}
|
||||||
action={openNotificationLogModal}
|
>
|
||||||
/>
|
<NotificationLogIcon />
|
||||||
<QuickAction
|
</Button>
|
||||||
Icon={PaintbrushIcon}
|
<Button
|
||||||
text="Edit QuickCSS"
|
onClick={() => VencordNative.quickCss.openEditor()}
|
||||||
action={() => VencordNative.quickCss.openEditor()}
|
look={Button.Looks.BLANK}
|
||||||
/>
|
>
|
||||||
|
<QuickCssIcon />
|
||||||
|
</Button>
|
||||||
{!IS_WEB && (
|
{!IS_WEB && (
|
||||||
<QuickAction
|
<Button
|
||||||
Icon={RestartIcon}
|
onClick={relaunch}
|
||||||
text="Relaunch Discord"
|
look={Button.Looks.BLANK}
|
||||||
action={relaunch}
|
>
|
||||||
/>
|
<RelaunchIcon />
|
||||||
|
</Button>
|
||||||
)}
|
)}
|
||||||
{!IS_WEB && (
|
{!IS_WEB && (
|
||||||
<QuickAction
|
<Button
|
||||||
Icon={FolderIcon}
|
onClick={() => showItemInFolder(settingsDir)}
|
||||||
text="Open Settings Folder"
|
look={Button.Looks.BLANK}
|
||||||
action={() => showItemInFolder(settingsDir)}
|
disabled={settingsDirPending}
|
||||||
/>
|
>
|
||||||
|
<OpenSettingsDirIcon />
|
||||||
|
</Button>
|
||||||
)}
|
)}
|
||||||
<QuickAction
|
<Button
|
||||||
Icon={GithubIcon}
|
onClick={() => VencordNative.native.openExternal("https://github.com/Vendicated/Vencord")}
|
||||||
text="View Source Code"
|
look={Button.Looks.BLANK}
|
||||||
action={() => VencordNative.native.openExternal("https://github.com/" + gitRemote)}
|
disabled={settingsDirPending}
|
||||||
/>
|
>
|
||||||
</QuickActionCard>
|
<OpenGithubIcon />
|
||||||
|
</Button>
|
||||||
|
</Card>
|
||||||
</Forms.FormSection>
|
</Forms.FormSection>
|
||||||
|
|
||||||
<Forms.FormDivider />
|
<Forms.FormDivider />
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
.vc-settings-quickActions-card {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(auto-fill, minmax(200px, max-content));
|
|
||||||
gap: 0.5em;
|
|
||||||
justify-content: center;
|
|
||||||
padding: 0.5em 0;
|
|
||||||
margin-bottom: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.vc-settings-quickActions-pill {
|
|
||||||
all: unset;
|
|
||||||
background: var(--background-secondary);
|
|
||||||
color: var(--header-secondary);
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5em;
|
|
||||||
padding: 8px 12px;
|
|
||||||
border-radius: 9999px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.vc-settings-quickActions-pill:hover {
|
|
||||||
background: var(--background-secondary-alt);
|
|
||||||
}
|
|
||||||
|
|
||||||
.vc-settings-quickActions-pill:focus-visible {
|
|
||||||
outline: 2px solid var(--focus-primary);
|
|
||||||
outline-offset: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.vc-settings-quickActions-img {
|
|
||||||
width: 24px;
|
|
||||||
height: 24px;
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/*
|
|
||||||
* Vencord, a Discord client mod
|
|
||||||
* Copyright (c) 2024 Vendicated and contributors
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
import "./quickActions.css";
|
|
||||||
|
|
||||||
import { classNameFactory } from "@api/Styles";
|
|
||||||
import { Card } from "@webpack/common";
|
|
||||||
import type { ComponentType, PropsWithChildren, ReactNode } from "react";
|
|
||||||
|
|
||||||
const cl = classNameFactory("vc-settings-quickActions-");
|
|
||||||
|
|
||||||
export interface QuickActionProps {
|
|
||||||
Icon: ComponentType<{ className?: string; }>;
|
|
||||||
text: ReactNode;
|
|
||||||
action?: () => void;
|
|
||||||
disabled?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function QuickAction(props: QuickActionProps) {
|
|
||||||
const { Icon, action, text, disabled } = props;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<button className={cl("pill")} onClick={action} disabled={disabled}>
|
|
||||||
<Icon className={cl("img")} />
|
|
||||||
{text}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function QuickActionCard(props: PropsWithChildren) {
|
|
||||||
return (
|
|
||||||
<Card className={cl("card")}>
|
|
||||||
{props.children}
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -10,6 +10,26 @@
|
||||||
margin-bottom: -2px;
|
margin-bottom: -2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vc-settings-quick-actions-card {
|
||||||
|
color: var(--text-normal);
|
||||||
|
padding: 1em;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
gap: 1em;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vc-settings-quick-actions-card button {
|
||||||
|
min-width: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vc-settings-quick-actions-img {
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
.vc-settings-donate {
|
.vc-settings-donate {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|
|
@ -16,34 +16,28 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { definePluginSettings } from "@api/Settings";
|
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
export default definePlugin({
|
||||||
|
name: "BANger",
|
||||||
|
description: "Replaces the GIF in the ban dialogue with a custom one.",
|
||||||
|
authors: [Devs.Xinto, Devs.Glitch],
|
||||||
|
patches: [
|
||||||
|
{
|
||||||
|
find: "BAN_CONFIRM_TITLE.",
|
||||||
|
replacement: {
|
||||||
|
match: /src:\i\("?\d+"?\)/g,
|
||||||
|
replace: "src: Vencord.Settings.plugins.BANger.source"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
options: {
|
||||||
source: {
|
source: {
|
||||||
description: "Source to replace ban GIF with (Video or Gif)",
|
description: "Source to replace ban GIF with (Video or Gif)",
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
default: "https://i.imgur.com/wp5q52C.mp4",
|
default: "https://i.imgur.com/wp5q52C.mp4",
|
||||||
restartNeeded: true,
|
restartNeeded: true,
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
export default definePlugin({
|
|
||||||
name: "BANger",
|
|
||||||
description: "Replaces the GIF in the ban dialogue with a custom one.",
|
|
||||||
authors: [Devs.Xinto, Devs.Glitch],
|
|
||||||
settings,
|
|
||||||
patches: [
|
|
||||||
{
|
|
||||||
find: "BAN_CONFIRM_TITLE.",
|
|
||||||
replacement: {
|
|
||||||
match: /src:\i\("?\d+"?\)/g,
|
|
||||||
replace: "src:$self.source"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
get source() {
|
|
||||||
return settings.store.source;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { definePluginSettings, Settings } from "@api/Settings";
|
import { Settings } from "@api/Settings";
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { canonicalizeMatch } from "@utils/patches";
|
import { canonicalizeMatch } from "@utils/patches";
|
||||||
|
@ -25,26 +25,10 @@ import { findByPropsLazy } from "@webpack";
|
||||||
|
|
||||||
const UserPopoutSectionCssClasses = findByPropsLazy("section", "lastSection");
|
const UserPopoutSectionCssClasses = findByPropsLazy("section", "lastSection");
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
|
||||||
hide: {
|
|
||||||
type: OptionType.BOOLEAN,
|
|
||||||
description: "Hide notes",
|
|
||||||
default: false,
|
|
||||||
restartNeeded: true
|
|
||||||
},
|
|
||||||
noSpellCheck: {
|
|
||||||
type: OptionType.BOOLEAN,
|
|
||||||
description: "Disable spellcheck in notes",
|
|
||||||
disabled: () => Settings.plugins.BetterNotesBox.hide,
|
|
||||||
default: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "BetterNotesBox",
|
name: "BetterNotesBox",
|
||||||
description: "Hide notes or disable spellcheck (Configure in settings!!)",
|
description: "Hide notes or disable spellcheck (Configure in settings!!)",
|
||||||
authors: [Devs.Ven],
|
authors: [Devs.Ven],
|
||||||
settings,
|
|
||||||
|
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
|
@ -52,7 +36,7 @@ export default definePlugin({
|
||||||
all: true,
|
all: true,
|
||||||
// Some modules match the find but the replacement is returned untouched
|
// Some modules match the find but the replacement is returned untouched
|
||||||
noWarn: true,
|
noWarn: true,
|
||||||
predicate: () => settings.store.hide,
|
predicate: () => Vencord.Settings.plugins.BetterNotesBox.hide,
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /hideNote:.+?(?=([,}].*?\)))/g,
|
match: /hideNote:.+?(?=([,}].*?\)))/g,
|
||||||
replace: (m, rest) => {
|
replace: (m, rest) => {
|
||||||
|
@ -70,7 +54,7 @@ export default definePlugin({
|
||||||
find: "Messages.NOTE_PLACEHOLDER",
|
find: "Messages.NOTE_PLACEHOLDER",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /\.NOTE_PLACEHOLDER,/,
|
match: /\.NOTE_PLACEHOLDER,/,
|
||||||
replace: "$&spellCheck:!$self.noSpellCheck,"
|
replace: "$&spellCheck:!Vencord.Settings.plugins.BetterNotesBox.noSpellCheck,"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -82,14 +66,25 @@ export default definePlugin({
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
options: {
|
||||||
|
hide: {
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
description: "Hide notes",
|
||||||
|
default: false,
|
||||||
|
restartNeeded: true
|
||||||
|
},
|
||||||
|
noSpellCheck: {
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
description: "Disable spellcheck in notes",
|
||||||
|
disabled: () => Settings.plugins.BetterNotesBox.hide,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
patchPadding: ErrorBoundary.wrap(({ lastSection }) => {
|
patchPadding: ErrorBoundary.wrap(({ lastSection }) => {
|
||||||
if (!lastSection) return null;
|
if (!lastSection) return null;
|
||||||
return (
|
return (
|
||||||
<div className={UserPopoutSectionCssClasses.lastSection} ></div>
|
<div className={UserPopoutSectionCssClasses.lastSection} ></div>
|
||||||
);
|
);
|
||||||
}),
|
})
|
||||||
|
|
||||||
get noSpellCheck() {
|
|
||||||
return settings.store.noSpellCheck;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
# ConsoleJanitor
|
|
||||||
|
|
||||||
Disables annoying console messages/errors. This plugin mainly removes errors/warnings that happen all the time and noisy/spammy logging messages.
|
|
||||||
|
|
||||||
Some of the disabled messages include the "notosans-400-normalitalic" error and MessageActionCreators, Routing/Utils loggers.
|
|
|
@ -1,152 +0,0 @@
|
||||||
/*
|
|
||||||
* Vencord, a Discord client mod
|
|
||||||
* Copyright (c) 2024 Vendicated and contributors
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { definePluginSettings } from "@api/Settings";
|
|
||||||
import { Devs } from "@utils/constants";
|
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
|
||||||
|
|
||||||
const Noop = () => { };
|
|
||||||
const NoopLogger = {
|
|
||||||
logDangerously: Noop,
|
|
||||||
log: Noop,
|
|
||||||
verboseDangerously: Noop,
|
|
||||||
verbose: Noop,
|
|
||||||
info: Noop,
|
|
||||||
warn: Noop,
|
|
||||||
error: Noop,
|
|
||||||
trace: Noop,
|
|
||||||
time: Noop,
|
|
||||||
fileOnly: Noop
|
|
||||||
};
|
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
|
||||||
disableNoisyLoggers: {
|
|
||||||
type: OptionType.BOOLEAN,
|
|
||||||
description: "Disable noisy loggers like the MessageActionCreators",
|
|
||||||
default: false,
|
|
||||||
restartNeeded: true
|
|
||||||
},
|
|
||||||
disableSpotifyLogger: {
|
|
||||||
type: OptionType.BOOLEAN,
|
|
||||||
description: "Disable the Spotify logger, which leaks account information and access token",
|
|
||||||
default: true,
|
|
||||||
restartNeeded: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default definePlugin({
|
|
||||||
name: "ConsoleJanitor",
|
|
||||||
description: "Disables annoying console messages/errors",
|
|
||||||
authors: [Devs.Nuckyz],
|
|
||||||
settings,
|
|
||||||
|
|
||||||
NoopLogger: () => NoopLogger,
|
|
||||||
|
|
||||||
patches: [
|
|
||||||
{
|
|
||||||
find: 'console.warn("Window state not initialized"',
|
|
||||||
replacement: {
|
|
||||||
match: /console\.warn\("Window state not initialized",\i\),/,
|
|
||||||
replace: ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
find: "is not a valid locale.",
|
|
||||||
replacement: {
|
|
||||||
match: /\i\.error\(""\.concat\(\i," is not a valid locale."\)\);/,
|
|
||||||
replace: ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
find: "notosans-400-normalitalic",
|
|
||||||
replacement: {
|
|
||||||
match: /,"notosans-.+?"/g,
|
|
||||||
replace: ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
find: 'console.warn("[DEPRECATED] Please use `subscribeWithSelector` middleware");',
|
|
||||||
all: true,
|
|
||||||
replacement: {
|
|
||||||
match: /console\.warn\("\[DEPRECATED\] Please use `subscribeWithSelector` middleware"\);/,
|
|
||||||
replace: ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
find: "RPCServer:WSS",
|
|
||||||
replacement: {
|
|
||||||
match: /\i\.error\("Error: "\.concat\((\i)\.message/,
|
|
||||||
replace: '!$1.message.includes("EADDRINUSE")&&$&'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
find: "Tried getting Dispatch instance before instantiated",
|
|
||||||
replacement: {
|
|
||||||
match: /null==\i&&\i\.warn\("Tried getting Dispatch instance before instantiated"\),/,
|
|
||||||
replace: ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
find: "Unable to determine render window for element",
|
|
||||||
replacement: {
|
|
||||||
match: /console\.warn\("Unable to determine render window for element",\i\),/,
|
|
||||||
replace: ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
find: "failed to send analytics events",
|
|
||||||
replacement: {
|
|
||||||
match: /console\.error\("\[analytics\] failed to send analytics events query: "\.concat\(\i\)\)/,
|
|
||||||
replace: ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
find: "Slow dispatch on",
|
|
||||||
replacement: {
|
|
||||||
match: /\i\.totalTime>100&&\i\.verbose\("Slow dispatch on ".+?\)\);/,
|
|
||||||
replace: ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
...[
|
|
||||||
'("MessageActionCreators")', '("ChannelMessages")',
|
|
||||||
'("Routing/Utils")', '("RTCControlSocket")',
|
|
||||||
'("ConnectionEventFramerateReducer")', '("RTCLatencyTestManager")',
|
|
||||||
'("OverlayBridgeStore")', '("RPCServer:WSS")', '("RPCServer:IPC")'
|
|
||||||
].map(logger => ({
|
|
||||||
find: logger,
|
|
||||||
predicate: () => settings.store.disableNoisyLoggers,
|
|
||||||
all: true,
|
|
||||||
replacement: {
|
|
||||||
match: new RegExp(String.raw`new \i\.\i${logger.replace(/([()])/g, "\\$1")}`),
|
|
||||||
replace: `$self.NoopLogger${logger}`
|
|
||||||
}
|
|
||||||
})),
|
|
||||||
{
|
|
||||||
find: '"Experimental codecs: "',
|
|
||||||
predicate: () => settings.store.disableNoisyLoggers,
|
|
||||||
replacement: {
|
|
||||||
match: /new \i\.\i\("Connection\("\.concat\(\i,"\)"\)\)/,
|
|
||||||
replace: "$self.NoopLogger()"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
find: '"Handling ping: "',
|
|
||||||
predicate: () => settings.store.disableNoisyLoggers,
|
|
||||||
replacement: {
|
|
||||||
match: /new \i\.\i\("RTCConnection\("\.concat.+?\)\)(?=,)/,
|
|
||||||
replace: "$self.NoopLogger()"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
find: '("Spotify")',
|
|
||||||
predicate: () => settings.store.disableSpotifyLogger,
|
|
||||||
replacement: {
|
|
||||||
match: /new \i\.\i\("Spotify"\)/,
|
|
||||||
replace: "$self.NoopLogger()"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
|
@ -40,9 +40,9 @@ export default definePlugin({
|
||||||
}),
|
}),
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
find: "!this.hasOpenCodeBlock()",
|
find: ".ENTER&&(!",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /!(\i).shiftKey&&!(this.hasOpenCodeBlock\(\))&&\(.{0,100}?\)/,
|
match: /(?<=(\i)\.which===\i\.\i.ENTER&&).{0,100}(\(0,\i\.\i\)\(\i\)).{0,100}(?=&&\(\i\.preventDefault)/,
|
||||||
replace: "$self.shouldSubmit($1, $2)"
|
replace: "$self.shouldSubmit($1, $2)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,15 +59,11 @@ export function addPatch(newPatch: Omit<Patch, "plugin">, pluginName: string) {
|
||||||
delete patch.group;
|
delete patch.group;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (patch.predicate && !patch.predicate()) return;
|
|
||||||
|
|
||||||
canonicalizeFind(patch);
|
canonicalizeFind(patch);
|
||||||
if (!Array.isArray(patch.replacement)) {
|
if (!Array.isArray(patch.replacement)) {
|
||||||
patch.replacement = [patch.replacement];
|
patch.replacement = [patch.replacement];
|
||||||
}
|
}
|
||||||
|
|
||||||
patch.replacement = patch.replacement.filter(({ predicate }) => !predicate || predicate());
|
|
||||||
|
|
||||||
if (IS_REPORTER) {
|
if (IS_REPORTER) {
|
||||||
patch.replacement.forEach(r => {
|
patch.replacement.forEach(r => {
|
||||||
delete r.predicate;
|
delete r.predicate;
|
||||||
|
|
|
@ -337,7 +337,7 @@ export default definePlugin({
|
||||||
// Pass through editHistory & deleted & original attachments to the "edited message" transformer
|
// Pass through editHistory & deleted & original attachments to the "edited message" transformer
|
||||||
match: /(?<=null!=\i\.edited_timestamp\)return )\i\(\i,\{reactions:(\i)\.reactions.{0,50}\}\)/,
|
match: /(?<=null!=\i\.edited_timestamp\)return )\i\(\i,\{reactions:(\i)\.reactions.{0,50}\}\)/,
|
||||||
replace:
|
replace:
|
||||||
"Object.assign($&,{ deleted:$1.deleted, editHistory:$1.editHistory })"
|
"Object.assign($&,{ deleted:$1.deleted, editHistory:$1.editHistory, attachments:$1.attachments })"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,15 +8,11 @@
|
||||||
.emoji,
|
.emoji,
|
||||||
[data-type="sticker"],
|
[data-type="sticker"],
|
||||||
iframe,
|
iframe,
|
||||||
.messagelogger-deleted-attachment,
|
.messagelogger-deleted-attachment:not([class*="hiddenAttachment_"]),
|
||||||
[class|="inlineMediaEmbed"]
|
[class|="inlineMediaEmbed"]
|
||||||
) {
|
) {
|
||||||
filter: grayscale(1) !important;
|
filter: grayscale(1) !important;
|
||||||
transition: 150ms filter ease-in-out;
|
transition: 150ms filter ease-in-out;
|
||||||
|
|
||||||
&[class*="hiddenMosaicItem_"] {
|
|
||||||
filter: grayscale(1) blur(var(--custom-message-attachment-spoiler-blur-radius, 44px)) !important;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.messagelogger-deleted
|
.messagelogger-deleted
|
||||||
|
@ -27,7 +23,8 @@
|
||||||
iframe,
|
iframe,
|
||||||
.messagelogger-deleted-attachment,
|
.messagelogger-deleted-attachment,
|
||||||
[class|="inlineMediaEmbed"]
|
[class|="inlineMediaEmbed"]
|
||||||
):hover {
|
):hover,
|
||||||
|
.messagelogger-deleted {
|
||||||
filter: grayscale(0) !important;
|
filter: grayscale(0) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ import UserPermissions from "./components/UserPermissions";
|
||||||
import { getSortedRoles, sortPermissionOverwrites } from "./utils";
|
import { getSortedRoles, sortPermissionOverwrites } from "./utils";
|
||||||
|
|
||||||
const PopoutClasses = findByPropsLazy("container", "scroller", "list");
|
const PopoutClasses = findByPropsLazy("container", "scroller", "list");
|
||||||
const RoleButtonClasses = findByPropsLazy("button", "buttonInner", "icon", "banner");
|
const RoleButtonClasses = findByPropsLazy("button", "buttonInner", "icon", "text");
|
||||||
|
|
||||||
export const enum PermissionsSortOrder {
|
export const enum PermissionsSortOrder {
|
||||||
HighestRole,
|
HighestRole,
|
||||||
|
|
|
@ -37,7 +37,8 @@ import { getCurrentUserInfo, readNotification } from "./reviewDbApi";
|
||||||
import { settings } from "./settings";
|
import { settings } from "./settings";
|
||||||
import { showToast } from "./utils";
|
import { showToast } from "./utils";
|
||||||
|
|
||||||
const RoleButtonClasses = findByPropsLazy("button", "buttonInner", "icon", "banner");
|
const PopoutClasses = findByPropsLazy("container", "scroller", "list");
|
||||||
|
const RoleButtonClasses = findByPropsLazy("button", "buttonInner", "icon", "text");
|
||||||
|
|
||||||
const guildPopoutPatch: NavContextMenuPatchCallback = (children, { guild }: { guild: Guild, onClose(): void; }) => {
|
const guildPopoutPatch: NavContextMenuPatchCallback = (children, { guild }: { guild: Guild, onClose(): void; }) => {
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
@ -180,9 +181,9 @@ export default definePlugin({
|
||||||
onClick={() => openReviewsModal(user.id, user.username)}
|
onClick={() => openReviewsModal(user.id, user.username)}
|
||||||
look={Button.Looks.FILLED}
|
look={Button.Looks.FILLED}
|
||||||
size={Button.Sizes.NONE}
|
size={Button.Sizes.NONE}
|
||||||
color={RoleButtonClasses.bannerColor}
|
color={RoleButtonClasses.color}
|
||||||
className={classes(RoleButtonClasses.button, RoleButtonClasses.icon, RoleButtonClasses.banner)}
|
className={classes(RoleButtonClasses.button, RoleButtonClasses.banner)}
|
||||||
innerClassName={classes(RoleButtonClasses.buttonInner, RoleButtonClasses.icon, RoleButtonClasses.banner)}
|
innerClassName={classes(RoleButtonClasses.buttonInner, RoleButtonClasses.banner)}
|
||||||
>
|
>
|
||||||
<NotesIcon height={16} width={16} />
|
<NotesIcon height={16} width={16} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -15,8 +15,8 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: ".Messages.VIEW_ALL_ROLES",
|
find: ".Messages.VIEW_ALL_ROLES",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(\i)\.slice\(0,\i\)/,
|
match: /return null!=\i(?=\?\i\.slice)/,
|
||||||
replace: "$1"
|
replace: "return false"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -257,7 +257,7 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: '"alt+shift+down"',
|
find: '"alt+shift+down"',
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=getChannel\(\i\);return null!=(\i))(?=.{0,200}?>0\)&&\(0,\i\.\i\)\(\i\))/,
|
match: /(?<=getChannel\(\i\);return null!=(\i))(?=.{0,150}?>0\)&&\(0,\i\.\i\)\(\i\))/,
|
||||||
replace: (_, channel) => `&&!$self.isHiddenChannel(${channel})`
|
replace: (_, channel) => `&&!$self.isHiddenChannel(${channel})`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -265,8 +265,8 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: ".APPLICATION_STORE&&null!=",
|
find: ".APPLICATION_STORE&&null!=",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /getState\(\)\.channelId.+?(?=\.map\(\i=>\i\.id)/,
|
match: /(?<=getState\(\)\.channelId.{0,30}?\(0,\i\.\i\)\(\i\))(?=\.map\()/,
|
||||||
replace: "$&.filter(e=>!$self.isHiddenChannel(e))"
|
replace: ".filter(e=>!$self.isHiddenChannel(e))"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
13
src/plugins/urbanDictionary/README.md
Normal file
13
src/plugins/urbanDictionary/README.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Urban Dictionary
|
||||||
|
|
||||||
|
Use /urban slash command to search for a definition for a word on [Urban Dictionary](https://www.urbandictionary.com/).
|
||||||
|
|
||||||
|
## Preview
|
||||||
|
|
||||||
|
![preview](https://i.imgur.com/1zwzj38.png)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
- Enable this plugin
|
||||||
|
- Set plugin settings as desired
|
||||||
|
- Type /urban and start getting definitions right into your Discord client.
|
105
src/plugins/urbanDictionary/index.ts
Normal file
105
src/plugins/urbanDictionary/index.ts
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a modification for Discord's desktop app
|
||||||
|
* Copyright (c) 2022 Vendicated and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ApplicationCommandOptionType, sendBotMessage } from "@api/Commands";
|
||||||
|
import { ApplicationCommandInputType } from "@api/Commands/types";
|
||||||
|
import { definePluginSettings } from "@api/Settings";
|
||||||
|
import { Devs } from "@utils/constants";
|
||||||
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
|
|
||||||
|
const settings = definePluginSettings({
|
||||||
|
resultsAmount: {
|
||||||
|
type: OptionType.NUMBER,
|
||||||
|
description: "The amount of results you want to get (more gives better results, but is slower)",
|
||||||
|
default: 10
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default definePlugin({
|
||||||
|
name: "UrbanDictionary",
|
||||||
|
description: "Search for a word on Urban Dictionary via /urban slash command",
|
||||||
|
authors: [Devs.jewdev],
|
||||||
|
dependencies: ["CommandsAPI"],
|
||||||
|
settings,
|
||||||
|
commands: [
|
||||||
|
{
|
||||||
|
name: "urban",
|
||||||
|
description: "Returns the definition of a word from Urban Dictionary",
|
||||||
|
inputType: ApplicationCommandInputType.BUILT_IN,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
type: ApplicationCommandOptionType.STRING,
|
||||||
|
name: "word",
|
||||||
|
description: "The word to search for on Urban Dictionary",
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
execute: async (args, ctx) => {
|
||||||
|
try {
|
||||||
|
const query: string = encodeURIComponent(args[0].value);
|
||||||
|
const { list } = await fetch(`https://api.urbandictionary.com/v0/define?term=${query}&per_page=${settings.store.resultsAmount}`).then(response => response.json());
|
||||||
|
|
||||||
|
if (!list.length)
|
||||||
|
return void sendBotMessage(ctx.channel.id, { content: "No results found." });
|
||||||
|
|
||||||
|
const definition = list.reduce((prev, curr) => {
|
||||||
|
return prev.thumbs_up > curr.thumbs_up ? prev : curr;
|
||||||
|
});
|
||||||
|
|
||||||
|
const linkify = (text: string) => text
|
||||||
|
.replaceAll("\r\n", "\n")
|
||||||
|
.replace(/([*>_`~\\])/gsi, "\\$1")
|
||||||
|
.replace(/\[(.+?)\]/g, (_, word) => `[${word}](https://www.urbandictionary.com/define.php?term=${encodeURIComponent(word)} "Define '${word}' on Urban Dictionary")`)
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
return void sendBotMessage(ctx.channel.id, {
|
||||||
|
embeds: [
|
||||||
|
{
|
||||||
|
type: "rich",
|
||||||
|
author: {
|
||||||
|
name: `Uploaded by "${definition.author}"`,
|
||||||
|
url: `https://www.urbandictionary.com/author.php?author=${encodeURIComponent(definition.author)}`,
|
||||||
|
},
|
||||||
|
title: definition.word,
|
||||||
|
url: `https://www.urbandictionary.com/define.php?term=${encodeURIComponent(definition.word)}`,
|
||||||
|
description: linkify(definition.definition),
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "Example",
|
||||||
|
value: linkify(definition.example),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Want more definitions?",
|
||||||
|
value: `Check out [more definitions](https://www.urbandictionary.com/define.php?term=${query} "Define "${args[0].value}" on Urban Dictionary") on Urban Dictionary.`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
color: 0xFF9900,
|
||||||
|
footer: { text: `👍 ${definition.thumbs_up.toString()} | 👎 ${definition.thumbs_down.toString()}`, icon_url: "https://www.urbandictionary.com/favicon.ico" },
|
||||||
|
timestamp: new Date(definition.written_on).toISOString(),
|
||||||
|
},
|
||||||
|
] as any,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
sendBotMessage(ctx.channel.id, {
|
||||||
|
content: `Something went wrong: \`${error}\``,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
|
@ -213,8 +213,8 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: ".canUsePremiumProfileCustomization,{avatarSrc:",
|
find: ".canUsePremiumProfileCustomization,{avatarSrc:",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /\.avatar,\i\.clickable\),onClick:\i,(?<=avatarSrc:(\i).+?)/,
|
match: /children:\(0,\i\.jsx\)\(\i,{src:(\i)/,
|
||||||
replace: "$&style:{cursor:\"pointer\"},onClick:()=>{$self.openImage($1)},"
|
replace: "style:{cursor:\"pointer\"},onClick:()=>{$self.openImage($1)},$&"
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
110
src/plugins/wikisearch/index.ts
Normal file
110
src/plugins/wikisearch/index.ts
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a modification for Discord's desktop app
|
||||||
|
* Copyright (c) 2023 Vendicated and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands";
|
||||||
|
import { Devs } from "@utils/constants";
|
||||||
|
import definePlugin from "@utils/types";
|
||||||
|
|
||||||
|
export default definePlugin({
|
||||||
|
name: "Wikisearch",
|
||||||
|
description: "Searches Wikipedia for your requested query. (/wikisearch)",
|
||||||
|
authors: [Devs.Samu],
|
||||||
|
dependencies: ["CommandsAPI"],
|
||||||
|
commands: [
|
||||||
|
{
|
||||||
|
name: "wikisearch",
|
||||||
|
description: "Searches Wikipedia for your request.",
|
||||||
|
inputType: ApplicationCommandInputType.BUILT_IN,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: "search",
|
||||||
|
description: "Word to search for",
|
||||||
|
type: ApplicationCommandOptionType.STRING,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
],
|
||||||
|
execute: async (_, ctx) => {
|
||||||
|
const word = findOption(_, "search", "");
|
||||||
|
|
||||||
|
if (!word) {
|
||||||
|
return sendBotMessage(ctx.channel.id, {
|
||||||
|
content: "No word was defined!"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataSearchParams = new URLSearchParams({
|
||||||
|
action: "query",
|
||||||
|
format: "json",
|
||||||
|
list: "search",
|
||||||
|
formatversion: "2",
|
||||||
|
origin: "*",
|
||||||
|
srsearch: word
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await fetch("https://en.wikipedia.org/w/api.php?" + dataSearchParams).then(response => response.json())
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
sendBotMessage(ctx.channel.id, { content: "There was an error. Check the console for more info" });
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
|
if (!data.query?.search?.length) {
|
||||||
|
console.log(data);
|
||||||
|
return sendBotMessage(ctx.channel.id, { content: "No results given" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const altData = await fetch(`https://en.wikipedia.org/w/api.php?action=query&format=json&prop=info%7Cdescription%7Cimages%7Cimageinfo%7Cpageimages&list=&meta=&indexpageids=1&pageids=${data.query.search[0].pageid}&formatversion=2&origin=*`)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => data.query.pages[0])
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
sendBotMessage(ctx.channel.id, { content: "There was an error. Check the console for more info" });
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!altData) return;
|
||||||
|
|
||||||
|
const thumbnailData = altData.thumbnail;
|
||||||
|
|
||||||
|
const thumbnail = thumbnailData && {
|
||||||
|
url: thumbnailData.source.replace(/(50px-)/ig, "1000px-"),
|
||||||
|
height: thumbnailData.height * 100,
|
||||||
|
width: thumbnailData.width * 100
|
||||||
|
};
|
||||||
|
|
||||||
|
sendBotMessage(ctx.channel.id, {
|
||||||
|
embeds: [
|
||||||
|
{
|
||||||
|
type: "rich",
|
||||||
|
title: data.query.search[0].title,
|
||||||
|
url: `https://wikipedia.org/w/index.php?curid=${data.query.search[0].pageid}`,
|
||||||
|
color: "0x8663BE",
|
||||||
|
description: data.query.search[0].snippet.replace(/( |<([^>]+)>)/ig, "").replace(/(")/ig, "\"") + "...",
|
||||||
|
image: thumbnail,
|
||||||
|
footer: {
|
||||||
|
text: "Powered by the Wikimedia API",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
] as any
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
|
@ -24,7 +24,7 @@ import { DevsById } from "./constants";
|
||||||
* Calls .join(" ") on the arguments
|
* Calls .join(" ") on the arguments
|
||||||
* classes("one", "two") => "one two"
|
* classes("one", "two") => "one two"
|
||||||
*/
|
*/
|
||||||
export function classes(...classes: Array<string | null | undefined | false>) {
|
export function classes(...classes: Array<string | null | undefined>) {
|
||||||
return classes.filter(Boolean).join(" ");
|
return classes.filter(Boolean).join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
62
src/webpack/common/types/utils.d.ts
vendored
62
src/webpack/common/types/utils.d.ts
vendored
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Guild, GuildMember, User } from "discord-types/general";
|
import { Guild, GuildMember } from "discord-types/general";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { LiteralUnion } from "type-fest";
|
import { LiteralUnion } from "type-fest";
|
||||||
|
|
||||||
|
@ -256,63 +256,3 @@ export interface PopoutActions {
|
||||||
close(key: string): void;
|
close(key: string): void;
|
||||||
setAlwaysOnTop(key: string, alwaysOnTop: boolean): void;
|
setAlwaysOnTop(key: string, alwaysOnTop: boolean): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UserNameUtilsTagInclude = LiteralUnion<"auto" | "always" | "never", string>;
|
|
||||||
export interface UserNameUtilsTagOptions {
|
|
||||||
forcePomelo?: boolean;
|
|
||||||
identifiable?: UserNameUtilsTagInclude;
|
|
||||||
decoration?: UserNameUtilsTagInclude;
|
|
||||||
mode?: "full" | "username";
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UsernameUtils {
|
|
||||||
getGlobalName(user: User): string;
|
|
||||||
getFormattedName(user: User, useTagInsteadOfUsername?: boolean): string;
|
|
||||||
getName(user: User): string;
|
|
||||||
useName(user: User): string;
|
|
||||||
getUserTag(user: User, options?: UserNameUtilsTagOptions): string;
|
|
||||||
useUserTag(user: User, options?: UserNameUtilsTagOptions): string;
|
|
||||||
|
|
||||||
|
|
||||||
useDirectMessageRecipient: any;
|
|
||||||
humanizeStatus: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DisplayProfile {
|
|
||||||
userId: string;
|
|
||||||
banner?: string;
|
|
||||||
bio?: string;
|
|
||||||
pronouns?: string;
|
|
||||||
accentColor?: number;
|
|
||||||
themeColors?: number[];
|
|
||||||
popoutAnimationParticleType?: any;
|
|
||||||
profileEffectId?: string;
|
|
||||||
_userProfile?: any;
|
|
||||||
_guildMemberProfile?: any;
|
|
||||||
canUsePremiumProfileCustomization: boolean;
|
|
||||||
canEditThemes: boolean;
|
|
||||||
premiumGuildSince: Date | null;
|
|
||||||
premiumSince: Date | null;
|
|
||||||
premiumType?: number;
|
|
||||||
primaryColor?: number;
|
|
||||||
|
|
||||||
getBadges(): Array<{
|
|
||||||
id: string;
|
|
||||||
description: string;
|
|
||||||
icon: string;
|
|
||||||
link?: string;
|
|
||||||
}>;
|
|
||||||
getBannerURL(options: { canAnimate: boolean; size: number; }): string;
|
|
||||||
getLegacyUsername(): string | null;
|
|
||||||
hasFullProfile(): boolean;
|
|
||||||
hasPremiumCustomization(): boolean;
|
|
||||||
hasThemeColors(): boolean;
|
|
||||||
isUsingGuildMemberBanner(): boolean;
|
|
||||||
isUsingGuildMemberBio(): boolean;
|
|
||||||
isUsingGuildMemberPronouns(): boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DisplayProfileUtils {
|
|
||||||
getDisplayProfile(userId: string, guildId?: string, customStores?: any): DisplayProfile | null;
|
|
||||||
useDisplayProfile(userId: string, guildId?: string, customStores?: any): DisplayProfile | null;
|
|
||||||
}
|
|
||||||
|
|
|
@ -73,25 +73,6 @@ const ToastPosition = {
|
||||||
BOTTOM: 1
|
BOTTOM: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ToastData {
|
|
||||||
message: string,
|
|
||||||
id: string,
|
|
||||||
/**
|
|
||||||
* Toasts.Type
|
|
||||||
*/
|
|
||||||
type: number,
|
|
||||||
options?: ToastOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ToastOptions {
|
|
||||||
/**
|
|
||||||
* Toasts.Position
|
|
||||||
*/
|
|
||||||
position?: number;
|
|
||||||
component?: React.ReactNode,
|
|
||||||
duration?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Toasts = {
|
export const Toasts = {
|
||||||
Type: ToastType,
|
Type: ToastType,
|
||||||
Position: ToastPosition,
|
Position: ToastPosition,
|
||||||
|
@ -100,9 +81,23 @@ export const Toasts = {
|
||||||
|
|
||||||
// hack to merge with the following interface, dunno if there's a better way
|
// hack to merge with the following interface, dunno if there's a better way
|
||||||
...{} as {
|
...{} as {
|
||||||
show(data: ToastData): void;
|
show(data: {
|
||||||
|
message: string,
|
||||||
|
id: string,
|
||||||
|
/**
|
||||||
|
* Toasts.Type
|
||||||
|
*/
|
||||||
|
type: number,
|
||||||
|
options?: {
|
||||||
|
/**
|
||||||
|
* Toasts.Position
|
||||||
|
*/
|
||||||
|
position?: number;
|
||||||
|
component?: React.ReactNode,
|
||||||
|
duration?: number;
|
||||||
|
};
|
||||||
|
}): void;
|
||||||
pop(): void;
|
pop(): void;
|
||||||
create(message: string, type: number, options?: ToastOptions): ToastData;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -110,15 +105,18 @@ export const Toasts = {
|
||||||
waitFor("showToast", m => {
|
waitFor("showToast", m => {
|
||||||
Toasts.show = m.showToast;
|
Toasts.show = m.showToast;
|
||||||
Toasts.pop = m.popToast;
|
Toasts.pop = m.popToast;
|
||||||
Toasts.create = m.createToast;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a simple toast. If you need more options, use Toasts.show manually
|
* Show a simple toast. If you need more options, use Toasts.show manually
|
||||||
*/
|
*/
|
||||||
export function showToast(message: string, type = ToastType.MESSAGE, options?: ToastOptions) {
|
export function showToast(message: string, type = ToastType.MESSAGE) {
|
||||||
Toasts.show(Toasts.create(message, type, options));
|
Toasts.show({
|
||||||
|
id: Toasts.genId(),
|
||||||
|
message,
|
||||||
|
type
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UserUtils = {
|
export const UserUtils = {
|
||||||
|
@ -174,9 +172,3 @@ export const PopoutActions: t.PopoutActions = mapMangledModuleLazy('type:"POPOUT
|
||||||
close: filters.byCode('type:"POPOUT_WINDOW_CLOSE"'),
|
close: filters.byCode('type:"POPOUT_WINDOW_CLOSE"'),
|
||||||
setAlwaysOnTop: filters.byCode('type:"POPOUT_WINDOW_SET_ALWAYS_ON_TOP"'),
|
setAlwaysOnTop: filters.byCode('type:"POPOUT_WINDOW_SET_ALWAYS_ON_TOP"'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const UsernameUtils: t.UsernameUtils = findByPropsLazy("useName", "getGlobalName");
|
|
||||||
export const DisplayProfileUtils: t.DisplayProfileUtils = mapMangledModuleLazy(/=\i\.getUserProfile\(\i\),\i=\i\.getGuildMemberProfile\(/, {
|
|
||||||
getDisplayProfile: filters.byCode(".getGuildMemberProfile("),
|
|
||||||
useDisplayProfile: filters.byCode(/\[\i\.\i,\i\.\i],\(\)=>/)
|
|
||||||
});
|
|
||||||
|
|
|
@ -259,6 +259,7 @@ function patchFactories(factories: Record<string, (module: any, exports: any, re
|
||||||
|
|
||||||
for (let i = 0; i < patches.length; i++) {
|
for (let i = 0; i < patches.length; i++) {
|
||||||
const patch = patches[i];
|
const patch = patches[i];
|
||||||
|
if (patch.predicate && !patch.predicate()) continue;
|
||||||
|
|
||||||
const moduleMatches = typeof patch.find === "string"
|
const moduleMatches = typeof patch.find === "string"
|
||||||
? code.includes(patch.find)
|
? code.includes(patch.find)
|
||||||
|
@ -274,6 +275,8 @@ function patchFactories(factories: Record<string, (module: any, exports: any, re
|
||||||
|
|
||||||
// We change all patch.replacement to array in plugins/index
|
// We change all patch.replacement to array in plugins/index
|
||||||
for (const replacement of patch.replacement as PatchReplacement[]) {
|
for (const replacement of patch.replacement as PatchReplacement[]) {
|
||||||
|
if (replacement.predicate && !replacement.predicate()) continue;
|
||||||
|
|
||||||
const lastMod = mod;
|
const lastMod = mod;
|
||||||
const lastCode = code;
|
const lastCode = code;
|
||||||
|
|
||||||
|
|
|
@ -38,43 +38,31 @@ export let cache: WebpackInstance["c"];
|
||||||
|
|
||||||
export type FilterFn = (mod: any) => boolean;
|
export type FilterFn = (mod: any) => boolean;
|
||||||
|
|
||||||
type PropsFilter = Array<string>;
|
|
||||||
type CodeFilter = Array<string | RegExp>;
|
|
||||||
type StoreNameFilter = string;
|
|
||||||
|
|
||||||
const stringMatches = (s: string, filter: CodeFilter) =>
|
|
||||||
filter.every(f =>
|
|
||||||
typeof f === "string"
|
|
||||||
? s.includes(f)
|
|
||||||
: f.test(s)
|
|
||||||
);
|
|
||||||
|
|
||||||
export const filters = {
|
export const filters = {
|
||||||
byProps: (...props: PropsFilter): FilterFn =>
|
byProps: (...props: string[]): FilterFn =>
|
||||||
props.length === 1
|
props.length === 1
|
||||||
? m => m[props[0]] !== void 0
|
? m => m[props[0]] !== void 0
|
||||||
: m => props.every(p => m[p] !== void 0),
|
: m => props.every(p => m[p] !== void 0),
|
||||||
|
|
||||||
byCode: (...code: CodeFilter): FilterFn => {
|
byCode: (...code: string[]): FilterFn => m => {
|
||||||
code = code.map(canonicalizeMatch);
|
|
||||||
return m => {
|
|
||||||
if (typeof m !== "function") return false;
|
if (typeof m !== "function") return false;
|
||||||
return stringMatches(Function.prototype.toString.call(m), code);
|
const s = Function.prototype.toString.call(m);
|
||||||
};
|
for (const c of code) {
|
||||||
|
if (!s.includes(c)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
byStoreName: (name: StoreNameFilter): FilterFn => m =>
|
byStoreName: (name: string): FilterFn => m =>
|
||||||
m.constructor?.displayName === name,
|
m.constructor?.displayName === name,
|
||||||
|
|
||||||
componentByCode: (...code: CodeFilter): FilterFn => {
|
componentByCode: (...code: string[]): FilterFn => {
|
||||||
const filter = filters.byCode(...code);
|
const filter = filters.byCode(...code);
|
||||||
return m => {
|
return m => {
|
||||||
if (filter(m)) return true;
|
if (filter(m)) return true;
|
||||||
if (!m.$$typeof) return false;
|
if (!m.$$typeof) return false;
|
||||||
if (m.type)
|
if (m.type && m.type.render) return filter(m.type.render); // memo + forwardRef
|
||||||
return m.type.render
|
if (m.type) return filter(m.type); // memos
|
||||||
? filter(m.type.render) // memo + forwardRef
|
if (m.render) return filter(m.render); // forwardRefs
|
||||||
: filter(m.type); // memo
|
|
||||||
if (m.render) return filter(m.render); // forwardRef
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -257,9 +245,15 @@ export const findBulk = traceFunction("findBulk", function findBulk(...filterFns
|
||||||
* Find the id of the first module factory that includes all the given code
|
* Find the id of the first module factory that includes all the given code
|
||||||
* @returns string or null
|
* @returns string or null
|
||||||
*/
|
*/
|
||||||
export const findModuleId = traceFunction("findModuleId", function findModuleId(...code: CodeFilter) {
|
export const findModuleId = traceFunction("findModuleId", function findModuleId(...code: string[]) {
|
||||||
|
outer:
|
||||||
for (const id in wreq.m) {
|
for (const id in wreq.m) {
|
||||||
if (stringMatches(wreq.m[id].toString(), code)) return id;
|
const str = wreq.m[id].toString();
|
||||||
|
|
||||||
|
for (const c of code) {
|
||||||
|
if (!str.includes(c)) continue outer;
|
||||||
|
}
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const err = new Error("Didn't find module with code(s):\n" + code.join("\n"));
|
const err = new Error("Didn't find module with code(s):\n" + code.join("\n"));
|
||||||
|
@ -278,7 +272,7 @@ export const findModuleId = traceFunction("findModuleId", function findModuleId(
|
||||||
* Find the first module factory that includes all the given code
|
* Find the first module factory that includes all the given code
|
||||||
* @returns The module factory or null
|
* @returns The module factory or null
|
||||||
*/
|
*/
|
||||||
export function findModuleFactory(...code: CodeFilter) {
|
export function findModuleFactory(...code: string[]) {
|
||||||
const id = findModuleId(...code);
|
const id = findModuleId(...code);
|
||||||
if (!id) return null;
|
if (!id) return null;
|
||||||
|
|
||||||
|
@ -331,7 +325,7 @@ export function findLazy(filter: FilterFn) {
|
||||||
/**
|
/**
|
||||||
* Find the first module that has the specified properties
|
* Find the first module that has the specified properties
|
||||||
*/
|
*/
|
||||||
export function findByProps(...props: PropsFilter) {
|
export function findByProps(...props: string[]) {
|
||||||
const res = find(filters.byProps(...props), { isIndirect: true });
|
const res = find(filters.byProps(...props), { isIndirect: true });
|
||||||
if (!res)
|
if (!res)
|
||||||
handleModuleNotFound("findByProps", ...props);
|
handleModuleNotFound("findByProps", ...props);
|
||||||
|
@ -341,7 +335,7 @@ export function findByProps(...props: PropsFilter) {
|
||||||
/**
|
/**
|
||||||
* Find the first module that has the specified properties, lazily
|
* Find the first module that has the specified properties, lazily
|
||||||
*/
|
*/
|
||||||
export function findByPropsLazy(...props: PropsFilter) {
|
export function findByPropsLazy(...props: string[]) {
|
||||||
if (IS_REPORTER) lazyWebpackSearchHistory.push(["findByProps", props]);
|
if (IS_REPORTER) lazyWebpackSearchHistory.push(["findByProps", props]);
|
||||||
|
|
||||||
return proxyLazy(() => findByProps(...props));
|
return proxyLazy(() => findByProps(...props));
|
||||||
|
@ -350,7 +344,7 @@ export function findByPropsLazy(...props: PropsFilter) {
|
||||||
/**
|
/**
|
||||||
* Find the first function that includes all the given code
|
* Find the first function that includes all the given code
|
||||||
*/
|
*/
|
||||||
export function findByCode(...code: CodeFilter) {
|
export function findByCode(...code: string[]) {
|
||||||
const res = find(filters.byCode(...code), { isIndirect: true });
|
const res = find(filters.byCode(...code), { isIndirect: true });
|
||||||
if (!res)
|
if (!res)
|
||||||
handleModuleNotFound("findByCode", ...code);
|
handleModuleNotFound("findByCode", ...code);
|
||||||
|
@ -360,7 +354,7 @@ export function findByCode(...code: CodeFilter) {
|
||||||
/**
|
/**
|
||||||
* Find the first function that includes all the given code, lazily
|
* Find the first function that includes all the given code, lazily
|
||||||
*/
|
*/
|
||||||
export function findByCodeLazy(...code: CodeFilter) {
|
export function findByCodeLazy(...code: string[]) {
|
||||||
if (IS_REPORTER) lazyWebpackSearchHistory.push(["findByCode", code]);
|
if (IS_REPORTER) lazyWebpackSearchHistory.push(["findByCode", code]);
|
||||||
|
|
||||||
return proxyLazy(() => findByCode(...code));
|
return proxyLazy(() => findByCode(...code));
|
||||||
|
@ -369,7 +363,7 @@ export function findByCodeLazy(...code: CodeFilter) {
|
||||||
/**
|
/**
|
||||||
* Find a store by its displayName
|
* Find a store by its displayName
|
||||||
*/
|
*/
|
||||||
export function findStore(name: StoreNameFilter) {
|
export function findStore(name: string) {
|
||||||
const res = find(filters.byStoreName(name), { isIndirect: true });
|
const res = find(filters.byStoreName(name), { isIndirect: true });
|
||||||
if (!res)
|
if (!res)
|
||||||
handleModuleNotFound("findStore", name);
|
handleModuleNotFound("findStore", name);
|
||||||
|
@ -379,7 +373,7 @@ export function findStore(name: StoreNameFilter) {
|
||||||
/**
|
/**
|
||||||
* Find a store by its displayName, lazily
|
* Find a store by its displayName, lazily
|
||||||
*/
|
*/
|
||||||
export function findStoreLazy(name: StoreNameFilter) {
|
export function findStoreLazy(name: string) {
|
||||||
if (IS_REPORTER) lazyWebpackSearchHistory.push(["findStore", [name]]);
|
if (IS_REPORTER) lazyWebpackSearchHistory.push(["findStore", [name]]);
|
||||||
|
|
||||||
return proxyLazy(() => findStore(name));
|
return proxyLazy(() => findStore(name));
|
||||||
|
@ -388,7 +382,7 @@ export function findStoreLazy(name: StoreNameFilter) {
|
||||||
/**
|
/**
|
||||||
* Finds the component which includes all the given code. Checks for plain components, memos and forwardRefs
|
* Finds the component which includes all the given code. Checks for plain components, memos and forwardRefs
|
||||||
*/
|
*/
|
||||||
export function findComponentByCode(...code: CodeFilter) {
|
export function findComponentByCode(...code: string[]) {
|
||||||
const res = find(filters.componentByCode(...code), { isIndirect: true });
|
const res = find(filters.componentByCode(...code), { isIndirect: true });
|
||||||
if (!res)
|
if (!res)
|
||||||
handleModuleNotFound("findComponentByCode", ...code);
|
handleModuleNotFound("findComponentByCode", ...code);
|
||||||
|
@ -413,7 +407,7 @@ export function findComponentLazy<T extends object = any>(filter: FilterFn) {
|
||||||
/**
|
/**
|
||||||
* Finds the first component that includes all the given code, lazily
|
* Finds the first component that includes all the given code, lazily
|
||||||
*/
|
*/
|
||||||
export function findComponentByCodeLazy<T extends object = any>(...code: CodeFilter) {
|
export function findComponentByCodeLazy<T extends object = any>(...code: string[]) {
|
||||||
if (IS_REPORTER) lazyWebpackSearchHistory.push(["findComponentByCode", code]);
|
if (IS_REPORTER) lazyWebpackSearchHistory.push(["findComponentByCode", code]);
|
||||||
|
|
||||||
return LazyComponent<T>(() => {
|
return LazyComponent<T>(() => {
|
||||||
|
@ -427,7 +421,7 @@ export function findComponentByCodeLazy<T extends object = any>(...code: CodeFil
|
||||||
/**
|
/**
|
||||||
* Finds the first component that is exported by the first prop name, lazily
|
* Finds the first component that is exported by the first prop name, lazily
|
||||||
*/
|
*/
|
||||||
export function findExportedComponentLazy<T extends object = any>(...props: PropsFilter) {
|
export function findExportedComponentLazy<T extends object = any>(...props: string[]) {
|
||||||
if (IS_REPORTER) lazyWebpackSearchHistory.push(["findExportedComponent", props]);
|
if (IS_REPORTER) lazyWebpackSearchHistory.push(["findExportedComponent", props]);
|
||||||
|
|
||||||
return LazyComponent<T>(() => {
|
return LazyComponent<T>(() => {
|
||||||
|
@ -451,13 +445,10 @@ export function findExportedComponentLazy<T extends object = any>(...props: Prop
|
||||||
* closeModal: filters.byCode("key==")
|
* closeModal: filters.byCode("key==")
|
||||||
* })
|
* })
|
||||||
*/
|
*/
|
||||||
export const mapMangledModule = traceFunction("mapMangledModule", function mapMangledModule<S extends string>(code: string | RegExp | CodeFilter, mappers: Record<S, FilterFn>): Record<S, any> {
|
export const mapMangledModule = traceFunction("mapMangledModule", function mapMangledModule<S extends string>(code: string, mappers: Record<S, FilterFn>): Record<S, any> {
|
||||||
if (!Array.isArray(code)) code = [code];
|
|
||||||
code = code.map(canonicalizeMatch);
|
|
||||||
|
|
||||||
const exports = {} as Record<S, any>;
|
const exports = {} as Record<S, any>;
|
||||||
|
|
||||||
const id = findModuleId(...code);
|
const id = findModuleId(code);
|
||||||
if (id === null)
|
if (id === null)
|
||||||
return exports;
|
return exports;
|
||||||
|
|
||||||
|
@ -491,7 +482,7 @@ export const mapMangledModule = traceFunction("mapMangledModule", function mapMa
|
||||||
* closeModal: filters.byCode("key==")
|
* closeModal: filters.byCode("key==")
|
||||||
* })
|
* })
|
||||||
*/
|
*/
|
||||||
export function mapMangledModuleLazy<S extends string>(code: string | RegExp | CodeFilter, mappers: Record<S, FilterFn>): Record<S, any> {
|
export function mapMangledModuleLazy<S extends string>(code: string, mappers: Record<S, FilterFn>): Record<S, any> {
|
||||||
if (IS_REPORTER) lazyWebpackSearchHistory.push(["mapMangledModule", [code, mappers]]);
|
if (IS_REPORTER) lazyWebpackSearchHistory.push(["mapMangledModule", [code, mappers]]);
|
||||||
|
|
||||||
return proxyLazy(() => mapMangledModule(code, mappers));
|
return proxyLazy(() => mapMangledModule(code, mappers));
|
||||||
|
@ -506,7 +497,7 @@ export const ChunkIdsRegex = /\("([^"]+?)"\)/g;
|
||||||
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the first lazy chunk loading found in the module factory
|
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the first lazy chunk loading found in the module factory
|
||||||
* @returns A promise that resolves with a boolean whether the chunks were loaded
|
* @returns A promise that resolves with a boolean whether the chunks were loaded
|
||||||
*/
|
*/
|
||||||
export async function extractAndLoadChunks(code: CodeFilter, matcher: RegExp = DefaultExtractAndLoadChunksRegex) {
|
export async function extractAndLoadChunks(code: string[], matcher: RegExp = DefaultExtractAndLoadChunksRegex) {
|
||||||
const module = findModuleFactory(...code);
|
const module = findModuleFactory(...code);
|
||||||
if (!module) {
|
if (!module) {
|
||||||
const err = new Error("extractAndLoadChunks: Couldn't find module factory");
|
const err = new Error("extractAndLoadChunks: Couldn't find module factory");
|
||||||
|
@ -571,7 +562,7 @@ export async function extractAndLoadChunks(code: CodeFilter, matcher: RegExp = D
|
||||||
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the first lazy chunk loading found in the module factory
|
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the first lazy chunk loading found in the module factory
|
||||||
* @returns A function that returns a promise that resolves with a boolean whether the chunks were loaded, on first call
|
* @returns A function that returns a promise that resolves with a boolean whether the chunks were loaded, on first call
|
||||||
*/
|
*/
|
||||||
export function extractAndLoadChunksLazy(code: CodeFilter, matcher = DefaultExtractAndLoadChunksRegex) {
|
export function extractAndLoadChunksLazy(code: string[], matcher = DefaultExtractAndLoadChunksRegex) {
|
||||||
if (IS_REPORTER) lazyWebpackSearchHistory.push(["extractAndLoadChunks", [code, matcher]]);
|
if (IS_REPORTER) lazyWebpackSearchHistory.push(["extractAndLoadChunks", [code, matcher]]);
|
||||||
|
|
||||||
return makeLazy(() => extractAndLoadChunks(code, matcher));
|
return makeLazy(() => extractAndLoadChunks(code, matcher));
|
||||||
|
@ -581,7 +572,7 @@ export function extractAndLoadChunksLazy(code: CodeFilter, matcher = DefaultExtr
|
||||||
* Wait for a module that matches the provided filter to be registered,
|
* Wait for a module that matches the provided filter to be registered,
|
||||||
* then call the callback with the module as the first argument
|
* then call the callback with the module as the first argument
|
||||||
*/
|
*/
|
||||||
export function waitFor(filter: string | PropsFilter | FilterFn, callback: CallbackFn, { isIndirect = false }: { isIndirect?: boolean; } = {}) {
|
export function waitFor(filter: string | string[] | FilterFn, callback: CallbackFn, { isIndirect = false }: { isIndirect?: boolean; } = {}) {
|
||||||
if (IS_REPORTER && !isIndirect) lazyWebpackSearchHistory.push(["waitFor", Array.isArray(filter) ? filter : [filter]]);
|
if (IS_REPORTER && !isIndirect) lazyWebpackSearchHistory.push(["waitFor", Array.isArray(filter) ? filter : [filter]]);
|
||||||
|
|
||||||
if (typeof filter === "string")
|
if (typeof filter === "string")
|
||||||
|
@ -602,17 +593,20 @@ export function waitFor(filter: string | PropsFilter | FilterFn, callback: Callb
|
||||||
/**
|
/**
|
||||||
* Search modules by keyword. This searches the factory methods,
|
* Search modules by keyword. This searches the factory methods,
|
||||||
* meaning you can search all sorts of things, displayName, methodName, strings somewhere in the code, etc
|
* meaning you can search all sorts of things, displayName, methodName, strings somewhere in the code, etc
|
||||||
* @param code One or more strings or regexes
|
* @param filters One or more strings or regexes
|
||||||
* @returns Mapping of found modules
|
* @returns Mapping of found modules
|
||||||
*/
|
*/
|
||||||
export function search(...code: CodeFilter) {
|
export function search(...filters: Array<string | RegExp>) {
|
||||||
const results = {} as Record<number, Function>;
|
const results = {} as Record<number, Function>;
|
||||||
const factories = wreq.m;
|
const factories = wreq.m;
|
||||||
|
outer:
|
||||||
for (const id in factories) {
|
for (const id in factories) {
|
||||||
const factory = factories[id].original ?? factories[id];
|
const factory = factories[id].original ?? factories[id];
|
||||||
|
const str: string = factory.toString();
|
||||||
if (stringMatches(factory.toString(), code))
|
for (const filter of filters) {
|
||||||
|
if (typeof filter === "string" && !str.includes(filter)) continue outer;
|
||||||
|
if (filter instanceof RegExp && !filter.test(str)) continue outer;
|
||||||
|
}
|
||||||
results[id] = factory;
|
results[id] = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue