diff --git a/src/plugins/dayNightSwitcher/README.md b/src/plugins/dayNightSwitcher/README.md new file mode 100644 index 000000000..b520d5118 --- /dev/null +++ b/src/plugins/dayNightSwitcher/README.md @@ -0,0 +1,30 @@ +# DayNight Switcher + +### Overview +The **DayNight Switcher** plugin for Vencord automatically switches between Discord's light and dark themes based on the time of day. Users can easily configure the start times for the day and night themes directly from the plugin settings. + +### Features +- **Automatic Theme Switching**: Automatically applies the light theme during the day and the dark theme at night. +- **Customizable Times**: Configure the start times for day and night themes using the plugin settings. +- **Seamless Integration**: No need for manual installation; simply toggle the plugin in Vencord's plugin settings. + +### Usage Instructions +1. Go to **Vencord Settings** > **Plugins**. +2. Locate the **DayNight Switcher** plugin. +3. Toggle the plugin to enable it. +4. Adjust the following settings to suit your preferences: + - **Day Theme Start Time**: Set the hour (0-23) when the light theme should start. + - **Night Theme Start Time**: Set the hour (0-23) when the dark theme should start. + + The default configuration is set to: + - **Day Theme**: Starts at 8 AM + - **Night Theme**: Starts at 8 PM + +### Example +- If you want the **Day Theme** to start at 7 AM and the **Night Theme** to start at 6 PM: + 1. Open **Vencord Settings** > **DayNight Switcher**. + 2. Set the **Day Theme Start Time** to 7. + 3. Set the **Night Theme Start Time** to 18. + +### License +This plugin is licensed under the GNU General Public License v3.0. See the [LICENSE](https://www.gnu.org/licenses/gpl-3.0.html) for more details. diff --git a/src/plugins/dayNightSwitcher/index.tsx b/src/plugins/dayNightSwitcher/index.tsx new file mode 100644 index 000000000..4865ba470 --- /dev/null +++ b/src/plugins/dayNightSwitcher/index.tsx @@ -0,0 +1,63 @@ +import { definePluginSettings, Settings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import { OptionType } from "@utils/types"; +import definePlugin from "@utils/types"; + +// Define plugin settings with day and night time +const settings = definePluginSettings({ + dayTime: { + type: OptionType.NUMBER, + description: "Day Theme Start Time (Hour)", + default: 8, // Default: 8 AM + isValid: (value) => value >= 0 && value <= 23 || "Must be a valid hour (0-23)" + }, + nightTime: { + type: OptionType.NUMBER, + description: "Night Theme Start Time (Hour)", + default: 20, // Default: 8 PM + isValid: (value) => value >= 0 && value <= 23 || "Must be a valid hour (0-23)" + } +}); + +function setTheme(theme: "light" | "dark") { + const body = document.body; + if (theme === "light") { + body.classList.remove("theme-dark"); + body.classList.add("theme-light"); + } else { + body.classList.remove("theme-light"); + body.classList.add("theme-dark"); + } +} + +// Function to apply light or dark theme based on current time +function applyThemeBasedOnTime() { + const currentHour = new Date().getHours(); + const { dayTime, nightTime } = settings.store; + + if (currentHour >= dayTime && currentHour < nightTime) { + setTheme("light"); + } else { + setTheme("dark"); + } +} + +// Start and stop logic +function startPlugin() { + applyThemeBasedOnTime(); + setInterval(applyThemeBasedOnTime, 3600000); // Check every hour +} + +function stopPlugin() { + // Optionally reset to user's original theme (not implemented yet) +} + +// Plugin export with metadata and settings +export default definePlugin({ + name: "DayNight Switcher", + description: "Automatically switches between Discord's light and dark themes based on time.", + authors: [Devs.Migu], + settings, + start: startPlugin, + stop: stopPlugin +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 0572fa102..c45cd4322 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -575,6 +575,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "RamziAH", id: 1279957227612147747n, }, + Migu: { + name: "MiguVT", + id: 813034603854037024n, + }, } satisfies Record); // iife so #__PURE__ works correctly