Spaces:
Sleeping
Sleeping
eithney commited on
Commit ·
bc2665f
1
Parent(s): dc3bb4a
Add static files with LFS support for fonts
Browse filesFiles changed (22)
- .gitattributes+2
- download_resources.py+4-4
- index.html+4-6
- static/css/all.min.cssAdded
- static/css/inter.cssAdded+35
- static/css/style.cssAdded+910
- static/fonts/fa-brands-400.ttfAdded+3
- static/fonts/fa-brands-400.woff2Added+3
- static/fonts/fa-regular-400.ttfAdded+3
- static/fonts/fa-regular-400.woff2Added+3
- static/fonts/fa-solid-900.ttfAdded+3
- static/fonts/fa-solid-900.woff2Added+3
- static/fonts/fa-v4compatibility.ttfAdded+3
- static/fonts/fa-v4compatibility.woff2Added+3
- static/fonts/inter/Inter-300.ttfAdded+3
- static/fonts/inter/Inter-400.ttfAdded+3
- static/fonts/inter/Inter-500.ttfAdded+3
- static/fonts/inter/Inter-600.ttfAdded+3
- static/fonts/inter/Inter-700.ttfAdded+3
- static/fonts/inter/Inter-Light.woff2Added+3
- static/fonts/inter/inter.cssAdded+35
- static/js/script.jsAdded+952
36 unmodified lines37383936 unmodified lines*.mp3 filter=lfs diff=lfs merge=lfs -text*.jpg filter=lfs diff=lfs merge=lfs -text*.woff filter=lfs diff=lfs merge=lfs -text36 unmodified lines373839404136 unmodified lines*.mp3 filter=lfs diff=lfs merge=lfs -text*.jpg filter=lfs diff=lfs merge=lfs -text*.woff filter=lfs diff=lfs merge=lfs -text*.ttf filter=lfs diff=lfs merge=lfs -text*.woff2 filter=lfs diff=lfs merge=lfs -text
95 unmodified lines9697989910010110210310410510610710810911011195 unmodified lines# 提取图片URLif 'originImgUrl' in page:urls['images'].add(page['originImgUrl'])if 'encryptImgUrl' in page:urls['images'].add(page['encryptImgUrl'])# 提取音频URLif 'pieces' in page:for piece in page['pieces']:if 'originSoundUrl' in piece:urls['audios'].add(piece['originSoundUrl'])if 'encryptSoundUrl' in piece:urls['audios'].add(piece['encryptSoundUrl'])return urls95 unmodified lines9697989910010110210310410510610710810911011195 unmodified lines# 提取图片URLif 'originImgUrl' in page:urls['images'].add(page['originImgUrl'])# if 'encryptImgUrl' in page:# urls['images'].add(page['encryptImgUrl'])# 提取音频URLif 'pieces' in page:for piece in page['pieces']:if 'originSoundUrl' in piece:urls['audios'].add(piece['originSoundUrl'])# if 'encryptSoundUrl' in piece:# urls['audios'].add(piece['encryptSoundUrl'])return urls
3 unmodified lines4567891011121314169 unmodified lines1841851861871881893 unmodified lines<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>交互式英语学习应用</title><link rel="stylesheet" href="style.css"><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"></head><body><div class="app-container">169 unmodified lines<div class="toast" id="toast"></div></div><script src="script.js"></script></body></html>3 unmodified lines456789101112169 unmodified lines1821831841851861873 unmodified lines<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>交互式英语学习应用</title><link rel="stylesheet" href="static/css/style.css"><link rel="stylesheet" href="static/css/inter.css"><link rel="stylesheet" href="static/css/all.min.css"></head><body><div class="app-container">169 unmodified lines<div class="toast" id="toast"></div></div><script src="static/js/script.js"></script></body></html>
1234567891011121314151617181920212223242526272829303132333435@font-face { font-family: 'Inter'; font-style: normal; font-weight: 300; font-display: swap; src: url(../fonts/inter/Inter-300.ttf) format('truetype');}@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/inter/Inter-400.ttf) format('truetype');}@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/inter/Inter-500.ttf) format('truetype');}@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url(../fonts/inter/Inter-600.ttf) format('truetype');}@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url(../fonts/inter/Inter-700.ttf) format('truetype');}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910/* 全局样式重置和基础设置 */* { margin: 0; padding: 0; box-sizing: border-box;}
:root { --primary-color: #2563eb; --primary-hover: #1d4ed8; --secondary-color: #64748b; --success-color: #059669; --warning-color: #d97706; --error-color: #dc2626; --bg-primary: #ffffff; --bg-secondary: #f8fafc; --bg-tertiary: #e2e8f0; --text-primary: #1e293b; --text-secondary: #475569; --text-muted: #64748b; --border-color: #e2e8f0; --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05); --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); --border-radius: 8px; --border-radius-lg: 12px; --border-radius-xl: 16px; --font-size-sm: 0.875rem; --font-size-base: 1rem; --font-size-lg: 1.125rem; --font-size-xl: 1.25rem; --font-size-2xl: 1.5rem; --z-index-dropdown: 1000; --z-index-overlay: 2000; --z-index-modal: 3000; --z-index-toast: 4000;}
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', '微软雅黑', Roboto, sans-serif; background-color: var(--bg-secondary); color: var(--text-primary); line-height: 1.6;}
.app-container { min-height: 100vh; display: flex; flex-direction: column;}
/* 顶部导航栏 */.header { background: var(--bg-primary); border-bottom: 1px solid var(--border-color); box-shadow: var(--shadow-sm); position: sticky; top: 0; z-index: var(--z-index-dropdown);}
.header-content { max-width: 1200px; margin: 0 auto; padding: 1rem 1.5rem; display: flex; justify-content: space-between; align-items: center;}
.app-title { font-size: var(--font-size-xl); font-weight: 600; color: var(--primary-color); display: flex; align-items: center; gap: 0.75rem;}
.app-title i { font-size: var(--font-size-2xl);}
.controls { display: flex; gap: 0.75rem;}
.control-btn { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--border-radius); color: var(--text-secondary); font-size: var(--font-size-sm); cursor: pointer; transition: all 0.2s ease;}
.control-btn:hover { background: var(--primary-color); color: white; border-color: var(--primary-color);}
.control-btn.active { background: var(--primary-color); color: white; border-color: var(--primary-color);}
/* 主要内容区域 */.main-content { flex: 1; max-width: 1200px; margin: 0 auto; width: 100%; padding: 1.5rem;}
/* 页面导航 */.page-navigation { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: 1.5rem; padding: 1rem; background: var(--bg-primary); border-radius: var(--border-radius-lg); box-shadow: var(--shadow-sm);}
.nav-btn { width: 2.5rem; height: 2.5rem; border: 1px solid var(--border-color); background: var(--bg-primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s ease; color: var(--text-secondary);}
.nav-btn:hover { background: var(--primary-color); color: white; border-color: var(--primary-color);}
.nav-btn:disabled { opacity: 0.5; cursor: not-allowed;}
.nav-btn:disabled:hover { background: var(--bg-primary); color: var(--text-secondary); border-color: var(--border-color);}
.page-info { font-size: var(--font-size-lg); font-weight: 500; color: var(--text-primary); min-width: 4rem; text-align: center;}
.progress-bar { flex: 1; max-width: 200px; height: 4px; background: var(--bg-tertiary); border-radius: 2px; overflow: hidden; margin-left: 1rem;}
.progress-fill { height: 100%; background: var(--primary-color); border-radius: 2px; transition: width 0.3s ease;}
/* 页面容器 */.page-container { background: var(--bg-primary); border-radius: var(--border-radius-xl); box-shadow: var(--shadow-lg); overflow: hidden; min-height: 500px; display: flex; align-items: center; justify-content: center;}
.loading { text-align: center; color: var(--text-muted);}
.loading i { font-size: 2rem; margin-bottom: 1rem; color: var(--primary-color);}
.page-content { width: 100%; height: 100%;}
.page-image-container { position: relative; width: 100%; height: 100%; min-height: 500px; display: flex; justify-content: center; align-items: center; overflow: hidden;}
.page-image { max-width: 100%; max-height: 80vh; height: auto; border-radius: var(--border-radius); box-shadow: var(--shadow-md); display: block;}
/* 文本覆盖层 */.text-overlays { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none;}
.text-piece { position: absolute; background: transparent; border: 1px solid transparent; border-radius: 4px; cursor: pointer; pointer-events: all; transition: all 0.3s ease; padding: 0;}
.text-piece:hover { background: rgba(37, 99, 235, 0.08); border-color: rgba(37, 99, 235, 0.8); border-width: 2px; box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.2);}
.text-piece.active { background: rgba(37, 99, 235, 0.12); border-color: var(--primary-color); border-width: 2px; box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4); animation: activeFlash 1s ease-in-out;}
.text-piece.playing { border-color: var(--success-color); box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.4); animation: playingPulse 2s ease-in-out infinite;}
/* 交互模式下显示所有区域的轮廓 */.show-interactive-areas .text-piece { background: rgba(37, 99, 235, 0.05); border-color: rgba(37, 99, 235, 0.3); border-width: 1px;}
.show-interactive-areas .text-piece:hover { background: rgba(37, 99, 235, 0.1); border-color: var(--primary-color); border-width: 2px;}
.piece-text { font-size: var(--font-size-sm); font-weight: 500; color: var(--text-primary); text-shadow: 0 1px 2px rgba(255, 255, 255, 1); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', '微软雅黑', sans-serif; opacity: 0; pointer-events: none; display: none;}
.piece-translation { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.125rem; text-shadow: 0 1px 2px rgba(255, 255, 255, 1); font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', '微软雅黑', sans-serif; opacity: 0; pointer-events: none; display: none;}
/* 交互模式下显示文本(仅用于调试) */.show-interactive-areas .piece-text { opacity: 0.6; display: block; background: rgba(255, 255, 255, 0.9); padding: 0.125rem 0.25rem; border-radius: 2px; font-size: 0.7rem;}
.show-interactive-areas .piece-translation { opacity: 0.5; display: block; background: rgba(255, 255, 255, 0.8); padding: 0.125rem 0.25rem; border-radius: 2px; font-size: 0.6rem;}
/* 底部控制面板 */.bottom-panel { margin-top: 1.5rem;}
.audio-player { background: var(--bg-primary); border-radius: var(--border-radius-lg); padding: 1rem; box-shadow: var(--shadow-md);}
.audio-info { display: flex; flex-direction: column; gap: 1rem;}
.audio-text { font-size: var(--font-size-lg); font-weight: 500; color: var(--text-primary); text-align: center; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', '微软雅黑', sans-serif;}
.audio-controls { display: flex; align-items: center; gap: 1rem;}
.audio-btn { width: 2.5rem; height: 2.5rem; border: none; background: var(--primary-color); color: white; border-radius: 50%; cursor: pointer; transition: all 0.2s ease; display: flex; align-items: center; justify-content: center;}
.audio-btn:hover { background: var(--primary-hover); transform: scale(1.05);}
.audio-progress { flex: 1; display: flex; flex-direction: column; gap: 0.5rem;}
.audio-timeline { height: 4px; background: var(--bg-tertiary); border-radius: 2px; cursor: pointer; position: relative;}
.audio-progress-bar { height: 100%; background: var(--primary-color); border-radius: 2px; transition: width 0.1s ease;}
.audio-time { display: flex; justify-content: space-between; font-size: var(--font-size-sm); color: var(--text-muted);}
/* 搜索面板 */.search-panel { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: var(--z-index-modal); display: flex; align-items: center; justify-content: center; padding: 1rem;}
.search-content { background: var(--bg-primary); border-radius: var(--border-radius-xl); box-shadow: var(--shadow-lg); width: 100%; max-width: 600px; max-height: 80vh; overflow: hidden;}
.search-header { padding: 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center;}
.search-body { padding: 1.5rem; max-height: 60vh; overflow-y: auto;}
.search-input-container { display: flex; gap: 0.5rem; margin-bottom: 1.5rem;}
.search-input-container input { flex: 1; padding: 0.75rem 1rem; border: 1px solid var(--border-color); border-radius: var(--border-radius); font-size: var(--font-size-base); outline: none; transition: border-color 0.2s ease;}
.search-input-container input:focus { border-color: var(--primary-color);}
.search-btn { padding: 0.75rem 1rem; background: var(--primary-color); color: white; border: none; border-radius: var(--border-radius); cursor: pointer; transition: background-color 0.2s ease;}
.search-btn:hover { background: var(--primary-hover);}
.search-results { min-height: 200px;}
.search-empty { text-align: center; color: var(--text-muted); padding: 2rem; font-style: italic;}
.search-result-item { padding: 1rem; border: 1px solid var(--border-color); border-radius: var(--border-radius); margin-bottom: 0.75rem; cursor: pointer; transition: all 0.2s ease;}
.search-result-item:hover { border-color: var(--primary-color); background: var(--bg-secondary);}
.search-result-page { font-size: var(--font-size-sm); color: var(--text-muted); margin-bottom: 0.5rem;}
.search-result-text { font-weight: 500; margin-bottom: 0.25rem; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', '微软雅黑', sans-serif;}
.search-result-translation { color: var(--text-secondary); font-size: var(--font-size-sm); font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', '微软雅黑', sans-serif;}
.search-highlight { background: yellow; padding: 0.125rem 0.25rem; border-radius: 2px;}
/* 书签面板 */.bookmark-panel { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: var(--z-index-modal); display: flex; align-items: center; justify-content: center; padding: 1rem;}
.bookmark-content { background: var(--bg-primary); border-radius: var(--border-radius-xl); box-shadow: var(--shadow-lg); width: 100%; max-width: 500px; max-height: 80vh; overflow: hidden;}
.bookmark-header { padding: 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center;}
.bookmark-body { padding: 1.5rem; max-height: 60vh; overflow-y: auto;}
.bookmark-empty { text-align: center; color: var(--text-muted); padding: 2rem; font-style: italic;}
.bookmark-item { display: flex; justify-content: space-between; align-items: center; padding: 1rem; border: 1px solid var(--border-color); border-radius: var(--border-radius); margin-bottom: 0.75rem; cursor: pointer; transition: all 0.2s ease;}
.bookmark-item:hover { border-color: var(--primary-color); background: var(--bg-secondary);}
.bookmark-info { flex: 1;}
.bookmark-page { font-weight: 500; color: var(--text-primary); margin-bottom: 0.25rem;}
.bookmark-time { font-size: var(--font-size-sm); color: var(--text-muted);}
.bookmark-actions { display: flex; gap: 0.5rem;}
.bookmark-delete { width: 1.5rem; height: 1.5rem; border: none; background: var(--error-color); color: white; border-radius: 50%; cursor: pointer; transition: all 0.2s ease; display: flex; align-items: center; justify-content: center; font-size: 0.75rem;}
.bookmark-delete:hover { transform: scale(1.1);}
/* 设置面板 */.settings-panel { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: var(--z-index-modal); display: flex; align-items: center; justify-content: center; padding: 1rem;}
.settings-content { background: var(--bg-primary); border-radius: var(--border-radius-xl); box-shadow: var(--shadow-lg); width: 100%; max-width: 400px; max-height: 80vh; overflow-y: auto;}
.settings-header { padding: 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center;}
.settings-header h3 { font-size: var(--font-size-xl); font-weight: 600; color: var(--text-primary);}
.close-btn { width: 2rem; height: 2rem; border: none; background: none; color: var(--text-muted); cursor: pointer; border-radius: 4px; transition: all 0.2s ease;}
.close-btn:hover { background: var(--bg-secondary); color: var(--text-primary);}
.settings-body { padding: 1.5rem;}
.setting-item { display: flex; justify-content: space-between; align-items: center; padding: 1rem 0; border-bottom: 1px solid var(--border-color);}
.setting-item:last-child { border-bottom: none;}
.setting-item label { font-weight: 500; color: var(--text-primary);}
.setting-item input[type="checkbox"] { width: 1rem; height: 1rem; accent-color: var(--primary-color);}
.setting-item select { padding: 0.25rem 0.5rem; border: 1px solid var(--border-color); border-radius: var(--border-radius); background: var(--bg-primary); color: var(--text-primary);}
/* 消息提示 */.toast { position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%); background: var(--text-primary); color: white; padding: 0.75rem 1.5rem; border-radius: var(--border-radius); box-shadow: var(--shadow-lg); z-index: var(--z-index-toast); opacity: 0; visibility: hidden; transition: all 0.3s ease;}
.toast.show { opacity: 1; visibility: visible;}
.toast.success { background: var(--success-color);}
.toast.warning { background: var(--warning-color);}
.toast.error { background: var(--error-color);}
/* 响应式设计 */@media (max-width: 768px) { .header-content { padding: 1rem; flex-direction: column; gap: 1rem; } .controls { width: 100%; justify-content: center; } .main-content { padding: 1rem; } .page-navigation { flex-wrap: wrap; gap: 0.75rem; } .progress-bar { width: 100%; margin-left: 0; margin-top: 0.5rem; } .audio-controls { flex-direction: column; gap: 0.75rem; } .control-btn span { display: none; } .text-piece { min-width: 2rem; min-height: 1.5rem; } .piece-text { font-size: 0.75rem; } .piece-translation { font-size: 0.625rem; }}
@media (max-width: 480px) { .app-title { font-size: var(--font-size-lg); } .page-info { font-size: var(--font-size-base); } .settings-content { margin: 0.5rem; }}
/* 动画效果 */@keyframes fadeIn { from { opacity: 0; transform: translateY(1rem); } to { opacity: 1; transform: translateY(0); }}
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); }}
@keyframes activeFlash { 0% { box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4); } 50% { box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.6); } 100% { box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4); }}
@keyframes playingPulse { 0% { box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.4); } 50% { box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.6); } 100% { box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.4); }}
.page-content { animation: fadeIn 0.3s ease;}
.text-piece.playing { animation: pulse 1s ease-in-out infinite;}
/* 滚动条样式 */::-webkit-scrollbar { width: 6px; height: 6px;}
::-webkit-scrollbar-track { background: var(--bg-secondary);}
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px;}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted);}123version https://git-lfs.github.com/spec/v1oid sha256:20c4a58bc9d1d69e935d06f1528923646a715be5e218665655cade8f5f1b8c00size 187208123version https://git-lfs.github.com/spec/v1oid sha256:748332090c4b8e20f95d0ff59f0be20fa9c889359d3b36d4b886d73376054207size 108020123version https://git-lfs.github.com/spec/v1oid sha256:528d022dce6725f8a0811fd91d8e6513445c81ef33353a5c3234eab932551abfsize 63952123version https://git-lfs.github.com/spec/v1oid sha256:8e7e5ea1b15f62ab14dbd41768e8fbcd21cc859a4ea5da812457ee714299fb35size 24948123version https://git-lfs.github.com/spec/v1oid sha256:67a65763c7f80903d81603bbeb9049fc2bf28508479b83ed011fe24c71fa950asize 394628123version https://git-lfs.github.com/spec/v1oid sha256:7152a6933ee3d690ec2af3d09da9d701723d16aa3410a6d80f28ff8866f3b880size 150124123version https://git-lfs.github.com/spec/v1oid sha256:0515a423f828ce4e6accf92a2ea0b03d19d31cc86d9af0373291e1fd4db5f348size 10172123version https://git-lfs.github.com/spec/v1oid sha256:694a17c3d9d6c05f8aac63c544615552a4b220e9a4de863d87341a6bcfc1bc8dsize 4564123version https://git-lfs.github.com/spec/v1oid sha256:d0f4bc7faca468376e3db9b5e57afcdc2192134c9ac82a9511f32767b56853a4size 325748123version https://git-lfs.github.com/spec/v1oid sha256:1b08e7fc267a5c7e1d614100f604b83e7e8a0be241f0f288faa2b3ac93a683basize 324820123version https://git-lfs.github.com/spec/v1oid sha256:8c883f63b2c4157d997319f2c8bc6995ed4357ef371940d31ca159004a4aae63size 325304123version https://git-lfs.github.com/spec/v1oid sha256:e7a1aaf7eda9f2fad4131725fa556265ec75ca7b2d756260173a040363e8d4f7size 326048123version https://git-lfs.github.com/spec/v1oid sha256:b37284b5701b6b168dfc770aa1a4ac492106422fd3ba76bc7641e37434e8019csize 326468123version https://git-lfs.github.com/spec/v1oid sha256:2301bb030a2bcaa9c763cc4771bd717aac16709c29eaba00673fcbe7cdf99a59size 215641234567891011121314151617181920212223242526272829303132333435@font-face { font-family: 'Inter'; font-style: normal; font-weight: 300; font-display: swap; src: url(../fonts/inter/Inter-300.ttf) format('truetype');}@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/inter/Inter-400.ttf) format('truetype');}@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/inter/Inter-500.ttf) format('truetype');}@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url(../fonts/inter/Inter-600.ttf) format('truetype');}@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url(../fonts/inter/Inter-700.ttf) format('truetype');}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952/** * 交互式英语学习应用 - 主要逻辑 * 支持点读、翻译显示和音频播放功能 */
class InteractiveLearningApp { constructor() { this.bookData = null; this.currentPageIndex = 0; this.currentAudio = null; this.isPlaying = false; this.showTranslation = false; this.showInteractiveAreas = false; this.bookmarks = []; this.searchResults = []; this.debugMode = false; // 调试模式 this.useLocalResources = true; // 使用本地资源 this.settings = { autoTranslation: false, playbackSpeed: 1, autoPlayNext: false }; this.init(); }
async init() { try { await this.loadBookData(); this.setupEventListeners(); this.loadSettings(); this.loadBookmarks(); this.renderCurrentPage(); this.updateUI(); } catch (error) { console.error('应用初始化失败:', error); this.showToast('应用初始化失败,请刷新页面重试', 'error'); } }
/** * 从URL中提取文件名 */ extractFilenameFromUrl(url) { if (!url) return null; try { const urlObj = new URL(url); const pathname = urlObj.pathname; const filename = pathname.split('/').pop(); // 移除URL解码 return decodeURIComponent(filename); } catch (error) { console.error('URL解析失败:', error); return null; } }
/** * 将线上URL转换为本地资源路径 */ mapToLocalResource(url, type) { if (!this.useLocalResources || !url) { return url; } const filename = this.extractFilenameFromUrl(url); if (!filename) { return url; } if (type === 'image') { return `./assets/images/${filename}`; } else if (type === 'audio') { return `./assets/audios/${filename}`; } return url; }
async loadBookData() { try { const response = await fetch('./book_10242.json'); if (!response.ok) { throw new Error('数据文件加载失败'); } const jsonData = await response.json(); if (!jsonData.Data) { throw new Error('数据格式不正确'); } this.bookData = JSON.parse(jsonData.Data); console.log('书籍数据加载成功:', this.bookData.length, '页'); } catch (error) { console.error('数据加载失败:', error); throw error; } }
setupEventListeners() { // 页面导航 document.getElementById('prevBtn').addEventListener('click', () => this.previousPage()); document.getElementById('nextBtn').addEventListener('click', () => this.nextPage()); // 控制按钮 document.getElementById('translationToggle').addEventListener('click', () => this.toggleTranslation()); document.getElementById('interactiveToggle').addEventListener('click', () => this.toggleInteractiveAreas()); document.getElementById('playAllBtn').addEventListener('click', () => this.playAllPieces()); document.getElementById('bookmarkBtn').addEventListener('click', () => this.toggleBookmark()); document.getElementById('searchBtn').addEventListener('click', () => this.showSearch()); document.getElementById('settingsBtn').addEventListener('click', () => this.showSettings()); // 音频控制 document.getElementById('playPauseBtn').addEventListener('click', () => this.togglePlayPause()); document.getElementById('repeatBtn').addEventListener('click', () => this.repeatAudio()); document.getElementById('audioTimeline').addEventListener('click', (e) => this.seekAudio(e)); // 设置面板 document.getElementById('closeSettings').addEventListener('click', () => this.hideSettings()); // 搜索面板 document.getElementById('closeSearch').addEventListener('click', () => this.hideSearch()); document.getElementById('doSearch').addEventListener('click', () => this.performSearch()); document.getElementById('searchInput').addEventListener('keypress', (e) => { if (e.key === 'Enter') this.performSearch(); }); // 书签面板 document.getElementById('closeBookmark').addEventListener('click', () => this.hideBookmarks()); document.getElementById('autoTranslation').addEventListener('change', (e) => { this.settings.autoTranslation = e.target.checked; this.saveSettings(); }); document.getElementById('playbackSpeed').addEventListener('change', (e) => { this.settings.playbackSpeed = parseFloat(e.target.value); this.saveSettings(); if (this.currentAudio) { this.currentAudio.playbackRate = this.settings.playbackSpeed; } }); document.getElementById('autoPlayNext').addEventListener('change', (e) => { this.settings.autoPlayNext = e.target.checked; this.saveSettings(); }); // 键盘快捷键 document.addEventListener('keydown', (e) => this.handleKeyPress(e)); // 点击设置面板外部关闭 document.getElementById('settingsPanel').addEventListener('click', (e) => { if (e.target.id === 'settingsPanel') { this.hideSettings(); } }); // 音频事件监听 const audio = document.getElementById('audio'); audio.addEventListener('loadedmetadata', () => this.updateAudioUI()); audio.addEventListener('timeupdate', () => this.updateAudioProgress()); audio.addEventListener('ended', () => this.onAudioEnded()); audio.addEventListener('error', (e) => { console.error('音频播放失败:', e); this.showToast('音频播放失败', 'error'); }); }
renderCurrentPage() { if (!this.bookData || this.currentPageIndex >= this.bookData.length) { return; }
const page = this.bookData[this.currentPageIndex]; const pageContainer = document.getElementById('pageContent'); const loading = document.getElementById('loading'); // 显示加载状态 loading.style.display = 'block'; pageContainer.style.display = 'none'; // 加载页面图片 const pageImage = document.getElementById('pageImage'); pageImage.onload = () => { loading.style.display = 'none'; pageContainer.style.display = 'block'; this.renderTextPieces(page); }; pageImage.onerror = () => { // 如果原始图片加载失败,尝试加载加密图片 if (pageImage.src.includes('assets/images/') && page.encryptImgUrl) { const encryptImageUrl = this.mapToLocalResource(page.encryptImgUrl, 'image'); pageImage.src = encryptImageUrl; } else { loading.style.display = 'none'; this.showToast('页面图片加载失败', 'error'); } }; const imageUrl = this.mapToLocalResource(page.originImgUrl, 'image'); pageImage.src = imageUrl; pageImage.alt = `第${page.pageNumber}页`; }
renderTextPieces(page) { const textOverlays = document.getElementById('textOverlays'); const pageImage = document.getElementById('pageImage'); // 清空现有的文本片段 textOverlays.innerHTML = ''; // 等待图片完全加载后渲染文本片段 const renderPieces = () => { // 获取图片的实际位置和尺寸 const imageRect = pageImage.getBoundingClientRect(); const overlayRect = textOverlays.getBoundingClientRect(); // 计算图片相对于overlay容器的偏移 const offsetX = imageRect.left - overlayRect.left; const offsetY = imageRect.top - overlayRect.top; // 获取图片的实际显示尺寸 const imageWidth = imageRect.width; const imageHeight = imageRect.height; console.log('图片信息:', { imageWidth, imageHeight, offsetX, offsetY, debugMode: this.debugMode }); page.pieces.forEach((piece, index) => { const textPiece = document.createElement('div'); textPiece.className = 'text-piece'; textPiece.dataset.pieceIndex = index; // 在调试模式下添加特殊样式 if (this.debugMode) { textPiece.style.border = '2px solid red'; textPiece.style.backgroundColor = 'rgba(255, 0, 0, 0.2)'; } // 根据坐标信息设置位置和大小(coordinate是相对图片的比例坐标) const coord = piece.coordinate; const left = offsetX + (coord.x * imageWidth); const top = offsetY + (coord.y * imageHeight); const width = coord.width * imageWidth; const height = coord.height * imageHeight; textPiece.style.left = `${left}px`; textPiece.style.top = `${top}px`; textPiece.style.width = `${width}px`; textPiece.style.height = `${height}px`; if (this.debugMode) { console.log(`Piece ${index + 1} (${piece.original}):`, { coord, left, top, width, height }); } // 创建文本内容 const originalText = document.createElement('div'); originalText.className = 'piece-text'; originalText.textContent = piece.original; const translationText = document.createElement('div'); translationText.className = 'piece-translation'; translationText.textContent = piece.translation; textPiece.appendChild(originalText); textPiece.appendChild(translationText); // 点击事件 textPiece.addEventListener('click', () => this.playPiece(piece, textPiece)); textOverlays.appendChild(textPiece); }); // 根据设置显示翻译 if (this.showTranslation || this.settings.autoTranslation) { textOverlays.classList.add('show-translation'); } }; // 如果图片已经加载完成,直接渲染 if (pageImage.complete && pageImage.naturalHeight !== 0) { renderPieces(); } else { // 否则等待图片加载完成 pageImage.addEventListener('load', renderPieces, { once: true }); } // 监听窗口大小变化和图片加载事件 let resizeTimeout; const handleResize = () => { clearTimeout(resizeTimeout); resizeTimeout = setTimeout(() => { if (pageImage.complete && pageImage.naturalHeight !== 0) { console.log('窗口大小变化,重新计算坐标'); renderPieces(); } }, 100); }; // 移除之前的监听器(如果存在) if (pageImage.resizeObserver) { pageImage.resizeObserver.disconnect(); } // 创建新的监听器 pageImage.resizeObserver = new ResizeObserver(handleResize); pageImage.resizeObserver.observe(pageImage); // 同时监听窗口大小变化 window.addEventListener('resize', handleResize); }
async playPiece(piece, element) { try { // 移除其他片段的激活状态 document.querySelectorAll('.text-piece').forEach(el => { el.classList.remove('active', 'playing'); }); // 激活当前片段 element.classList.add('active'); // 显示音频播放器 const audioPlayer = document.getElementById('audioPlayer'); audioPlayer.style.display = 'block'; // 更新音频文本显示 const audioText = document.getElementById('audioText'); audioText.innerHTML = ` <div style="font-weight: 600; margin-bottom: 0.5rem;">${piece.original}</div> <div style="color: var(--text-secondary); font-size: 0.9rem;">${piece.translation}</div> `; // 加载并播放音频 const audio = document.getElementById('audio'); const audioUrl = piece.originSoundUrl || piece.encryptSoundUrl; if (!audioUrl) { this.showToast('该片段没有可用的音频', 'warning'); return; } // 停止当前播放的音频 if (this.currentAudio && !this.currentAudio.paused) { this.currentAudio.pause(); } const localAudioUrl = this.mapToLocalResource(audioUrl, 'audio'); audio.src = localAudioUrl; audio.playbackRate = this.settings.playbackSpeed; this.currentAudio = audio; // 播放音频 await audio.play(); this.isPlaying = true; element.classList.add('playing'); this.updatePlayButton(); } catch (error) { console.error('音频播放失败:', error); this.showToast('音频播放失败', 'error'); element.classList.remove('active', 'playing'); } }
async playAllPieces() { const page = this.bookData[this.currentPageIndex]; if (!page || !page.pieces.length) return; let currentPieceIndex = 0; const playNext = async () => { if (currentPieceIndex >= page.pieces.length) { this.showToast('整页播放完成', 'success'); return; } const piece = page.pieces[currentPieceIndex]; const element = document.querySelector(`[data-piece-index="${currentPieceIndex}"]`); if (element) { await this.playPiece(piece, element); // 等待当前音频播放完成 const audio = document.getElementById('audio'); audio.addEventListener('ended', () => { currentPieceIndex++; setTimeout(playNext, 500); // 稍微延迟播放下一个 }, { once: true }); } else { currentPieceIndex++; playNext(); } }; playNext(); }
togglePlayPause() { const audio = document.getElementById('audio'); if (!audio.src) return; if (this.isPlaying) { audio.pause(); this.isPlaying = false; } else { audio.play().then(() => { this.isPlaying = true; }).catch(error => { console.error('播放失败:', error); this.showToast('播放失败', 'error'); }); } this.updatePlayButton(); }
repeatAudio() { const audio = document.getElementById('audio'); if (audio.src) { audio.currentTime = 0; if (!this.isPlaying) { this.togglePlayPause(); } } }
seekAudio(event) { const audio = document.getElementById('audio'); if (!audio.src || !audio.duration) return; const timeline = document.getElementById('audioTimeline'); const rect = timeline.getBoundingClientRect(); const percentage = (event.clientX - rect.left) / rect.width; const newTime = percentage * audio.duration; audio.currentTime = newTime; }
updatePlayButton() { const playPauseBtn = document.getElementById('playPauseBtn'); const icon = playPauseBtn.querySelector('i'); if (this.isPlaying) { icon.className = 'fas fa-pause'; } else { icon.className = 'fas fa-play'; } }
updateAudioUI() { const audio = document.getElementById('audio'); const totalTime = document.getElementById('totalTime'); if (audio.duration) { totalTime.textContent = this.formatTime(audio.duration); } }
updateAudioProgress() { const audio = document.getElementById('audio'); const progressBar = document.getElementById('audioProgressBar'); const currentTime = document.getElementById('currentTime'); if (audio.duration) { const percentage = (audio.currentTime / audio.duration) * 100; progressBar.style.width = `${percentage}%`; currentTime.textContent = this.formatTime(audio.currentTime); } }
onAudioEnded() { this.isPlaying = false; this.updatePlayButton(); // 移除播放状态 document.querySelectorAll('.text-piece').forEach(el => { el.classList.remove('playing'); }); // 如果启用自动播放下一个 if (this.settings.autoPlayNext) { // 这里可以实现自动播放下一个片段的逻辑 } }
toggleTranslation() { this.showTranslation = !this.showTranslation; const textOverlays = document.getElementById('textOverlays'); const translationBtn = document.getElementById('translationToggle'); if (this.showTranslation) { textOverlays.classList.add('show-translation'); translationBtn.classList.add('active'); } else { textOverlays.classList.remove('show-translation'); translationBtn.classList.remove('active'); } }
toggleInteractiveAreas() { this.showInteractiveAreas = !this.showInteractiveAreas; const textOverlays = document.getElementById('textOverlays'); const interactiveBtn = document.getElementById('interactiveToggle'); if (this.showInteractiveAreas) { textOverlays.classList.add('show-interactive-areas'); interactiveBtn.classList.add('active'); interactiveBtn.querySelector('i').className = 'fas fa-eye-slash'; interactiveBtn.title = '隐藏交互区域'; } else { textOverlays.classList.remove('show-interactive-areas'); interactiveBtn.classList.remove('active'); interactiveBtn.querySelector('i').className = 'fas fa-eye'; interactiveBtn.title = '显示交互区域'; } }
previousPage() { if (this.currentPageIndex > 0) { this.currentPageIndex--; this.renderCurrentPage(); this.updateUI(); this.stopCurrentAudio(); } }
nextPage() { if (this.currentPageIndex < this.bookData.length - 1) { this.currentPageIndex++; this.renderCurrentPage(); this.updateUI(); this.stopCurrentAudio(); } }
stopCurrentAudio() { if (this.currentAudio && !this.currentAudio.paused) { this.currentAudio.pause(); this.isPlaying = false; this.updatePlayButton(); } // 隐藏音频播放器 document.getElementById('audioPlayer').style.display = 'none'; // 移除所有激活状态 document.querySelectorAll('.text-piece').forEach(el => { el.classList.remove('active', 'playing'); }); }
updateUI() { // 更新页面信息 document.getElementById('currentPage').textContent = this.currentPageIndex + 1; document.getElementById('totalPages').textContent = this.bookData.length; // 更新进度条 const progress = ((this.currentPageIndex + 1) / this.bookData.length) * 100; document.getElementById('progressFill').style.width = `${progress}%`; // 更新导航按钮状态 document.getElementById('prevBtn').disabled = this.currentPageIndex === 0; document.getElementById('nextBtn').disabled = this.currentPageIndex === this.bookData.length - 1; // 更新书签按钮状态 this.updateBookmarkButton(); }
showSettings() { document.getElementById('settingsPanel').style.display = 'flex'; // 同步当前设置到UI document.getElementById('autoTranslation').checked = this.settings.autoTranslation; document.getElementById('playbackSpeed').value = this.settings.playbackSpeed; document.getElementById('autoPlayNext').checked = this.settings.autoPlayNext; }
hideSettings() { document.getElementById('settingsPanel').style.display = 'none'; }
loadSettings() { const saved = localStorage.getItem('learningAppSettings'); if (saved) { try { this.settings = { ...this.settings, ...JSON.parse(saved) }; } catch (error) { console.error('设置加载失败:', error); } } }
saveSettings() { localStorage.setItem('learningAppSettings', JSON.stringify(this.settings)); }
handleKeyPress(event) { // 如果设置面板打开,只处理 Escape 键 if (document.getElementById('settingsPanel').style.display === 'flex') { if (event.key === 'Escape') { this.hideSettings(); } return; } switch (event.key) { case 'ArrowLeft': event.preventDefault(); this.previousPage(); break; case 'ArrowRight': event.preventDefault(); this.nextPage(); break; case ' ': event.preventDefault(); this.togglePlayPause(); break; case 't': case 'T': event.preventDefault(); this.toggleTranslation(); break; case 'i': case 'I': event.preventDefault(); this.toggleInteractiveAreas(); break; case 'r': case 'R': event.preventDefault(); this.repeatAudio(); break; case 'p': case 'P': event.preventDefault(); this.playAllPieces(); break; case 'b': case 'B': event.preventDefault(); this.toggleBookmark(); break; case 'f': case 'F': event.preventDefault(); this.showSearch(); break; case 'd': case 'D': if (event.ctrlKey) { event.preventDefault(); this.toggleDebugMode(); } break; } }
showToast(message, type = 'info') { const toast = document.getElementById('toast'); toast.textContent = message; toast.className = `toast ${type} show`; setTimeout(() => { toast.classList.remove('show'); }, 3000); }
formatTime(seconds) { const mins = Math.floor(seconds / 60); const secs = Math.floor(seconds % 60); return `${mins}:${secs.toString().padStart(2, '0')}`; }
// 搜索功能 showSearch() { document.getElementById('searchPanel').style.display = 'flex'; document.getElementById('searchInput').focus(); }
hideSearch() { document.getElementById('searchPanel').style.display = 'none'; document.getElementById('searchInput').value = ''; this.clearSearchResults(); }
performSearch() { const query = document.getElementById('searchInput').value.trim(); if (!query) { this.showToast('请输入搜索关键词', 'warning'); return; }
const results = []; const regex = new RegExp(query, 'gi');
this.bookData.forEach((page, pageIndex) => { page.pieces.forEach((piece, pieceIndex) => { if (regex.test(piece.original) || regex.test(piece.translation)) { results.push({ pageIndex, pieceIndex, page: page.pageNumber, original: piece.original, translation: piece.translation, piece }); } }); });
this.searchResults = results; this.displaySearchResults(query); }
displaySearchResults(query) { const resultsContainer = document.getElementById('searchResults'); if (this.searchResults.length === 0) { resultsContainer.innerHTML = '<div class="search-empty">未找到匹配的内容</div>'; return; }
const regex = new RegExp(`(${query})`, 'gi'); let html = '';
this.searchResults.forEach((result, index) => { const highlightedOriginal = result.original.replace(regex, '<span class="search-highlight">$1</span>'); const highlightedTranslation = result.translation.replace(regex, '<span class="search-highlight">$1</span>');
html += ` <div class="search-result-item" data-result-index="${index}"> <div class="search-result-page">第 ${result.page} 页</div> <div class="search-result-text">${highlightedOriginal}</div> <div class="search-result-translation">${highlightedTranslation}</div> </div> `; });
resultsContainer.innerHTML = html;
// 添加点击事件 resultsContainer.querySelectorAll('.search-result-item').forEach(item => { item.addEventListener('click', (e) => { const index = parseInt(e.currentTarget.dataset.resultIndex); this.goToSearchResult(index); }); }); }
goToSearchResult(index) { const result = this.searchResults[index]; if (!result) return;
this.currentPageIndex = result.pageIndex; this.renderCurrentPage(); this.updateUI(); this.hideSearch();
// 稍微延迟后高亮显示并播放对应片段 setTimeout(() => { const element = document.querySelector(`[data-piece-index="${result.pieceIndex}"]`); if (element) { element.scrollIntoView({ behavior: 'smooth', block: 'center' }); this.playPiece(result.piece, element); } }, 500);
this.showToast(`跳转到第 ${result.page} 页`, 'success'); }
clearSearchResults() { this.searchResults = []; document.getElementById('searchResults').innerHTML = '<div class="search-empty">输入关键词开始搜索</div>'; }
// 书签功能 toggleBookmark() { const isBookmarked = this.bookmarks.some(b => b.pageIndex === this.currentPageIndex); if (isBookmarked) { const bookmark = this.bookmarks.find(b => b.pageIndex === this.currentPageIndex); this.removeBookmark(bookmark.id); } else { this.addBookmark(); } } showBookmarks() { document.getElementById('bookmarkPanel').style.display = 'flex'; this.renderBookmarks(); }
hideBookmarks() { document.getElementById('bookmarkPanel').style.display = 'none'; }
addBookmark() { const currentPage = this.bookData[this.currentPageIndex]; if (!currentPage) return;
const bookmark = { id: Date.now(), pageIndex: this.currentPageIndex, pageNumber: currentPage.pageNumber, title: `第 ${currentPage.pageNumber} 页`, timestamp: new Date().toISOString() };
// 检查是否已存在 const exists = this.bookmarks.some(b => b.pageIndex === this.currentPageIndex); if (exists) { this.showToast('当前页面已在书签中', 'warning'); return; }
this.bookmarks.push(bookmark); this.saveBookmarks(); this.updateBookmarkButton(); this.showToast('书签添加成功', 'success'); }
removeBookmark(bookmarkId) { this.bookmarks = this.bookmarks.filter(b => b.id !== bookmarkId); this.saveBookmarks(); this.updateBookmarkButton(); this.renderBookmarks(); this.showToast('书签删除成功', 'success'); }
renderBookmarks() { const container = document.getElementById('bookmarkList'); if (this.bookmarks.length === 0) { container.innerHTML = '<div class="bookmark-empty">还没有添加任何书签</div>'; return; }
let html = ''; this.bookmarks.forEach(bookmark => { const date = new Date(bookmark.timestamp); const timeString = date.toLocaleDateString() + ' ' + date.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'}); html += ` <div class="bookmark-item" data-page-index="${bookmark.pageIndex}"> <div class="bookmark-info"> <div class="bookmark-page">${bookmark.title}</div> <div class="bookmark-time">${timeString}</div> </div> <div class="bookmark-actions"> <button class="bookmark-delete" data-bookmark-id="${bookmark.id}"> <i class="fas fa-times"></i> </button> </div> </div> `; });
container.innerHTML = html;
// 添加点击事件 container.querySelectorAll('.bookmark-item').forEach(item => { item.addEventListener('click', (e) => { if (e.target.closest('.bookmark-delete')) return; const pageIndex = parseInt(item.dataset.pageIndex); this.goToBookmark(pageIndex); }); });
container.querySelectorAll('.bookmark-delete').forEach(btn => { btn.addEventListener('click', (e) => { e.stopPropagation(); const bookmarkId = parseInt(btn.dataset.bookmarkId); this.removeBookmark(bookmarkId); }); }); }
goToBookmark(pageIndex) { this.currentPageIndex = pageIndex; this.renderCurrentPage(); this.updateUI(); this.hideBookmarks(); this.showToast(`跳转到第 ${this.bookData[pageIndex].pageNumber} 页`, 'success'); }
updateBookmarkButton() { const btn = document.getElementById('bookmarkBtn'); const isBookmarked = this.bookmarks.some(b => b.pageIndex === this.currentPageIndex); if (isBookmarked) { btn.classList.add('active'); btn.title = '取消书签'; } else { btn.classList.remove('active'); btn.title = '添加书签'; } }
loadBookmarks() { const saved = localStorage.getItem('learningAppBookmarks'); if (saved) { try { this.bookmarks = JSON.parse(saved); } catch (error) { console.error('书签加载失败:', error); this.bookmarks = []; } } }
saveBookmarks() { localStorage.setItem('learningAppBookmarks', JSON.stringify(this.bookmarks)); }
// 调试模式 toggleDebugMode() { this.debugMode = !this.debugMode; this.showToast(`调试模式: ${this.debugMode ? '开启' : '关闭'}`, 'info'); // 重新渲染当前页面以应用调试样式 this.renderCurrentPage(); }}
// 页面加载完成后初始化应用document.addEventListener('DOMContentLoaded', () => { new InteractiveLearningApp();});
// 处理页面可见性变化,暂停音频播放document.addEventListener('visibilitychange', () => { if (document.hidden) { const audio = document.getElementById('audio'); if (audio && !audio.paused) { audio.pause(); } }});.gitattributes+2
download_resources.py+4-4
index.html+4-6
static/css/all.min.cssAdded
static/css/inter.cssAdded+35
static/css/style.cssAdded+910
static/fonts/fa-brands-400.ttfAdded+3
static/fonts/fa-brands-400.woff2Added+3
static/fonts/fa-regular-400.ttfAdded+3
static/fonts/fa-regular-400.woff2Added+3
static/fonts/fa-solid-900.ttfAdded+3
static/fonts/fa-solid-900.woff2Added+3
static/fonts/fa-v4compatibility.ttfAdded+3
static/fonts/fa-v4compatibility.woff2Added+3
static/fonts/inter/Inter-300.ttfAdded+3
static/fonts/inter/Inter-400.ttfAdded+3
static/fonts/inter/Inter-500.ttfAdded+3
static/fonts/inter/Inter-600.ttfAdded+3
static/fonts/inter/Inter-700.ttfAdded+3
static/fonts/inter/Inter-Light.woff2Added+3
static/fonts/inter/inter.cssAdded+35
static/js/script.jsAdded+952