Pārlūkot izejas kodu

!2 工作时间不可以玩游戏

pcacc 5 mēneši atpakaļ
vecāks
revīzija
81c376bd7d
1 mainītis faili ar 48 papildinājumiem un 1 dzēšanām
  1. 48 1
      templates/index_dongri.html

+ 48 - 1
templates/index_dongri.html

@@ -77,7 +77,7 @@
             <button class="custom-button" id="resetScript_btn" onclick="reset_script()">重置脚本</button>
             <button class="custom-button" id="closegame_btn" onclick="close_game()">关闭游戏</button>
             <button class="custom-button" id="restartgame_btn" onclick="restart_game()">重新关闭并自动游戏</button>
-            <button class="custom-button" id="atuo_btn" onclick="begin_auto()">自动模式</button>
+            <button class="custom-button" id="atuoRun_btn" onclick="begin_auto()">自动模式</button>
         </div>
     </div>
     
@@ -223,6 +223,48 @@
         function reset_script(){
             socket.emit('reset_script');
         }
+
+        function isWorkingHours() {
+            const now = new Date();
+            const day = now.getDay(); // 0是周日,1是周一,...,6是周六
+            const hours = now.getHours();
+            const minutes = now.getMinutes();
+            
+            // 将当前时间转换为分钟数,方便比较
+            const currentTime = hours * 60 + minutes;
+            
+            // 工作日检查(周一到周五)
+            const isWeekday = day >= 1 && day <= 5;
+            
+            // 工作时间段1: 9:00-11:30 (480-690分钟)
+            const morningStart = 9 * 60;      // 8:00
+            const morningEnd = 11 * 60 + 30;  // 11:30
+            
+            // 工作时间段2: 14:00-17:30 (840-1050分钟)
+            const afternoonStart = 14 * 60;    // 14:00
+            const afternoonEnd = 17 * 60 + 30; // 17:30
+            
+            // 检查是否在工作时间段内
+            const isWorkingTime = isWeekday && 
+                ((currentTime >= morningStart && currentTime <= morningEnd) || 
+                (currentTime >= afternoonStart && currentTime <= afternoonEnd));
+            
+            return isWorkingTime;
+        }
+
+        function updateButtonStatus() {
+            const buttons = document.querySelectorAll('.custom-button');
+            const isDisabled = isWorkingHours();
+            console.log("isDisabled:", isDisabled);
+            
+            buttons.forEach(button => {
+            // 排除restartgame_btn按钮
+            if(button.id !== 'restartgame_btn') {
+                button.disabled = isDisabled;
+            }
+        });
+        }
+
         function stopPageAndCloseSocket() {
             // 获取当前连接的 WebSocket URL
             const socketUrl = socket.io.uri;
@@ -241,6 +283,11 @@
             }
         }
 
+        document.addEventListener('DOMContentLoaded', function() {
+            updateButtonStatus();
+            // 每分钟检查一次时间变化
+            setInterval(updateButtonStatus, 60000);
+        });
         // 页面加载时设置5分钟后的定时器
         window.onload = function() {
             get_title();