aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/experiments.tsx
blob: 4cc2167c926859dc033a615c0207d14ba8edee4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { lazyWebpack } from "../utils";
import { Devs } from "../utils/constants";
import definePlugin, { OptionType } from "../utils/types";
import { Settings } from "../Vencord";
import { filters } from "../webpack";
import { Forms, React } from "../webpack/common";

const KbdStyles = lazyWebpack(filters.byProps(["key", "removeBuildOverride"]));

export default definePlugin({
    name: "Experiments",
    authors: [
        Devs.Megu,
        Devs.Ven,
        { name: "Nickyux", id: 427146305651998721n },
        { name: "BanTheNons", id: 460478012794863637n },
    ],
    description: "Enable Access to Experiments in Discord!",
    patches: [{
        find: "Object.defineProperties(this,{isDeveloper",
        replacement: {
            match: /(?<={isDeveloper:\{[^}]+,get:function\(\)\{return )\w/,
            replace: "true"
        },
    }, {
        find: 'type:"user",revision',
        replacement: {
            match: /(\w)\|\|"CONNECTION_OPEN".+?;/g,
            replace: "$1=!0;"
        },
    }, {
        find: ".isStaff=function(){",
        predicate: () => Settings.plugins["Experiments"].enableIsStaff === true,
        replacement: [
            {
                match: /return\s*(\w+)\.hasFlag\((.+?)\.STAFF\)}/,
                replace: "return Vencord.Webpack.Common.UserStore.getCurrentUser().id===$1.id||$1.hasFlag($2.STAFF)}"
            },
            {
                match: /hasFreePremium=function\(\){return this.is Staff\(\)\s*\|\|/,
                replace: "hasFreePremium=function(){return ",
            },
        ],
    }],
    options: {
        enableIsStaff: {
            description: "Enable isStaff (requires restart)",
            type: OptionType.BOOLEAN,
            default: false,
            restartNeeded: true,
        }
    },

    settingsAboutComponent: () => {
        const isMacOS = navigator.platform.includes("Mac");
        const modKey = isMacOS ? "cmd" : "ctrl";
        const altKey = isMacOS ? "opt" : "alt";
        return (
            <React.Fragment>
                <Forms.FormTitle tag="h3">More Information</Forms.FormTitle>
                <Forms.FormText variant="text-md/normal">
                    You can enable client DevTools{" "}
                    <kbd className={KbdStyles.key}>{modKey}</kbd> +{" "}
                    <kbd className={KbdStyles.key}>{altKey}</kbd> +{" "}
                    <kbd className={KbdStyles.key}>O</kbd>{" "}
                    after enabling <code>isStaff</code> below
                </Forms.FormText>
                <Forms.FormText>
                    and then toggling <code>Enable DevTools</code> in the <code>Developer Options</code> tab in settings.
                </Forms.FormText>
            </React.Fragment>
        );
    }
});