PageSourceSearch

https://fangg.netlify.app/js/windowManager.js

js fangg.netlify.app collected 2026-10-03 10:43:24 UTC 5,655 bytes, 168 lines download raw bytes

1// 窗口管理器 - windowManager.js
2
3// 打开窗口
4function openWindow(windowName) {
5    const window = document.getElementById(windowName + '-window');
6    const taskbarItem = document.getElementById(windowName + '-taskbar');
7    
8    if (window) {
9        window.style.display = 'block';
10        if (taskbarItem) {
11            taskbarItem.style.display = 'flex';
12        }
13        focusWindow(windowName);
14        bringToFront(window);
15
16        // 初始化特定窗口的内容
17        switch(windowName) {
18            case 'snake':
19                if (typeof initSnakeGame === 'function') initSnakeGame();
20                break;
21            case 'calculator':
22                if (typeof initCalculator === 'function') initCalculator();
23                break;
24            case 'album':
25                if (typeof initAlbum === 'function') initAlbum();
26                break;
27            case 'practice':
28                if (typeof initPractice === 'function') initPractice();
29                break;
30            case 'minesweeper':
31                if (typeof initMinesweeper === 'function') initMinesweeper();
32                break;
33            case 'tetris':
34                if (typeof initTetris === 'function') initTetris();
35                break;
36            case 'piano':
37                if (typeof initPiano === 'function') initPiano();
38                break;
39            case 'compressor':
40                if (typeof initImageCompressor === 'function') initImageCompressor();
41                break;
42            case 'ie':
43                if (typeof initIE === 'function') initIE();
44                break;
45            case 'bookmarks':
46                if (typeof initBookmarks === 'function') initBookmarks();
47                break;
48
49            case 'design':
50                if (typeof initDesign === 'function') initDesign();
51                break;
52            case '2048':
53                if (typeof init2048 === 'function') init2048();
54                break;
55            case 'space-invaders':
56                if (typeof initSpaceInvaders === 'function') initSpaceInvaders();
57                break;
58            case 'thoughts':
59                if (typeof initThoughtsList === 'function') initThoughtsList();
60                break;
61        }
62    }
63}
64
65// 关闭窗口
66function closeWindow(windowName) {
67    const window = document.getElementById(windowName + '-window');
68    const taskbarItem = document.getElementById(windowName + '-taskbar');
69    
70    if (window) {
71        window.style.display = 'none';
72        window.classList.remove('maximized');
73        if (taskbarItem) {
74            taskbarItem.style.display = 'none';
75        }
76    }
77}
78
79// 最小化窗口
80function minimizeWindow(windowName) {
81    const window = document.getElementById(windowName + '-window');
82    const taskbarItem = document.getElementById(windowName + '-taskbar');
83    
84    if (window) {
85        window.style.display = 'none';
86        window.classList.remove('maximized');
87        if (taskbarItem) {
88            taskbarItem.style.display = 'flex';
89        }
90    }
91}
92
93// 最大化窗口
94function maximizeWindow(windowName) {
95    const window = document.getElementById(windowName + '-window');
96    if (window) {
97        if (window.classList.contains('maximized')) {
98            window.classList.remove('maximized');
99        } else {
100            window.classList.add('maximized');
101        }
102        focusWindow(windowName);
103    }
104}
105
106// 聚焦窗口
107function focusWindow(windowName) {
108    const windows = document.querySelectorAll('.window');
109    const taskbarItems = document.querySelectorAll('.taskbar-item');
110    
111    // 重置所有窗口和任务栏项目的状态
112    windows.forEach(win => win.style.zIndex = '100');
113    taskbarItems.forEach(item => item.classList.remove('active'));
114    
115    // 设置当前窗口和任务栏项目的状态
116    const currentWindow = document.getElementById(windowName + '-window');
117    const currentTaskbarItem = document.getElementById(windowName + '-taskbar');
118    
119    if (currentWindow) {
120        currentWindow.style.zIndex = '101';
121        currentWindow.style.display = 'block';
122        activeWindow = windowName;
123    }
124    
125    if (currentTaskbarItem) {
126        currentTaskbarItem.classList.add('active');
127        currentTaskbarItem.style.display = 'flex';
128    }
129}
130
131// 将窗口带到前面
132function bringToFront(element) {
133    const windows = document.querySelectorAll('.window');
134    windows.forEach(win => win.style.zIndex = '100');
135    element.style.zIndex = '101';
136}
137
138// BSOD Effect
139let bsodActive = false;
140
141function triggerBSOD() {
142    const bsod = document.getElementById('bsod');
143    if (bsod && !bsodActive) {
144        bsodActive = true;
145        bsod.style.display = 'flex';
146        
147        // 尝试全屏(可能被浏览器阻止)
148        if (document.documentElement.requestFullscreen) {
149            document.documentElement.requestFullscreen().catch(err => {});
150        }
151        
152        // 延迟 1.5 秒后才允许按键/点击重启,给用户时间看蓝屏
153        setTimeout(() => {
154            const reloadHandler = (e) => {
155                e.preventDefault();
156                e.stopPropagation();
157                // 退出全屏
158                if (document.fullscreenElement) {
159                    document.exitFullscreen().catch(err => {});
160                }
161                location.reload();
162            };
163            document.addEventListener('keydown', reloadHandler, { once: true });
164            // 使用 mousedown 而不是 click,避免和触发 BSOD 的点击冲突
165            document.addEventListener('mousedown', reloadHandler, { once: true });
166        }, 1500);
167    }
168}

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.