Browse Source

【初始】添加学习时长统计与番茄钟应用

- 新增单 HTML 文件架构的学习时长统计与番茄钟应用
- 实现总学习时长统计、番茄钟和空闲钟三大核心功能
- 采用原生 HTML、CSS 和 JavaScript 开发,无外部依赖
- 使用 localStorage 进行数据持久化存储
- 支持响应式布局,适配不同屏幕尺寸
- 添加浏览器通知和声音提醒功能
- 编写详细的 README 文档,包含中英文两个版本
PJ568 1 year ago
commit
8e0b4fc87c
5 changed files with 1568 additions and 0 deletions
  1. 427 0
      LICENSE
  2. 105 0
      README.en.md
  3. 105 0
      README.md
  4. 132 0
      docs/design.md
  5. 799 0
      index.html

+ 427 - 0
LICENSE

@@ -0,0 +1,427 @@
+Attribution-ShareAlike 4.0 International
+
+=======================================================================
+
+Creative Commons Corporation ("Creative Commons") is not a law firm and
+does not provide legal services or legal advice. Distribution of
+Creative Commons public licenses does not create a lawyer-client or
+other relationship. Creative Commons makes its licenses and related
+information available on an "as-is" basis. Creative Commons gives no
+warranties regarding its licenses, any material licensed under their
+terms and conditions, or any related information. Creative Commons
+disclaims all liability for damages resulting from their use to the
+fullest extent possible.
+
+Using Creative Commons Public Licenses
+
+Creative Commons public licenses provide a standard set of terms and
+conditions that creators and other rights holders may use to share
+original works of authorship and other material subject to copyright
+and certain other rights specified in the public license below. The
+following considerations are for informational purposes only, are not
+exhaustive, and do not form part of our licenses.
+
+     Considerations for licensors: Our public licenses are
+     intended for use by those authorized to give the public
+     permission to use material in ways otherwise restricted by
+     copyright and certain other rights. Our licenses are
+     irrevocable. Licensors should read and understand the terms
+     and conditions of the license they choose before applying it.
+     Licensors should also secure all rights necessary before
+     applying our licenses so that the public can reuse the
+     material as expected. Licensors should clearly mark any
+     material not subject to the license. This includes other CC-
+     licensed material, or material used under an exception or
+     limitation to copyright. More considerations for licensors:
+	wiki.creativecommons.org/Considerations_for_licensors
+
+     Considerations for the public: By using one of our public
+     licenses, a licensor grants the public permission to use the
+     licensed material under specified terms and conditions. If
+     the licensor's permission is not necessary for any reason--for
+     example, because of any applicable exception or limitation to
+     copyright--then that use is not regulated by the license. Our
+     licenses grant only permissions under copyright and certain
+     other rights that a licensor has authority to grant. Use of
+     the licensed material may still be restricted for other
+     reasons, including because others have copyright or other
+     rights in the material. A licensor may make special requests,
+     such as asking that all changes be marked or described.
+     Although not required by our licenses, you are encouraged to
+     respect those requests where reasonable. More_considerations
+     for the public: 
+	wiki.creativecommons.org/Considerations_for_licensees
+
+=======================================================================
+
+Creative Commons Attribution-ShareAlike 4.0 International Public
+License
+
+By exercising the Licensed Rights (defined below), You accept and agree
+to be bound by the terms and conditions of this Creative Commons
+Attribution-ShareAlike 4.0 International Public License ("Public
+License"). To the extent this Public License may be interpreted as a
+contract, You are granted the Licensed Rights in consideration of Your
+acceptance of these terms and conditions, and the Licensor grants You
+such rights in consideration of benefits the Licensor receives from
+making the Licensed Material available under these terms and
+conditions.
+
+
+Section 1 -- Definitions.
+
+  a. Adapted Material means material subject to Copyright and Similar
+     Rights that is derived from or based upon the Licensed Material
+     and in which the Licensed Material is translated, altered,
+     arranged, transformed, or otherwise modified in a manner requiring
+     permission under the Copyright and Similar Rights held by the
+     Licensor. For purposes of this Public License, where the Licensed
+     Material is a musical work, performance, or sound recording,
+     Adapted Material is always produced where the Licensed Material is
+     synched in timed relation with a moving image.
+
+  b. Adapter's License means the license You apply to Your Copyright
+     and Similar Rights in Your contributions to Adapted Material in
+     accordance with the terms and conditions of this Public License.
+
+  c. BY-SA Compatible License means a license listed at
+     creativecommons.org/compatiblelicenses, approved by Creative
+     Commons as essentially the equivalent of this Public License.
+
+  d. Copyright and Similar Rights means copyright and/or similar rights
+     closely related to copyright including, without limitation,
+     performance, broadcast, sound recording, and Sui Generis Database
+     Rights, without regard to how the rights are labeled or
+     categorized. For purposes of this Public License, the rights
+     specified in Section 2(b)(1)-(2) are not Copyright and Similar
+     Rights.
+
+  e. Effective Technological Measures means those measures that, in the
+     absence of proper authority, may not be circumvented under laws
+     fulfilling obligations under Article 11 of the WIPO Copyright
+     Treaty adopted on December 20, 1996, and/or similar international
+     agreements.
+
+  f. Exceptions and Limitations means fair use, fair dealing, and/or
+     any other exception or limitation to Copyright and Similar Rights
+     that applies to Your use of the Licensed Material.
+
+  g. License Elements means the license attributes listed in the name
+     of a Creative Commons Public License. The License Elements of this
+     Public License are Attribution and ShareAlike.
+
+  h. Licensed Material means the artistic or literary work, database,
+     or other material to which the Licensor applied this Public
+     License.
+
+  i. Licensed Rights means the rights granted to You subject to the
+     terms and conditions of this Public License, which are limited to
+     all Copyright and Similar Rights that apply to Your use of the
+     Licensed Material and that the Licensor has authority to license.
+
+  j. Licensor means the individual(s) or entity(ies) granting rights
+     under this Public License.
+
+  k. Share means to provide material to the public by any means or
+     process that requires permission under the Licensed Rights, such
+     as reproduction, public display, public performance, distribution,
+     dissemination, communication, or importation, and to make material
+     available to the public including in ways that members of the
+     public may access the material from a place and at a time
+     individually chosen by them.
+
+  l. Sui Generis Database Rights means rights other than copyright
+     resulting from Directive 96/9/EC of the European Parliament and of
+     the Council of 11 March 1996 on the legal protection of databases,
+     as amended and/or succeeded, as well as other essentially
+     equivalent rights anywhere in the world.
+
+  m. You means the individual or entity exercising the Licensed Rights
+     under this Public License. Your has a corresponding meaning.
+
+
+Section 2 -- Scope.
+
+  a. License grant.
+
+       1. Subject to the terms and conditions of this Public License,
+          the Licensor hereby grants You a worldwide, royalty-free,
+          non-sublicensable, non-exclusive, irrevocable license to
+          exercise the Licensed Rights in the Licensed Material to:
+
+            a. reproduce and Share the Licensed Material, in whole or
+               in part; and
+
+            b. produce, reproduce, and Share Adapted Material.
+
+       2. Exceptions and Limitations. For the avoidance of doubt, where
+          Exceptions and Limitations apply to Your use, this Public
+          License does not apply, and You do not need to comply with
+          its terms and conditions.
+
+       3. Term. The term of this Public License is specified in Section
+          6(a).
+
+       4. Media and formats; technical modifications allowed. The
+          Licensor authorizes You to exercise the Licensed Rights in
+          all media and formats whether now known or hereafter created,
+          and to make technical modifications necessary to do so. The
+          Licensor waives and/or agrees not to assert any right or
+          authority to forbid You from making technical modifications
+          necessary to exercise the Licensed Rights, including
+          technical modifications necessary to circumvent Effective
+          Technological Measures. For purposes of this Public License,
+          simply making modifications authorized by this Section 2(a)
+          (4) never produces Adapted Material.
+
+       5. Downstream recipients.
+
+            a. Offer from the Licensor -- Licensed Material. Every
+               recipient of the Licensed Material automatically
+               receives an offer from the Licensor to exercise the
+               Licensed Rights under the terms and conditions of this
+               Public License.
+
+            b. Additional offer from the Licensor -- Adapted Material.
+               Every recipient of Adapted Material from You
+               automatically receives an offer from the Licensor to
+               exercise the Licensed Rights in the Adapted Material
+               under the conditions of the Adapter's License You apply.
+
+            c. No downstream restrictions. You may not offer or impose
+               any additional or different terms or conditions on, or
+               apply any Effective Technological Measures to, the
+               Licensed Material if doing so restricts exercise of the
+               Licensed Rights by any recipient of the Licensed
+               Material.
+
+       6. No endorsement. Nothing in this Public License constitutes or
+          may be construed as permission to assert or imply that You
+          are, or that Your use of the Licensed Material is, connected
+          with, or sponsored, endorsed, or granted official status by,
+          the Licensor or others designated to receive attribution as
+          provided in Section 3(a)(1)(A)(i).
+
+  b. Other rights.
+
+       1. Moral rights, such as the right of integrity, are not
+          licensed under this Public License, nor are publicity,
+          privacy, and/or other similar personality rights; however, to
+          the extent possible, the Licensor waives and/or agrees not to
+          assert any such rights held by the Licensor to the limited
+          extent necessary to allow You to exercise the Licensed
+          Rights, but not otherwise.
+
+       2. Patent and trademark rights are not licensed under this
+          Public License.
+
+       3. To the extent possible, the Licensor waives any right to
+          collect royalties from You for the exercise of the Licensed
+          Rights, whether directly or through a collecting society
+          under any voluntary or waivable statutory or compulsory
+          licensing scheme. In all other cases the Licensor expressly
+          reserves any right to collect such royalties.
+
+
+Section 3 -- License Conditions.
+
+Your exercise of the Licensed Rights is expressly made subject to the
+following conditions.
+
+  a. Attribution.
+
+       1. If You Share the Licensed Material (including in modified
+          form), You must:
+
+            a. retain the following if it is supplied by the Licensor
+               with the Licensed Material:
+
+                 i. identification of the creator(s) of the Licensed
+                    Material and any others designated to receive
+                    attribution, in any reasonable manner requested by
+                    the Licensor (including by pseudonym if
+                    designated);
+
+                ii. a copyright notice;
+
+               iii. a notice that refers to this Public License;
+
+                iv. a notice that refers to the disclaimer of
+                    warranties;
+
+                 v. a URI or hyperlink to the Licensed Material to the
+                    extent reasonably practicable;
+
+            b. indicate if You modified the Licensed Material and
+               retain an indication of any previous modifications; and
+
+            c. indicate the Licensed Material is licensed under this
+               Public License, and include the text of, or the URI or
+               hyperlink to, this Public License.
+
+       2. You may satisfy the conditions in Section 3(a)(1) in any
+          reasonable manner based on the medium, means, and context in
+          which You Share the Licensed Material. For example, it may be
+          reasonable to satisfy the conditions by providing a URI or
+          hyperlink to a resource that includes the required
+          information.
+
+       3. If requested by the Licensor, You must remove any of the
+          information required by Section 3(a)(1)(A) to the extent
+          reasonably practicable.
+
+  b. ShareAlike.
+
+     In addition to the conditions in Section 3(a), if You Share
+     Adapted Material You produce, the following conditions also apply.
+
+       1. The Adapter's License You apply must be a Creative Commons
+          license with the same License Elements, this version or
+          later, or a BY-SA Compatible License.
+
+       2. You must include the text of, or the URI or hyperlink to, the
+          Adapter's License You apply. You may satisfy this condition
+          in any reasonable manner based on the medium, means, and
+          context in which You Share Adapted Material.
+
+       3. You may not offer or impose any additional or different terms
+          or conditions on, or apply any Effective Technological
+          Measures to, Adapted Material that restrict exercise of the
+          rights granted under the Adapter's License You apply.
+
+
+Section 4 -- Sui Generis Database Rights.
+
+Where the Licensed Rights include Sui Generis Database Rights that
+apply to Your use of the Licensed Material:
+
+  a. for the avoidance of doubt, Section 2(a)(1) grants You the right
+     to extract, reuse, reproduce, and Share all or a substantial
+     portion of the contents of the database;
+
+  b. if You include all or a substantial portion of the database
+     contents in a database in which You have Sui Generis Database
+     Rights, then the database in which You have Sui Generis Database
+     Rights (but not its individual contents) is Adapted Material,
+
+     including for purposes of Section 3(b); and
+  c. You must comply with the conditions in Section 3(a) if You Share
+     all or a substantial portion of the contents of the database.
+
+For the avoidance of doubt, this Section 4 supplements and does not
+replace Your obligations under this Public License where the Licensed
+Rights include other Copyright and Similar Rights.
+
+
+Section 5 -- Disclaimer of Warranties and Limitation of Liability.
+
+  a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
+     EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
+     AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
+     ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
+     IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
+     WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
+     PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
+     ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
+     KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
+     ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
+
+  b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
+     TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
+     NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
+     INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
+     COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
+     USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
+     ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
+     DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
+     IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
+
+  c. The disclaimer of warranties and limitation of liability provided
+     above shall be interpreted in a manner that, to the extent
+     possible, most closely approximates an absolute disclaimer and
+     waiver of all liability.
+
+
+Section 6 -- Term and Termination.
+
+  a. This Public License applies for the term of the Copyright and
+     Similar Rights licensed here. However, if You fail to comply with
+     this Public License, then Your rights under this Public License
+     terminate automatically.
+
+  b. Where Your right to use the Licensed Material has terminated under
+     Section 6(a), it reinstates:
+
+       1. automatically as of the date the violation is cured, provided
+          it is cured within 30 days of Your discovery of the
+          violation; or
+
+       2. upon express reinstatement by the Licensor.
+
+     For the avoidance of doubt, this Section 6(b) does not affect any
+     right the Licensor may have to seek remedies for Your violations
+     of this Public License.
+
+  c. For the avoidance of doubt, the Licensor may also offer the
+     Licensed Material under separate terms or conditions or stop
+     distributing the Licensed Material at any time; however, doing so
+     will not terminate this Public License.
+
+  d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
+     License.
+
+
+Section 7 -- Other Terms and Conditions.
+
+  a. The Licensor shall not be bound by any additional or different
+     terms or conditions communicated by You unless expressly agreed.
+
+  b. Any arrangements, understandings, or agreements regarding the
+     Licensed Material not stated herein are separate from and
+     independent of the terms and conditions of this Public License.
+
+
+Section 8 -- Interpretation.
+
+  a. For the avoidance of doubt, this Public License does not, and
+     shall not be interpreted to, reduce, limit, restrict, or impose
+     conditions on any use of the Licensed Material that could lawfully
+     be made without permission under this Public License.
+
+  b. To the extent possible, if any provision of this Public License is
+     deemed unenforceable, it shall be automatically reformed to the
+     minimum extent necessary to make it enforceable. If the provision
+     cannot be reformed, it shall be severed from this Public License
+     without affecting the enforceability of the remaining terms and
+     conditions.
+
+  c. No term or condition of this Public License will be waived and no
+     failure to comply consented to unless expressly agreed to by the
+     Licensor.
+
+  d. Nothing in this Public License constitutes or may be interpreted
+     as a limitation upon, or waiver of, any privileges and immunities
+     that apply to the Licensor or You, including from the legal
+     processes of any jurisdiction or authority.
+
+
+=======================================================================
+
+Creative Commons is not a party to its public
+licenses. Notwithstanding, Creative Commons may elect to apply one of
+its public licenses to material it publishes and in those instances
+will be considered the “Licensor.” The text of the Creative Commons
+public licenses is dedicated to the public domain under the CC0 Public
+Domain Dedication. Except for the limited purpose of indicating that
+material is shared under a Creative Commons public license or as
+otherwise permitted by the Creative Commons policies published at
+creativecommons.org/policies, Creative Commons does not authorize the
+use of the trademark "Creative Commons" or any other trademark or logo
+of Creative Commons without its prior written consent including,
+without limitation, in connection with any unauthorized modifications
+to any of its public licenses or any other arrangements,
+understandings, or agreements concerning use of licensed material. For
+the avoidance of doubt, this paragraph does not form part of the
+public licenses.
+
+Creative Commons may be contacted at creativecommons.org.

+ 105 - 0
README.en.md

@@ -0,0 +1,105 @@
+# 🎓🍅♨️ Study Time Tracker & Pomodoro Timer
+
+> [简体中文](README.md) | ENGLISH
+
+A simple and efficient single HTML Pomodoro timer application that helps users track study time and manage time effectively.
+
+## 📋 Project Overview
+
+This project uses a single HTML file architecture without any external framework dependencies, implemented with native HTML, CSS, and JavaScript. The application includes three core features:
+
+- 🎓 **Total Study Time Tracker**: Accurately records and accumulates user's effective study time
+- 🍅 **Pomodoro Timer**: Customizable countdown focus tool with an intuitive circular progress bar
+- ♨️ **Idle Timer**: Independent break countdown tool with a linear progress bar
+
+## ✨ Key Features
+
+### 🎓 Study Time Tracker
+
+- Precise time tracking to the second
+- Persistent data storage (using `localStorage`)
+- Clear display in "hours:minutes" format
+- Data is preserved even after closing the page
+
+### 🍅 Pomodoro Timer
+
+- Customizable countdown duration (default 25 minutes)
+- Intuitive circular progress bar display
+- Complete control functions: start, pause, stop
+- Automatically adds elapsed time to total study time when countdown ends or is stopped
+- Supports browser notifications and sound alerts
+
+### ♨️ Idle Timer
+
+- Customizable countdown duration (default 5 minutes)
+- Clean linear progress bar display
+- Independent timing function that doesn't affect study time statistics
+- Also supports start, pause, and stop controls
+
+### 📱 Responsive Design
+
+The application uses responsive layout that automatically adapts to different screen sizes:
+
+- **Large screen devices** (> 1200px): 2x2 grid layout
+- **Medium screen devices** (768px - 1200px): Horizontal three-column layout
+- **Small screen devices** (< 768px): Vertical compact layout
+
+## 🚀 How to Use
+
+1. Simply open the [`index.html`](index.html) file in your browser to start using it
+2. No need to install any dependencies or server environment
+3. All data is automatically saved in browser local storage
+
+### Basic Operations
+
+1. **Set Time**: Click on the time input field to customize the duration of the Pomodoro or Idle timer
+2. **Start Timer**: Click the ▶️ button to start the countdown
+3. **Pause/Resume**: Click the ⏸️ button to pause or resume the timer
+4. **Stop Timer**: Click the ⏹️ button to stop the timer (Pomodoro timer will add elapsed time to total study time)
+
+## 🛠️ Technical Implementation
+
+### Tech Stack
+
+- **Frontend**: Native HTML, CSS, JavaScript
+- **Data Storage**: Browser `localStorage`
+- **Styling**: Native CSS, no external dependencies
+
+### Core Architecture
+
+- **Data Management Module**: Unified management of time data storage and formatting
+- **Pomodoro Timer Controller**: `PomodoroTimer` class, handles all Pomodoro timer logic
+- **Idle Timer Controller**: `IdleTimer` class, handles all idle timer logic
+- **Responsive Layout**: Uses CSS Grid and Flexbox to achieve adaptive layout
+
+### Data Structure
+
+```json
+{
+  "totalStudyTime": 0,
+  "pomodoroTime": 1500,
+  "idleTime": 300
+}
+```
+
+## 📄 License
+
+This project is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International](LICENSE) license.
+
+## 📖 Design Documentation
+
+For detailed design documentation, please refer to [`docs/design.md`](docs/design.md).
+
+## 🤝 Contributing
+
+Issues and Pull Requests are welcome to improve this project!
+
+## 📝 Changelog
+
+### Initial Version
+
+- Implemented basic Pomodoro and Idle timer functionality
+- Added study time tracking feature
+- Implemented responsive layout
+- Added persistent data storage
+- Support for browser notifications and sound alerts

+ 105 - 0
README.md

@@ -0,0 +1,105 @@
+# 🎓🍅♨️ 学习时长统计与番茄钟应用
+
+> 简体中文 | [ENGLISH](README.en.md)
+
+一个简洁、高效的单 HTML 番茄钟应用,帮助用户记录学习时长并有效管理时间。
+
+## 📋 项目概述
+
+本项目采用单 HTML 文件架构,无需依赖任何外部框架,使用原生 HTML、CSS 和 JavaScript 实现。应用包含三大核心功能:
+
+- 🎓 **总学习时长统计**:精确记录并累计用户的有效学习时间
+- 🍅 **番茄钟**:可自定义倒计时的专注工具,配有直观的圆形进度条
+- ♨️ **空闲钟**:独立的休息倒计时工具,配有条形进度条
+
+## ✨ 主要特性
+
+### 🎓 学习时长统计
+
+- 精确到秒的时间统计
+- 数据持久化存储(使用 `localStorage`)
+- 以"小时:分钟"格式清晰展示
+- 关闭页面后数据不丢失
+
+### 🍅 番茄钟
+
+- 可自定义倒计时长(默认 25 分钟)
+- 直观的圆形进度条显示
+- 完整的控制功能:开始、暂停、停止
+- 倒计时结束或取消时,自动将已进行时间计入总学习时长
+- 支持浏览器通知和声音提醒
+
+### ♨️ 空闲钟
+
+- 可自定义倒计时长(默认 5 分钟)
+- 简洁的条形进度条显示
+- 独立的计时功能,不影响学习时长统计
+- 同样支持开始、暂停、停止控制
+
+### 📱 响应式设计
+
+应用采用响应式布局,自动适配不同屏幕尺寸:
+
+- **大屏幕设备**(> 1200px):2x2 网格布局
+- **中等屏幕设备**(768px - 1200px):水平三列布局
+- **小屏幕设备**(< 768px):垂直紧凑布局
+
+## 🚀 使用方法
+
+1. 直接在浏览器中打开 [`index.html`](index.html) 文件即可使用
+2. 无需安装任何依赖或服务器环境
+3. 所有数据自动保存在浏览器本地存储中
+
+### 基本操作
+
+1. **设置时间**:点击时间输入框,可自定义番茄钟或空闲钟的时长
+2. **开始计时**:点击 ▶️ 按钮开始倒计时
+3. **暂停/继续**:点击 ⏸️ 按钮暂停或继续计时
+4. **停止计时**:点击 ⏹️ 按钮停止计时(番茄钟会将已进行时间加入总学习时长)
+
+## 🛠️ 技术实现
+
+### 技术栈
+
+- **前端**:原生 HTML、CSS、JavaScript
+- **数据存储**:浏览器 `localStorage`
+- **样式**:原生 CSS,无外部依赖
+
+### 核心架构
+
+- **数据管理模块**:统一管理时间数据的存储和格式化
+- **番茄钟控制器**:`PomodoroTimer` 类,处理番茄钟的所有逻辑
+- **空闲钟控制器**:`IdleTimer` 类,处理空闲钟的所有逻辑
+- **响应式布局**:使用 CSS Grid 和 Flexbox 实现自适应布局
+
+### 数据结构
+
+```json
+{
+  "totalStudyTime": 0,
+  "pomodoroTime": 1500,
+  "idleTime": 300
+}
+```
+
+## 📄 许可证
+
+本项目采用 [Creative Commons Attribution-ShareAlike 4.0 International](LICENSE) 许可证。
+
+## 📖 设计文档
+
+详细的设计文档请参考 [`docs/design.md`](docs/design.md)。
+
+## 🤝 贡献
+
+欢迎提交 Issue 和 Pull Request 来改进这个项目!
+
+## 📝 更新日志
+
+### 初始版本
+
+- 实现基础的番茄钟和空闲钟功能
+- 添加学习时长统计功能
+- 实现响应式布局
+- 添加数据持久化存储
+- 支持浏览器通知和声音提醒

+ 132 - 0
docs/design.md

@@ -0,0 +1,132 @@
+# 单 HTML 番茄钟应用设计文档
+
+## 1. 概述
+
+本文档旨在设计一个简洁、高效的单 HTML 番茄钟应用,帮助用户记录学习时长并有效管理时间。应用将包含总学习时长统计、可自定义的番茄钟和独立的空闲钟三大核心功能。
+
+## 2. 功能需求
+
+### 2.1 核心功能
+
+- **已学习时长**
+  - 精确到秒,持续累加用户的有效学习时间。
+  - 以“X:X”(小时:分钟)的格式清晰展示。
+  - 数据通过浏览器 `localStorage` 持久化,关闭页面不丢失。
+- **番茄钟**
+  - 用户可自定义倒计时长(小时:分钟:秒)(默认为 25 分钟)。
+  - 提供“▶️(开始)”、“⏸️(暂停)”、“⏹️(停止)”控制功能。
+  - 倒计时结束或取消时,将已进行的时间计入“已学习时长”。
+  - 界面需包含一个直观的圆形进度条,实时反馈剩余时间。
+  - 倒计时结束时,通过浏览器通知或声音进行提醒。
+- **空闲钟**
+  - 一个独立的、简单的倒计时工具。
+  - 用户可自定义倒计时长(小时:分钟:秒)(默认为 5 分钟)。
+  - 提供“▶️(开始)”、“⏸️(暂停)”、“⏹️(停止)”功能。
+  - 界面需包含一个直观的条形进度条,实时反馈剩余时间。
+  - 此倒计时不计入总学习时长。
+
+### 2.2 技术选型
+
+- **前端框架**:无。使用原生 HTML、CSS 和 JavaScript,确保应用轻量、快速。遵循最小、最简代码原则。
+- **数据存储**:`localStorage`,用于持久化存储总学习时长。
+- **样式**:原生 CSS,实现简洁、方角、无阴影且现代化的界面风格。
+
+## 3. 界面与交互设计 (UI/UX)
+
+采用无文字描述的界面以提升不同语种用户体验。(标题为“🎓🍅♨️”)
+
+应用将采用响应式网格布局,根据不同屏幕尺寸自动调整排列方式,确保所有功能在任何设备上都能一次性展示,无需滚动。
+
+### 3.1 响应式布局策略
+
+#### 大屏幕设备(> 1200px)
+
+采用 2x2 网格布局,番茄钟占据左侧两个单元格,突出主要功能:
+
+```mermaid
+graph TD
+    A[主容器 - CSS Grid] --> B[🍅番茄钟区域 - 2x1];
+    A --> C[🎓总学习时长 - 1x1];
+    A --> D[♨️空闲钟 - 1x1];
+
+    B --> B1[圆形进度条];
+    B --> B2[剩余时间];
+    B --> B3[控制按钮];
+
+    C --> C1["小时:分钟"];
+
+    D --> D1[条形进度条];
+    D --> D2[剩余时间];
+    D --> D3[控制按钮];
+```
+
+#### 中等屏幕设备(768px - 1200px)
+
+采用水平三列布局,番茄钟占据 50% 宽度:
+
+```mermaid
+graph TD
+    A[主容器 - Flexbox] --> B[🍅番茄钟区域 - 50%];
+    A --> C[🎓总学习时长 - 25%];
+    A --> D[♨️空闲钟 - 25%];
+
+    B --> B1[圆形进度条];
+    B --> B2[剩余时间];
+    B --> B3[控制按钮];
+
+    C --> C1["小时:分钟"];
+
+    D --> D1[条形进度条];
+    D --> D2[剩余时间];
+    D --> D3[控制按钮];
+```
+
+#### 小屏幕设备(< 768px)
+
+采用紧凑型垂直布局,确保总高度不超过屏幕可视区域:
+
+```mermaid
+graph TD
+    A[主容器 - Flexbox Column] --> B[🎓总学习时长 - 紧凑];
+    A --> C[🍅番茄钟区域 - 主要];
+    A --> D[♨️空闲钟 - 紧凑];
+
+    B --> B1["小时:分钟"];
+
+    C --> C1[圆形进度条];
+    C --> C2[剩余时间];
+    C --> C3[控制按钮];
+
+    D --> D1[条形进度条];
+    D --> D2[剩余时间];
+    D --> D3[控制按钮];
+```
+
+### 3.2 响应式断点设计
+
+- **小屏幕**:< 768px,垂直紧凑布局
+- **中等屏幕**:768px - 1200px,水平三列布局
+- **大屏幕**:> 1200px,2x2 网格布局
+
+### 3.3 布局切换动画
+
+屏幕尺寸变化时,应用平滑的过渡动画,保持用户操作状态的连续性,确保用户体验的一致性。
+
+当番茄钟或空闲钟未处于运行状态时,“剩余时间”可编辑,操作按钮处显示“▶️(开始)”按钮。
+当番茄钟或空闲钟处于运行状态时,“剩余时间”不可编辑,操作按钮处显示“⏸️(暂停)”和“⏹️(停止)”按钮。
+
+## 4. 数据结构
+
+应用所需的数据结构非常简单,将使用一个 JSON 对象存储在 `localStorage` 中。
+
+```json
+{
+  "totalStudyTime": 0,
+  "pomodoroTime": 1500,
+  "idleTime": 300
+}
+```
+
+- `totalStudyTime`: 以秒为单位存储的总学习时长。
+- `pomodoroTime`: 以秒为单位存储的番茄钟时长。
+- `idleTime`: 以秒为单位存储的空闲钟时长。

+ 799 - 0
index.html

@@ -0,0 +1,799 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+  <head>
+    <meta charset="UTF-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <title>🎓🍅♨️</title>
+    <style>
+      /* 重置样式 */
+      * {
+        margin: 0;
+        padding: 0;
+        box-sizing: border-box;
+      }
+
+      body {
+        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
+          sans-serif;
+        background-color: #f5f5f5;
+        color: #333;
+        height: 100vh;
+        overflow: hidden;
+      }
+
+      /* 主容器 */
+      .container {
+        width: 100%;
+        height: 100vh;
+        display: flex;
+        flex-direction: column;
+        padding: 20px;
+        gap: 20px;
+      }
+
+      /* 标题 */
+      .title {
+        text-align: center;
+        font-size: 2rem;
+        margin-bottom: 10px;
+      }
+
+      /* 内容区域 */
+      .content {
+        flex: 1;
+        display: flex;
+        flex-direction: column;
+        gap: 20px;
+      }
+
+      /* 总学习时长 */
+      .study-time {
+        background-color: #fff;
+        border-radius: 8px;
+        padding: 20px;
+        text-align: center;
+        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
+      }
+
+      .study-time-display {
+        font-size: 3rem;
+        font-weight: bold;
+        color: #4caf50;
+      }
+
+      /* 番茄钟和空闲钟容器 */
+      .timer-container {
+        flex: 1;
+        display: flex;
+        flex-direction: column;
+        gap: 20px;
+      }
+
+      /* 番茄钟 */
+      .pomodoro {
+        background-color: #fff;
+        border-radius: 8px;
+        padding: 20px;
+        flex: 2;
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+        justify-content: center;
+        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
+      }
+
+      /* 空闲钟 */
+      .idle {
+        background-color: #fff;
+        border-radius: 8px;
+        padding: 20px;
+        flex: 1;
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+        justify-content: center;
+        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
+      }
+
+      /* 圆形进度条容器 */
+      .circular-progress {
+        position: relative;
+        width: 200px;
+        height: 200px;
+        margin: 20px 0;
+      }
+
+      .circular-progress svg {
+        width: 100%;
+        height: 100%;
+        transform: rotate(-90deg);
+      }
+
+      .circular-progress .background {
+        fill: none;
+        stroke: #e0e0e0;
+        stroke-width: 10;
+      }
+
+      .circular-progress .progress {
+        fill: none;
+        stroke: #ff5722;
+        stroke-width: 10;
+        stroke-linecap: round;
+        stroke-dasharray: 565.48;
+        stroke-dashoffset: 565.48;
+        transition: stroke-dashoffset 1s linear;
+      }
+
+      .circular-progress .time-display {
+        position: absolute;
+        top: 50%;
+        left: 50%;
+        transform: translate(-50%, -50%);
+        font-size: 2rem;
+        font-weight: bold;
+      }
+
+      /* 条形进度条 */
+      .linear-progress {
+        width: 100%;
+        height: 20px;
+        background-color: #e0e0e0;
+        border-radius: 10px;
+        margin: 20px 0;
+        overflow: hidden;
+      }
+
+      .linear-progress .progress {
+        height: 100%;
+        background-color: #2196f3;
+        width: 0%;
+        transition: width 1s linear;
+      }
+
+      /* 时间输入 */
+      .time-input {
+        font-size: 1.5rem;
+        border: none;
+        background: transparent;
+        text-align: center;
+        width: 100px;
+        font-weight: bold;
+        transition: all 0.3s ease;
+      }
+
+      .time-input:focus {
+        outline: none;
+        background-color: #f0f0f0;
+        border-radius: 4px;
+        transform: scale(1.05);
+      }
+
+      .time-input:disabled {
+        cursor: not-allowed;
+        opacity: 0.7;
+      }
+
+      /* 控制按钮 */
+      .controls {
+        display: flex;
+        gap: 10px;
+        margin-top: 20px;
+      }
+
+      .btn {
+        background: none;
+        border: none;
+        font-size: 1.5rem;
+        cursor: pointer;
+        padding: 10px;
+        border-radius: 50%;
+        transition: all 0.3s ease;
+      }
+
+      .btn:hover {
+        background-color: #f0f0f0;
+        transform: scale(1.1);
+      }
+
+      .btn:active {
+        transform: scale(0.95);
+      }
+
+      .btn:disabled {
+        opacity: 0.5;
+        cursor: not-allowed;
+        transform: none;
+      }
+
+      /* 响应式布局 */
+      @media (min-width: 768px) {
+        .content {
+          flex-direction: row;
+          transition: flex-direction 0.3s ease;
+        }
+
+        .study-time {
+          flex: 1;
+          transition: flex 0.3s ease;
+        }
+
+        .timer-container {
+          flex: 2;
+          flex-direction: row;
+          transition: flex 0.3s ease, flex-direction 0.3s ease;
+        }
+      }
+
+      @media (min-width: 1200px) {
+        .container {
+          display: grid;
+          grid-template-columns: 2fr 1fr;
+          grid-template-rows: auto 1fr 1fr;
+          gap: 20px;
+          transition: all 0.3s ease;
+        }
+
+        .title {
+          grid-column: 1 / -1;
+        }
+
+        .pomodoro {
+          grid-row: 2 / 4;
+          grid-column: 1;
+          transition: all 0.3s ease;
+        }
+
+        .study-time {
+          grid-row: 2;
+          grid-column: 2;
+          transition: all 0.3s ease;
+        }
+
+        .idle {
+          grid-row: 3;
+          grid-column: 2;
+          transition: all 0.3s ease;
+        }
+
+        .content {
+          display: contents;
+        }
+
+        .timer-container {
+          display: contents;
+        }
+      }
+    </style>
+  </head>
+  <body>
+    <div class="container">
+      <h1 class="title">🎓🍅♨️</h1>
+
+      <div class="content">
+        <div class="study-time">
+          <h2>🎓</h2>
+          <div class="study-time-display">0:00</div>
+        </div>
+
+        <div class="timer-container">
+          <div class="pomodoro">
+            <h2>🍅</h2>
+            <div class="circular-progress">
+              <svg>
+                <circle class="background" cx="100" cy="100" r="90"></circle>
+                <circle class="progress" cx="100" cy="100" r="90"></circle>
+              </svg>
+              <div class="time-display">
+                <input type="text" class="time-input" value="25:00" readonly />
+              </div>
+            </div>
+            <div class="controls">
+              <button class="btn start-btn">▶️</button>
+              <button class="btn pause-btn" style="display: none">⏸️</button>
+              <button class="btn stop-btn" style="display: none">⏹️</button>
+            </div>
+          </div>
+
+          <div class="idle">
+            <h2>♨️</h2>
+            <div class="linear-progress">
+              <div class="progress"></div>
+            </div>
+            <div class="time-display">
+              <input type="text" class="time-input" value="5:00" readonly />
+            </div>
+            <div class="controls">
+              <button class="btn start-btn">▶️</button>
+              <button class="btn pause-btn" style="display: none">⏸️</button>
+              <button class="btn stop-btn" style="display: none">⏹️</button>
+            </div>
+          </div>
+        </div>
+      </div>
+    </div>
+
+    <script>
+      // 数据管理
+      const dataManager = {
+        // 初始化数据
+        init() {
+          const data = localStorage.getItem("timerData");
+          if (data) {
+            return JSON.parse(data);
+          } else {
+            return {
+              totalStudyTime: 0,
+              pomodoroTime: 1500, // 25 分钟
+              idleTime: 300, // 5 分钟
+            };
+          }
+        },
+
+        // 保存数据
+        save(data) {
+          localStorage.setItem("timerData", JSON.stringify(data));
+        },
+
+        // 格式化时间(秒转 HH:MM)
+        formatTime(seconds) {
+          const hours = Math.floor(seconds / 3600);
+          const minutes = Math.floor((seconds % 3600) / 60);
+          return `${hours}:${minutes.toString().padStart(2, "0")}`;
+        },
+
+        // 格式化倒计时(秒转 MM:SS)
+        formatCountdown(seconds) {
+          const minutes = Math.floor(seconds / 60);
+          const secs = seconds % 60;
+          return `${minutes}:${secs.toString().padStart(2, "0")}`;
+        },
+      };
+
+      // 番茄钟控制器
+      class PomodoroTimer {
+        constructor(element) {
+          this.element = element;
+          this.timeInput = element.querySelector(".time-input");
+          this.startBtn = element.querySelector(".start-btn");
+          this.pauseBtn = element.querySelector(".pause-btn");
+          this.stopBtn = element.querySelector(".stop-btn");
+          this.progressCircle = element.querySelector(
+            ".circular-progress .progress"
+          );
+          this.circumference = 2 * Math.PI * 90; // 圆的周长
+
+          this.data = dataManager.init();
+          this.totalTime = this.data.pomodoroTime;
+          this.remainingTime = this.totalTime;
+          this.isRunning = false;
+          this.interval = null;
+
+          this.init();
+        }
+
+        init() {
+          this.timeInput.value = dataManager.formatCountdown(
+            this.remainingTime
+          );
+          this.updateProgress();
+
+          // 事件监听
+          this.startBtn.addEventListener("click", () => this.start());
+          this.pauseBtn.addEventListener("click", () => this.pause());
+          this.stopBtn.addEventListener("click", () => this.stop());
+
+          // 允许编辑时间
+          this.timeInput.addEventListener("blur", () => {
+            if (!this.isRunning) {
+              const timeParts = this.timeInput.value.split(":");
+              if (timeParts.length === 2) {
+                const minutes = parseInt(timeParts[0], 10);
+                const seconds = parseInt(timeParts[1], 10);
+
+                // 验证输入
+                if (
+                  !isNaN(minutes) &&
+                  !isNaN(seconds) &&
+                  minutes >= 0 &&
+                  minutes <= 99 &&
+                  seconds >= 0 &&
+                  seconds <= 59
+                ) {
+                  this.totalTime = minutes * 60 + seconds;
+                  this.remainingTime = this.totalTime;
+                  this.data.pomodoroTime = this.totalTime;
+                  dataManager.save(this.data);
+                  this.updateProgress();
+                }
+              }
+              // 重置为有效格式
+              this.timeInput.value = dataManager.formatCountdown(
+                this.remainingTime
+              );
+            }
+          });
+
+          // 限制输入格式
+          this.timeInput.addEventListener("input", (e) => {
+            let value = e.target.value;
+            // 只允许数字和冒号
+            value = value.replace(/[^0-9:]/g, "");
+
+            // 自动格式化
+            if (value.length > 2 && value.indexOf(":") === -1) {
+              value = value.slice(0, 2) + ":" + value.slice(2);
+            }
+
+            // 限制长度
+            if (value.length > 5) {
+              value = value.slice(0, 5);
+            }
+
+            e.target.value = value;
+          });
+        }
+
+        start() {
+          if (!this.isRunning) {
+            this.isRunning = true;
+            this.timeInput.readOnly = true;
+            this.startBtn.style.display = "none";
+            this.pauseBtn.style.display = "inline-block";
+            this.stopBtn.style.display = "inline-block";
+
+            this.interval = setInterval(() => {
+              this.remainingTime--;
+              this.timeInput.value = dataManager.formatCountdown(
+                this.remainingTime
+              );
+              this.updateProgress();
+
+              if (this.remainingTime <= 0) {
+                this.complete();
+              }
+            }, 1000);
+          }
+        }
+
+        pause() {
+          if (this.isRunning) {
+            this.isRunning = false;
+            clearInterval(this.interval);
+            this.startBtn.style.display = "inline-block";
+            this.pauseBtn.style.display = "none";
+          }
+        }
+
+        stop() {
+          this.isRunning = false;
+          clearInterval(this.interval);
+
+          // 将已进行的时间加入总学习时长
+          const elapsed = this.totalTime - this.remainingTime;
+          this.data.totalStudyTime += elapsed;
+          dataManager.save(this.data);
+          studyTimeDisplay.textContent = dataManager.formatTime(
+            this.data.totalStudyTime
+          );
+
+          // 重置计时器
+          this.remainingTime = this.totalTime;
+          this.timeInput.value = dataManager.formatCountdown(
+            this.remainingTime
+          );
+          this.timeInput.readOnly = false;
+          this.updateProgress();
+
+          this.startBtn.style.display = "inline-block";
+          this.pauseBtn.style.display = "none";
+          this.stopBtn.style.display = "none";
+        }
+
+        complete() {
+          this.isRunning = false;
+          clearInterval(this.interval);
+
+          // 将全部时间加入总学习时长
+          this.data.totalStudyTime += this.totalTime;
+          dataManager.save(this.data);
+          studyTimeDisplay.textContent = dataManager.formatTime(
+            this.data.totalStudyTime
+          );
+
+          // 重置计时器
+          this.remainingTime = this.totalTime;
+          this.timeInput.value = dataManager.formatCountdown(
+            this.remainingTime
+          );
+          this.timeInput.readOnly = false;
+          this.updateProgress();
+
+          this.startBtn.style.display = "inline-block";
+          this.pauseBtn.style.display = "none";
+          this.stopBtn.style.display = "none";
+
+          // 发送通知
+          this.sendNotification("番茄钟完成", "恭喜你完成了一个番茄钟!");
+        }
+
+        updateProgress() {
+          const progress =
+            (this.totalTime - this.remainingTime) / this.totalTime;
+          const offset = this.circumference - progress * this.circumference;
+          this.progressCircle.style.strokeDashoffset = offset;
+        }
+
+        sendNotification(title, message) {
+          if ("Notification" in window) {
+            if (Notification.permission === "granted") {
+              new Notification(title, { body: message });
+            } else if (Notification.permission !== "denied") {
+              Notification.requestPermission().then((permission) => {
+                if (permission === "granted") {
+                  new Notification(title, { body: message });
+                }
+              });
+            }
+          }
+
+          // 播放声音
+          const audio = new Audio(
+            "data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQoGAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwFJHfH8N2QQAoUXrTp66hVFApGn+DyvmwhBSuBzvLZiTYIG2m98OScTgwOUarm7blmFgU7k9n1unEiBC13yO/eizEIHWq+8+OWT"
+          );
+          audio.play();
+        }
+      }
+
+      // 空闲钟控制器
+      class IdleTimer {
+        constructor(element) {
+          this.element = element;
+          this.timeInput = element.querySelector(".time-input");
+          this.startBtn = element.querySelector(".start-btn");
+          this.pauseBtn = element.querySelector(".pause-btn");
+          this.stopBtn = element.querySelector(".stop-btn");
+          this.progressBar = element.querySelector(
+            ".linear-progress .progress"
+          );
+
+          this.data = dataManager.init();
+          this.totalTime = this.data.idleTime;
+          this.remainingTime = this.totalTime;
+          this.isRunning = false;
+          this.interval = null;
+
+          this.init();
+        }
+
+        init() {
+          this.timeInput.value = dataManager.formatCountdown(
+            this.remainingTime
+          );
+          this.updateProgress();
+
+          // 事件监听
+          this.startBtn.addEventListener("click", () => this.start());
+          this.pauseBtn.addEventListener("click", () => this.pause());
+          this.stopBtn.addEventListener("click", () => this.stop());
+
+          // 允许编辑时间
+          this.timeInput.addEventListener("blur", () => {
+            if (!this.isRunning) {
+              const timeParts = this.timeInput.value.split(":");
+              if (timeParts.length === 2) {
+                const minutes = parseInt(timeParts[0], 10);
+                const seconds = parseInt(timeParts[1], 10);
+
+                // 验证输入
+                if (
+                  !isNaN(minutes) &&
+                  !isNaN(seconds) &&
+                  minutes >= 0 &&
+                  minutes <= 99 &&
+                  seconds >= 0 &&
+                  seconds <= 59
+                ) {
+                  this.totalTime = minutes * 60 + seconds;
+                  this.remainingTime = this.totalTime;
+                  this.data.idleTime = this.totalTime;
+                  dataManager.save(this.data);
+                  this.updateProgress();
+                }
+              }
+              // 重置为有效格式
+              this.timeInput.value = dataManager.formatCountdown(
+                this.remainingTime
+              );
+            }
+          });
+
+          // 限制输入格式
+          this.timeInput.addEventListener("input", (e) => {
+            let value = e.target.value;
+            // 只允许数字和冒号
+            value = value.replace(/[^0-9:]/g, "");
+
+            // 自动格式化
+            if (value.length > 2 && value.indexOf(":") === -1) {
+              value = value.slice(0, 2) + ":" + value.slice(2);
+            }
+
+            // 限制长度
+            if (value.length > 5) {
+              value = value.slice(0, 5);
+            }
+
+            e.target.value = value;
+          });
+        }
+
+        start() {
+          if (!this.isRunning) {
+            this.isRunning = true;
+            this.timeInput.readOnly = true;
+            this.startBtn.style.display = "none";
+            this.pauseBtn.style.display = "inline-block";
+            this.stopBtn.style.display = "inline-block";
+
+            this.interval = setInterval(() => {
+              this.remainingTime--;
+              this.timeInput.value = dataManager.formatCountdown(
+                this.remainingTime
+              );
+              this.updateProgress();
+
+              if (this.remainingTime <= 0) {
+                this.complete();
+              }
+            }, 1000);
+          }
+        }
+
+        pause() {
+          if (this.isRunning) {
+            this.isRunning = false;
+            clearInterval(this.interval);
+            this.startBtn.style.display = "inline-block";
+            this.pauseBtn.style.display = "none";
+          }
+        }
+
+        stop() {
+          this.isRunning = false;
+          clearInterval(this.interval);
+
+          // 重置计时器
+          this.remainingTime = this.totalTime;
+          this.timeInput.value = dataManager.formatCountdown(
+            this.remainingTime
+          );
+          this.timeInput.readOnly = false;
+          this.updateProgress();
+
+          this.startBtn.style.display = "inline-block";
+          this.pauseBtn.style.display = "none";
+          this.stopBtn.style.display = "none";
+        }
+
+        complete() {
+          this.isRunning = false;
+          clearInterval(this.interval);
+
+          // 重置计时器
+          this.remainingTime = this.totalTime;
+          this.timeInput.value = dataManager.formatCountdown(
+            this.remainingTime
+          );
+          this.timeInput.readOnly = false;
+          this.updateProgress();
+
+          this.startBtn.style.display = "inline-block";
+          this.pauseBtn.style.display = "none";
+          this.stopBtn.style.display = "none";
+
+          // 发送通知
+          this.sendNotification("空闲时间结束", "休息时间结束了!");
+        }
+
+        updateProgress() {
+          const progress =
+            (this.totalTime - this.remainingTime) / this.totalTime;
+          this.progressBar.style.width = `${progress * 100}%`;
+        }
+
+        sendNotification(title, message) {
+          if ("Notification" in window) {
+            if (Notification.permission === "granted") {
+              new Notification(title, { body: message });
+            } else if (Notification.permission !== "denied") {
+              Notification.requestPermission().then((permission) => {
+                if (permission === "granted") {
+                  new Notification(title, { body: message });
+                }
+              });
+            }
+          }
+
+          // 播放声音
+          const audio = new Audio(
+            "data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQoGAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwFJHfH8N2QQAoUXrTp66hVFApGn+DyvmwhBSuBzvLZiTYIG2m98OScTgwOUarm7blmFgU7k9n1unEiBC13yO/eizEIHWq+8+OWT"
+          );
+          audio.play();
+        }
+      }
+
+      // 初始化应用
+      const data = dataManager.init();
+      const studyTimeDisplay = document.querySelector(".study-time-display");
+      studyTimeDisplay.textContent = dataManager.formatTime(
+        data.totalStudyTime
+      );
+
+      // 初始化番茄钟
+      const pomodoroElement = document.querySelector(".pomodoro");
+      const pomodoroTimer = new PomodoroTimer(pomodoroElement);
+
+      // 初始化空闲钟
+      const idleElement = document.querySelector(".idle");
+      const idleTimer = new IdleTimer(idleElement);
+
+      // 请求通知权限
+      if ("Notification" in window && Notification.permission === "default") {
+        Notification.requestPermission();
+      }
+
+      // 处理页面可见性变化
+      let lastVisibleTime = Date.now();
+
+      document.addEventListener("visibilitychange", () => {
+        if (document.visibilityState === "visible") {
+          // 页面变为可见时,计算经过的时间并更新计时器
+          const now = Date.now();
+          const elapsedSeconds = Math.floor((now - lastVisibleTime) / 1000);
+
+          if (pomodoroTimer.isRunning) {
+            pomodoroTimer.remainingTime = Math.max(
+              0,
+              pomodoroTimer.remainingTime - elapsedSeconds
+            );
+            pomodoroTimer.timeInput.value = dataManager.formatCountdown(
+              pomodoroTimer.remainingTime
+            );
+            pomodoroTimer.updateProgress();
+
+            if (pomodoroTimer.remainingTime <= 0) {
+              pomodoroTimer.complete();
+            }
+          }
+
+          if (idleTimer.isRunning) {
+            idleTimer.remainingTime = Math.max(
+              0,
+              idleTimer.remainingTime - elapsedSeconds
+            );
+            idleTimer.timeInput.value = dataManager.formatCountdown(
+              idleTimer.remainingTime
+            );
+            idleTimer.updateProgress();
+
+            if (idleTimer.remainingTime <= 0) {
+              idleTimer.complete();
+            }
+          }
+        }
+
+        lastVisibleTime = Date.now();
+      });
+
+      // 页面关闭前提醒
+      window.addEventListener("beforeunload", (e) => {
+        if (pomodoroTimer.isRunning || idleTimer.isRunning) {
+          e.preventDefault();
+          e.returnValue = "您有正在运行的计时器,确定要离开吗?";
+          return e.returnValue;
+        }
+      });
+    </script>
+  </body>
+</html>