haicord/src/plugins/betterNotes/index.tsx

78 lines
2.5 KiB
TypeScript
Raw Normal View History

2022-11-24 02:02:15 +01:00
/*
* 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/>.
*/
2024-06-12 23:56:02 -03:00
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
2024-03-22 09:42:19 -03:00
import { canonicalizeMatch } from "@utils/patches";
import definePlugin, { OptionType } from "@utils/types";
2022-11-24 02:02:15 +01:00
2024-06-12 23:56:02 -03:00
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.store.hide,
default: false
}
});
2022-11-24 02:02:15 +01:00
export default definePlugin({
name: "BetterNotesBox",
description: "Hide notes or disable spellcheck (Configure in settings!!)",
authors: [Devs.Ven],
2024-06-12 23:56:02 -03:00
settings,
2022-11-24 02:02:15 +01:00
patches: [
{
find: "hideNote:",
all: true,
2023-10-26 15:07:44 -03:00
// Some modules match the find but the replacement is returned untouched
noWarn: true,
2024-06-12 23:56:02 -03:00
predicate: () => settings.store.hide,
2022-11-24 02:02:15 +01:00
replacement: {
2023-10-26 15:07:44 -03:00
match: /hideNote:.+?(?=([,}].*?\)))/g,
replace: (m, rest) => {
const destructuringMatch = rest.match(/}=.+/);
2024-03-22 09:42:19 -03:00
if (destructuringMatch) {
const defaultValueMatch = m.match(canonicalizeMatch(/hideNote:(\i)=!?\d/));
return defaultValueMatch ? `hideNote:${defaultValueMatch[1]}=!0` : m;
}
return "hideNote:!0";
2023-10-26 15:07:44 -03:00
}
2022-11-24 02:02:15 +01:00
}
},
{
2022-11-24 02:02:15 +01:00
find: "Messages.NOTE_PLACEHOLDER",
replacement: {
match: /\.NOTE_PLACEHOLDER,/,
2024-07-03 21:38:21 +02:00
replace: "$&spellCheck:!$self.noSpellCheck,"
2022-11-24 02:02:15 +01:00
}
}
],
2024-07-03 21:38:21 +02:00
get noSpellCheck() {
return settings.store.noSpellCheck;
}
2022-11-24 02:02:15 +01:00
});