feat: add global theme toggle

This commit is contained in:
SethBurkart123
2025-03-30 08:49:13 +11:00
parent 6147e96cc9
commit 3ecd7205ed
14 changed files with 145 additions and 141 deletions
@@ -1,29 +1,18 @@
import type { Plugin } from '../../core/types';
import { BasePlugin, BooleanSetting } from '../../core/settings';
interface NotificationCollectorStorage {
lastNotificationCount: number;
lastCheckedTime: string;
}
class NotificationCollectorPluginClass extends BasePlugin {
@BooleanSetting({
default: true,
title: "Notification Collector",
description: "Uncaps the 9+ limit for notifications, showing the real number.",
})
enabled!: boolean;
}
// Create an instance to extract settings
const settingsInstance = new NotificationCollectorPluginClass();
const notificationCollectorPlugin: Plugin<typeof settingsInstance.settings, NotificationCollectorStorage> = {
const notificationCollectorPlugin: Plugin<{}, NotificationCollectorStorage> = {
id: 'notificationCollector',
name: 'Notification Collector',
description: 'Collects and displays SEQTA notifications',
version: '1.0.0',
settings: settingsInstance.settings,
settings: {},
disableToggle: true,
run: async (api) => {
let pollInterval: number | null = null;
@@ -80,30 +69,21 @@ const notificationCollectorPlugin: Plugin<typeof settingsInstance.settings, Noti
pollInterval = null;
const alertDiv = document.querySelector(".notifications__bubble___1EkSQ") as HTMLElement;
if (alertDiv) {
alertDiv.textContent = "9+";
if (api.storage.lastNotificationCount > 9) {
alertDiv.textContent = "9+";
} else {
alertDiv.textContent = api.storage.lastNotificationCount.toString();
}
}
}
};
if (api.settings.enabled) {
api.seqta.onMount(".notifications__bubble___1EkSQ", (_) => {
startPolling();
});
}
const enabledCallback = (value: any) => {
if (value) {
startPolling();
} else {
stopPolling();
}
};
api.settings.onChange('enabled', enabledCallback);
api.seqta.onMount(".notifications__bubble___1EkSQ", (_) => {
startPolling();
});
return () => {
stopPolling();
api.settings.offChange('enabled', enabledCallback);
};
}
};
+8 -3
View File
@@ -5,9 +5,9 @@ class TestPluginClass extends BasePlugin {
@BooleanSetting({
default: true,
title: "Test Plugin",
description: "A test plugin for BetterSEQTA+",
description: "Some random setting",
})
enabled!: boolean;
someSetting!: boolean;
}
const settingsInstance = new TestPluginClass();
@@ -22,9 +22,14 @@ const testPlugin: Plugin<typeof settingsInstance.settings> = {
run: async (api) => {
console.log('Test plugin running');
api.seqta.onPageChange((page) => {
const { unregister } = api.seqta.onPageChange((page) => {
console.log('Page changed to', page);
});
return () => {
console.log('Test plugin stopped');
unregister();
}
}
};
+19 -40
View File
@@ -2,53 +2,32 @@ import { settingsState } from '@/seqta/utils/listeners/SettingsState';
import type { Plugin } from '../../core/types';
import { convertTo12HourFormat } from '@/seqta/utils/convertTo12HourFormat';
import { waitForElm } from '@/seqta/utils/waitForElm';
import { BasePlugin, BooleanSetting } from '../../core/settings';
// Define only the typed settings - no need for redundant interface
class TimetablePluginClass extends BasePlugin {
@BooleanSetting({
default: true,
title: "Timetable Enhancer",
description: "Adds extra features to the timetable view."
})
enabled!: boolean;
}
// Create an instance to extract settings
const settingsInstance = new TimetablePluginClass();
const timetablePlugin: Plugin<typeof settingsInstance.settings> = {
const timetablePlugin: Plugin<{}, {}> = {
id: 'timetable',
name: 'Timetable Enhancer',
description: 'Adds extra features to the timetable view',
version: '1.0.0',
settings: settingsInstance.settings,
settings: {},
disableToggle: true,
run: async (api) => {
if (api.settings.enabled) {
api.seqta.onMount('.timetablepage', handleTimetable)
}
const enabledCallback = (value: any) => {
if (value) {
api.seqta.onMount('.timetablepage', handleTimetable)
} else {
const timetablePage = document.querySelector('.timetablepage')
if (timetablePage) {
const zoomControls = document.querySelector('.timetable-zoom-controls')
if (zoomControls) zoomControls.remove()
const hideControls = document.querySelector('.timetable-hide-controls')
if (hideControls) hideControls.remove()
resetTimetableStyles()
}
}
}
api.settings.onChange('enabled', enabledCallback)
const { unregister } = api.seqta.onMount('.timetablepage', handleTimetable)
return () => {
api.settings.offChange('enabled', enabledCallback)
// Call the unregister function to remove the mount listener
unregister();
const timetablePage = document.querySelector('.timetablepage')
if (timetablePage) {
const zoomControls = document.querySelector('.timetable-zoom-controls')
if (zoomControls) zoomControls.remove()
const hideControls = document.querySelector('.timetable-hide-controls')
if (hideControls) hideControls.remove()
resetTimetableStyles()
}
}
}
};