Skip to content

Commit

Permalink
Neat Settings Context Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Cynosphere committed Feb 2, 2025
1 parent 5567ab7 commit d6f6e40
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/neatSettingsContext/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ExtensionWebpackModule, Patch } from "@moonlight-mod/types";

export const patches: Patch[] = [
{
find: 'navId:"user-settings-cog"',
replace: [
{
match: /(?<=,\i=\(0,(\i\.\i)\)\(\)\.filter\(.+?),children:\[(?=\i\.map\()/,
replacement: (_, getSections) => `,children:[require("neatSettingsContext_menu").default(${getSections},`
},
{
match: /\),(?=\i\.user\.isStaff\(\)&&)/,
replacement: ")),"
}
],
hardFail: true
}
];

export const webpackModules: Record<string, ExtensionWebpackModule> = {
menu: {
dependencies: [{ id: "react" }, { ext: "contextMenu", id: "contextMenu" }, { ext: "settings", id: "settings" }]
}
};
15 changes: 15 additions & 0 deletions src/neatSettingsContext/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://moonlight-mod.github.io/manifest.schema.json",
"id": "neatSettingsContext",
"version": "1.0.0",
"meta": {
"name": "Neat Settings Context Menu",
"tagline": "Groups the user settings context menu by their headings",
"authors": ["Cynosphere"],
"tags": ["qol"],
"source": "https://github.com/Cynosphere/moonlight-extensions",
"donate": "https://ko-fi.com/Cynosphere"
},
"dependencies": ["contextMenu", "settings"],
"apiLevel": 2
}
60 changes: 60 additions & 0 deletions src/neatSettingsContext/webpackModules/menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from "@moonlight-mod/wp/react";
import { MenuItem } from "@moonlight-mod/wp/contextMenu_contextMenu";
import { Settings } from "@moonlight-mod/wp/settings_settings";

const DEVELOPER_SECTIONS = [
"Experiments",
"Developer Options",
"Hotspot Options",
"Dismissible Content Options",
"Payment Flow Modals",
"Revenue Storybook",
"Design System",
"Text Playground",
"Text Component",
"Intl Testing",
"Profile Effects Preview Tool",
"Name Plate Tool",
"Web Setting Tree Tool",
"Quest Preview Tool"
];

export default function ReorganizeMenu(getSections: () => any[], sections: any[]) {
const newSections = [];
const currentCategory = [];
const allSections = getSections();

let currentHeader = "Unsorted";
for (const section of allSections) {
const key = section.section.replace(/\W/gi, "_");
const item = sections.find((s) => s.key === key);
if (Settings.sectionNames.includes(section.section)) {
newSections.push(item);
continue;
}
if (section.section === "CUSTOM" || section.section === "logout") continue;

if (section.section === "DIVIDER") {
if (currentCategory.length > 0)
newSections.push(
<MenuItem id={currentHeader.replace(/\W/gi, "_")} label={currentHeader}>
{currentCategory.splice(0, currentCategory.length)}
</MenuItem>
);

currentHeader = "Unsorted";
} else if (section.section === "HEADER") {
currentHeader = section.label;
} else {
if (DEVELOPER_SECTIONS.includes(section.section)) currentHeader = "Developer";

if (currentHeader === "Unsorted") {
newSections.push(item);
} else {
currentCategory.push(item);
}
}
}

return newSections;
}

0 comments on commit d6f6e40

Please sign in to comment.