PageSourceSearch

https://pupwife.com/projects/chatroom/scripts/components/ComponentManager.js

js pupwife.com collected 2026-09-30 15:06:42 UTC 2,341 bytes, 97 lines download raw bytes

1/**
2 * Component Manager (Vencord-inspired)
3 * Manages and initializes all UI components
4 */
5
6window.ChatroomComponents = (function() {
7    'use strict';
8
9    const components = new Map();
10    const initialized = new Set();
11
12    /**
13     * Register a component
14     */
15    function register(name, component) {
16        if (components.has(name)) {
17            console.warn(`Component ${name} already registered, overwriting...`);
18        }
19        components.set(name, component);
20    }
21
22    /**
23     * Get a component
24     */
25    function get(name) {
26        return components.get(name);
27    }
28
29    /**
30     * Initialize a component
31     */
32    function init(name, ...args) {
33        const component = components.get(name);
34        if (!component) {
35            console.error(`Component ${name} not found`);
36            return false;
37        }
38
39        if (initialized.has(name)) {
40            console.warn(`Component ${name} already initialized`);
41            return true;
42        }
43
44        try {
45            if (typeof component.init === 'function') {
46                component.init(...args);
47                initialized.add(name);
48                console.log(`✅ Component ${name} initialized`);
49                return true;
50            } else {
51                console.error(`Component ${name} has no init method`);
52                return false;
53            }
54        } catch (error) {
55            console.error(`Error initializing component ${name}:`, error);
56            return false;
57        }
58    }
59
60    /**
61     * Initialize all components
62     */
63    function initAll() {
64        const initOrder = [
65            'presence',
66            'moderator',
67            'settings',
68            'reactions',
69            'messageFormatter',
70            'contextMenu',
71            'userProfile',
72            'directMessages',
73            'chatroom'
74        ];
75
76        initOrder.forEach(name => {
77            if (components.has(name)) {
78                init(name);
79            }
80        });
81    }
82
83    /**
84     * Check if component is initialized
85     */
86    function isInitialized(name) {
87        return initialized.has(name);
88    }
89
90    return {
91        register,
92        get,
93        init,
94        initAll,
95        isInitialized
96    };
97})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.