Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 75 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,75 @@
# RandomWord - 英语单词动态壁纸

[![AGPL-3.0 License](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](LICENSE)
[![Lively Wallpaper](https://img.shields.io/badge/Lively-Compatible-green.svg)](https://github.com/rocksdanister/lively)
[![dict API](https://img.shields.io/badge/dict-API-blue.svg)](https://github.com/kajweb/dict)

在精美壁纸上学习英语单词的动态壁纸应用,支持 Lively Wallpaper。

[在线预览](https://majiangla.github.io/RandomWord/)

## ✨ 功能特色

- 📚 内置高中/四级词库,支持自定义 CSV 导入
- 🎨 智能主题色提取,从壁纸自动配色
- 📍 可调卡片位置(横纵百分比)
- 🔄 自动切换单词和壁纸
- 🌄 必应每日壁纸(国际版/中国版双源)

## 🚀 快速使用

**本地运行:**
```bash
git clone https://github.com/majiangla/RandomWord.git
cd RandomWord
python -m http.server 8000
```
访问 `http://localhost:8000`

**Lively 壁纸:**
1. [下载 Release](https://github.com/majiangla/RandomWord/releases/tag/pnblish)
2. 拖入 Lively Wallpaper 窗口

## ⚙️ 基本设置

1. **词书选择**:高中/四级或自定义 CSV
2. **位置调整**:水平/垂直滑块 (0-100%)
3. **显示控制**:单词/释义开关,动画开关
4. **自动模式**:设置切换间隔时间

## 📄 词书格式

```csv
单词,释义
apple,苹果
book,书
computer,计算机
```

## 🤝 致谢

- [bing-wallpaper](https://github.com/niumoo/bing-wallpaper) - 壁纸数据
- [dict](https://github.com/kajweb/dict) - 词典数据

## 📄 许可证

AGPL-3.0 © [MaJiang](https://github.com/majiangla)

---

⭐ **欢迎 Star 和 Fork!**
# RandomWord - 英语单词动态壁纸

[![AGPL-3.0 License](https://img.shields.io/badge/License-AGPL--3.0-blue.svg)](LICENSE)
[![Lively Wallpaper](https://img.shields.io/badge/Lively-Compatible-green.svg)](https://github.com/rocksdanister/lively)
[![dict API](https://img.shields.io/badge/dict-API-blue.svg)](https://github.com/kajweb/dict)

在精美壁纸上学习英语单词的动态壁纸应用,支持 Lively Wallpaper。

[在线预览](https://majiangla.github.io/RandomWord/)

## ✨ 功能特色

- 📚 内置高中/四级词库,支持自定义 CSV 导入
- 🎨 智能主题色提取,从壁纸自动配色
- 📍 可调卡片位置(横纵百分比)
- 🔄 自动切换单词和壁纸
- 🌄 必应每日壁纸(中国版新 API + 国际版 GitHub 数据)

## 🚀 快速使用

**本地运行:**
```bash
git clone https://github.com/majiangla/RandomWord.git
cd RandomWord
python -m http.server 8000
```
访问 `http://localhost:8000`

**Lively 壁纸:**
1. [下载 Release](https://github.com/majiangla/RandomWord/releases/tag/pnblish)
2. 拖入 Lively Wallpaper 窗口

## ⚙️ 基本设置

1. **词书选择**:高中/四级或自定义 CSV
2. **位置调整**:水平/垂直滑块 (0-100%)
3. **显示控制**:单词/释义开关,动画开关
4. **自动模式**:设置切换间隔时间


## 🖼️ 中国版 Bing 壁纸开放 API

本站中国版壁纸使用以下可直接引用的图片 API:

- 今日壁纸(长期服务):`https://bing.img.run/uhd.php`
- 随机历史壁纸:`https://bing.img.run/rand_uhd.php`(收录范围:2020-09-01 至今)

可直接作为 `img` 链接使用:

```html
<img src="https://bing.img.run/uhd.php" alt="Bing每日壁纸UHD超高清原图" />
<img src="https://bing.img.run/rand_uhd.php" alt="随机获取Bing历史壁纸UHD超高清原图" />
```

## 📄 词书格式

```csv
单词,释义
apple,苹果
book,书
computer,计算机
```

## 🤝 致谢

- [bing-wallpaper](https://github.com/niumoo/bing-wallpaper) - 壁纸数据
- [dict](https://github.com/kajweb/dict) - 词典数据

## 📄 许可证

AGPL-3.0 © [MaJiang](https://github.com/majiangla)

---

⭐ **欢迎 Star 和 Fork!**
184 changes: 92 additions & 92 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
// 主应用程序
class VocabularyApp {
constructor() {
// 初始化模块
this.wordManager = new WordManager();
this.wallpaperManager = new WallpaperManager();
this.settingsManager = new SettingsManager(this.wordManager, this.wallpaperManager);
// 全局状态
this.isInitialized = false;
}
// 初始化应用程序
async init() {
if (this.isInitialized) return;
// 显示启动信息
this.showWelcomeMessage();
// 初始化UI
this.settingsManager.initUIElements();
// 尝试自动加载词书
const hasWords = await this.wordManager.tryAutoLoad();
// 显示随机单词
this.showRandomWord();
// 设置壁纸
this.wallpaperManager.setRandomBingBackground();
// 设置全局事件监听
this.setupGlobalEventListeners();
this.isInitialized = true;
Logger.log('应用程序初始化完成');
}
// 显示欢迎信息
showWelcomeMessage() {
console.log('====================================');
console.log('MaJiang - 英语单词随机展示系统');
console.log('作者: MaJiangla (Bilibili: 1431497051)');
console.log('功能说明:');
console.log(' • 点击页面任意位置切换单词');
console.log(' • 每 ' + this.settingsManager.settings.bgInterval + ' 个单词切换一次壁纸');
console.log(' • 支持导入CSV格式单词表');
console.log(' • 支持自动模式');
console.log(' • 支持词书选择');
console.log('====================================');
}
// 设置全局事件监听器
setupGlobalEventListeners() {
// 点击页面切换单词
document.body.addEventListener('click', (e) => {
if (!this.settingsManager.elements.settingsMenu.contains(e.target) &&
!this.settingsManager.elements.settingsBtn.contains(e.target)) {
this.showRandomWord();
}
});
}
// 显示随机单词
showRandomWord() {
const entry = this.wordManager.showRandom();
// 更新显示
this.settingsManager.updateDisplay(entry.word, entry.meaning);
// 记录日志
Logger.logWord(entry.word, entry.meaning ? entry.meaning.replace(/\n/g, ' ') : '(无释义)');
// 增加点击计数
this.settingsManager.incrementClickCount();
}
}
// 创建全局实例
let app;
// 将showRandomWord暴露为全局函数(提前定义,避免空闲检测时未定义)
window.showRandomWord = () => {
if (app && typeof app.showRandomWord === 'function') {
app.showRandomWord();
}
};
// 页面加载完成后初始化
window.onload = async function() {
app = new VocabularyApp();
await app.init();
// 主应用程序
class VocabularyApp {
constructor() {
// 初始化模块
this.wordManager = new WordManager();
this.wallpaperManager = new WallpaperManager();
this.settingsManager = new SettingsManager(this.wordManager, this.wallpaperManager);

// 全局状态
this.isInitialized = false;
}

// 初始化应用程序
async init() {
if (this.isInitialized) return;

// 显示启动信息
this.showWelcomeMessage();

// 初始化UI
this.settingsManager.initUIElements();

// 尝试自动加载词书
const hasWords = await this.wordManager.tryAutoLoad();

// 显示随机单词
this.showRandomWord();

// 设置壁纸(初始化固定为中国版必应今日壁纸)
this.wallpaperManager.setChineseDailyBackground();

// 设置全局事件监听
this.setupGlobalEventListeners();

this.isInitialized = true;
Logger.log('应用程序初始化完成');
}

// 显示欢迎信息
showWelcomeMessage() {
console.log('====================================');
console.log('MaJiang - 英语单词随机展示系统');
console.log('作者: MaJiangla (Bilibili: 1431497051)');
console.log('功能说明:');
console.log(' • 点击页面任意位置切换单词');
console.log(' • 每 ' + this.settingsManager.settings.bgInterval + ' 个单词切换一次壁纸');
console.log(' • 支持导入CSV格式单词表');
console.log(' • 支持自动模式');
console.log(' • 支持词书选择');
console.log('====================================');
}

// 设置全局事件监听器
setupGlobalEventListeners() {
// 点击页面切换单词
document.body.addEventListener('click', (e) => {
if (!this.settingsManager.elements.settingsMenu.contains(e.target) &&
!this.settingsManager.elements.settingsBtn.contains(e.target)) {
this.showRandomWord();
}
});
}

// 显示随机单词
showRandomWord() {
const entry = this.wordManager.showRandom();

// 更新显示
this.settingsManager.updateDisplay(entry.word, entry.meaning);

// 记录日志
Logger.logWord(entry.word, entry.meaning ? entry.meaning.replace(/\n/g, ' ') : '(无释义)');

// 增加点击计数
this.settingsManager.incrementClickCount();
}
}

// 创建全局实例
let app;

// 将showRandomWord暴露为全局函数(提前定义,避免空闲检测时未定义)
window.showRandomWord = () => {
if (app && typeof app.showRandomWord === 'function') {
app.showRandomWord();
}
};

// 页面加载完成后初始化
window.onload = async function() {
app = new VocabularyApp();
await app.init();
};
Loading