aboutsummaryrefslogtreecommitdiffstats
path: root/html/rtb/public
diff options
context:
space:
mode:
authorelioat <{ID}+{username}@users.noreply.github.com>2025-09-30 09:34:59 -0400
committerelioat <{ID}+{username}@users.noreply.github.com>2025-09-30 09:34:59 -0400
commitdd79baacf8dcaaea21d3b11c104677e344f49c4d (patch)
tree6ded52dd1811ffd9841b3155c8f9dbc301c1f5ac /html/rtb/public
parentf1c601a66df41cb4f31f8a521df0f0b2ac88169b (diff)
downloadtour-dd79baacf8dcaaea21d3b11c104677e344f49c4d.tar.gz
*
Diffstat (limited to 'html/rtb/public')
-rw-r--r--html/rtb/public/about.html69
-rw-r--r--html/rtb/public/app.js90
-rw-r--r--html/rtb/public/styles.css170
3 files changed, 299 insertions, 30 deletions
diff --git a/html/rtb/public/about.html b/html/rtb/public/about.html
new file mode 100644
index 0000000..2e171f8
--- /dev/null
+++ b/html/rtb/public/about.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>About Read the Book</title>
+ <link rel="stylesheet" href="styles.css">
+</head>
+<body>
+ <div class="about-container">
+ <div class="about-reading-view">
+ <div class="about-text">
+ <p>I felt myself falling into bad habits.</p>
+
+ <p>This project is meant to replace doom scrolling and encourage reading books by presenting them in really tiny digestible parts.</p>
+
+ <p>All the books are from the <a href="https://gutenberg.org/">public domain</a>.</p>
+ </div>
+
+ <div class="about-controls">
+ <a href="index.html" class="back-link">Back to Reading</a>
+ </div>
+ </div>
+ </div>
+
+ <script>
+ // Simple dark mode application for about page
+ const STORAGE_KEY = 'rtb-state';
+
+ function loadDarkMode() {
+ try {
+ const saved = localStorage.getItem(STORAGE_KEY);
+ if (saved) {
+ const state = JSON.parse(saved);
+ return state.darkMode !== undefined ? state.darkMode : null;
+ }
+ } catch (e) {
+ console.error('Failed to load dark mode state:', e);
+ }
+ return null;
+ }
+
+ function getEffectiveDarkMode() {
+ const darkMode = loadDarkMode();
+ if (darkMode !== null) {
+ return darkMode;
+ }
+ return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
+ }
+
+ function applyDarkMode() {
+ const isDark = getEffectiveDarkMode();
+ document.documentElement.classList.toggle('dark-mode', isDark);
+ }
+
+ // Apply dark mode on load
+ document.addEventListener('DOMContentLoaded', applyDarkMode);
+
+ // Listen for system preference changes
+ if (window.matchMedia) {
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
+ if (loadDarkMode() === null) {
+ applyDarkMode();
+ }
+ });
+ }
+ </script>
+</body>
+</html> \ No newline at end of file
diff --git a/html/rtb/public/app.js b/html/rtb/public/app.js
index 4d682b4..db91289 100644
--- a/html/rtb/public/app.js
+++ b/html/rtb/public/app.js
@@ -12,7 +12,8 @@ function createInitialModel() {
currentSentence: 0,
error: null,
chunkCache: {},
- cacheAccessOrder: []
+ cacheAccessOrder: [],
+ darkMode: null // null = auto, true = dark, false = light
};
}
@@ -25,7 +26,8 @@ function loadState() {
...createInitialModel(),
readingProgress: state.readingProgress || {},
currentBookId: state.currentBookId || null,
- currentSentence: state.currentSentence || 0
+ currentSentence: state.currentSentence || 0,
+ darkMode: state.darkMode !== undefined ? state.darkMode : null
};
}
} catch (e) {
@@ -39,7 +41,8 @@ function saveState(model) {
const toSave = {
readingProgress: model.readingProgress,
currentBookId: model.currentBookId,
- currentSentence: model.currentSentence
+ currentSentence: model.currentSentence,
+ darkMode: model.darkMode
};
localStorage.setItem(STORAGE_KEY, JSON.stringify(toSave));
} catch (e) {
@@ -63,6 +66,33 @@ function getBook(model, bookId) {
return model.books.find(b => b.id === bookId);
}
+function getSortableTitle(title) {
+ // Remove leading articles for sorting
+ const articles = ['the ', 'a ', 'an '];
+ let sortableTitle = title.toLowerCase();
+
+ for (const article of articles) {
+ if (sortableTitle.startsWith(article)) {
+ sortableTitle = sortableTitle.substring(article.length);
+ break;
+ }
+ }
+
+ return sortableTitle;
+}
+
+function getEffectiveDarkMode(model) {
+ if (model.darkMode !== null) {
+ return model.darkMode;
+ }
+ return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
+}
+
+function applyDarkMode(model) {
+ const isDark = getEffectiveDarkMode(model);
+ document.documentElement.classList.toggle('dark-mode', isDark);
+}
+
function updateCache(model, chunkIndex, sentences) {
const newCache = { ...model.chunkCache, [chunkIndex]: sentences };
const newOrder = model.cacheAccessOrder.filter(i => i !== chunkIndex);
@@ -255,6 +285,15 @@ async function update(msg, model) {
};
}
+ case 'SetDarkMode': {
+ const newModel = {
+ ...model,
+ darkMode: msg.darkMode
+ };
+ saveState(newModel);
+ return newModel;
+ }
+
default:
return model;
}
@@ -262,6 +301,7 @@ async function update(msg, model) {
function render(model) {
const app = document.getElementById('app');
+ applyDarkMode(model);
if (model.view === 'loading') {
app.innerHTML = '<div class="loading">Loading...</div>';
@@ -269,7 +309,13 @@ function render(model) {
}
if (model.view === 'selecting') {
- const bookItems = model.books.map(book => {
+ const sortedBooks = [...model.books].sort((a, b) => {
+ const titleA = getSortableTitle(a.title);
+ const titleB = getSortableTitle(b.title);
+ return titleA.localeCompare(titleB);
+ });
+
+ const bookItems = sortedBooks.map(book => {
const progress = model.readingProgress[book.id];
const percentage = progress
? Math.round((progress.currentSentence / book.totalSentences) * 100)
@@ -285,9 +331,17 @@ function render(model) {
}).join('');
app.innerHTML = `
- <h1>Read the Book</h1>
+ <div class="header">
+ <h1>Read the Book</h1>
+ <select id="dark-mode-select" class="dark-mode-select" title="Choose dark mode preference">
+ <option value="auto" ${model.darkMode === null ? 'selected' : ''}>🌓 Auto</option>
+ <option value="light" ${model.darkMode === false ? 'selected' : ''}>☀️ Light</option>
+ <option value="dark" ${model.darkMode === true ? 'selected' : ''}>🌙 Dark</option>
+ </select>
+ </div>
${model.error ? `<div class="error">${model.error}</div>` : ''}
<ul class="book-list">${bookItems}</ul>
+ <footer><p><a href="about.html">About</a></p></footer>
`;
document.querySelectorAll('.book-item').forEach(item => {
@@ -296,6 +350,15 @@ function render(model) {
dispatch({ type: 'SelectBook', bookId });
});
});
+
+ const darkModeSelect = document.getElementById('dark-mode-select');
+ if (darkModeSelect) {
+ darkModeSelect.addEventListener('change', (e) => {
+ const value = e.target.value;
+ const newDarkMode = value === 'auto' ? null : value === 'dark';
+ dispatch({ type: 'SetDarkMode', darkMode: newDarkMode });
+ });
+ }
return;
}
@@ -321,7 +384,7 @@ function render(model) {
${book.title} — ${progress}% complete
</div>
<button class="secondary" id="select-another" style="margin-top: 2rem;">
- Choose Another Book
+ Choose a Different Book
</button>
</div>
`;
@@ -350,10 +413,10 @@ function render(model) {
app.innerHTML = `
<div class="completed-view">
- <h2>Congratulations!</h2>
- <p>You've completed <em>${book ? book.title : 'this book'}</em></p>
+ <h2>The End!</h2>
+ <p>You've finished <em>${book ? book.title : 'this book'}</em></p>
<button id="select-another" style="margin-top: 2rem;">
- Choose Another Book
+ Choose A New Book
</button>
</div>
`;
@@ -371,4 +434,13 @@ async function dispatch(msg) {
render(currentModel);
}
+// Listen for system preference changes
+if (window.matchMedia) {
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
+ if (currentModel.darkMode === null) {
+ applyDarkMode(currentModel);
+ }
+ });
+}
+
dispatch({ type: 'Initialize' }); \ No newline at end of file
diff --git a/html/rtb/public/styles.css b/html/rtb/public/styles.css
index 0c2630b..1f02622 100644
--- a/html/rtb/public/styles.css
+++ b/html/rtb/public/styles.css
@@ -1,3 +1,41 @@
+:root {
+ --bg-primary: #faf9f6;
+ --bg-secondary: #ffffff;
+ --text-primary: #333;
+ --text-secondary: #7f8c8d;
+ --text-muted: #95a5a6;
+ --border-color: rgba(0,0,0,0.1);
+ --shadow: 0 2px 4px rgba(0,0,0,0.1);
+ --shadow-hover: 0 4px 8px rgba(0,0,0,0.15);
+ --button-primary: #3498db;
+ --button-primary-hover: #2980b9;
+ --button-secondary: #95a5a6;
+ --button-secondary-hover: #7f8c8d;
+ --button-disabled: #bdc3c7;
+ --error-bg: #fadbd8;
+ --error-text: #e74c3c;
+ --success-text: #27ae60;
+}
+
+.dark-mode {
+ --bg-primary: #1a1a1a;
+ --bg-secondary: #2d2d2d;
+ --text-primary: #e0e0e0;
+ --text-secondary: #a0a0a0;
+ --text-muted: #808080;
+ --border-color: rgba(255,255,255,0.1);
+ --shadow: 0 2px 4px rgba(0,0,0,0.3);
+ --shadow-hover: 0 4px 8px rgba(0,0,0,0.4);
+ --button-primary: #4a9eff;
+ --button-primary-hover: #357abd;
+ --button-secondary: #6c757d;
+ --button-secondary-hover: #5a6268;
+ --button-disabled: #495057;
+ --error-bg: #2d1b1b;
+ --error-text: #ff6b6b;
+ --success-text: #51cf66;
+}
+
* {
margin: 0;
padding: 0;
@@ -6,9 +44,15 @@
body {
font-family: 'Georgia', serif;
- background-color: #faf9f6;
- color: #333;
+ background-color: var(--bg-primary);
+ color: var(--text-primary);
line-height: 1.6;
+ transition: background-color 0.3s ease, color 0.3s ease;
+}
+
+footer {
+ text-align: center;
+ margin-top: 2rem;
}
#app {
@@ -18,16 +62,23 @@ body {
min-height: 100vh;
}
+.header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 2rem;
+}
+
h1 {
font-size: 2.5rem;
- margin-bottom: 1rem;
- color: #2c3e50;
+ margin-bottom: 0;
+ color: var(--text-primary);
}
h2 {
font-size: 1.8rem;
margin-bottom: 1.5rem;
- color: #34495e;
+ color: var(--text-primary);
}
.book-list {
@@ -37,32 +88,33 @@ h2 {
.book-item {
padding: 1.5rem;
margin-bottom: 1rem;
- background: white;
+ background: var(--bg-secondary);
border-radius: 8px;
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
+ box-shadow: var(--shadow);
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
.book-item:hover {
transform: translateY(-2px);
- box-shadow: 0 4px 8px rgba(0,0,0,0.15);
+ box-shadow: var(--shadow-hover);
}
.book-title {
font-size: 1.5rem;
font-weight: bold;
margin-bottom: 0.5rem;
+ color: var(--text-primary);
}
.book-author {
font-size: 1.1rem;
- color: #7f8c8d;
+ color: var(--text-secondary);
}
.book-progress {
font-size: 0.9rem;
- color: #95a5a6;
+ color: var(--text-muted);
margin-top: 0.5rem;
}
@@ -78,8 +130,8 @@ h2 {
font-size: 1.4rem;
line-height: 1.8;
margin-bottom: 3rem;
- text-align: justify;
max-width: 650px;
+ color: var(--text-primary);
}
.controls {
@@ -91,7 +143,7 @@ h2 {
button {
padding: 0.75rem 1.5rem;
font-size: 1rem;
- background: #3498db;
+ background: var(--button-primary);
color: white;
border: none;
border-radius: 6px;
@@ -101,25 +153,49 @@ button {
}
button:hover:not(:disabled) {
- background: #2980b9;
+ background: var(--button-primary-hover);
}
button:disabled {
- background: #bdc3c7;
+ background: var(--button-disabled);
cursor: not-allowed;
}
button.secondary {
- background: #95a5a6;
+ background: var(--button-secondary);
}
button.secondary:hover:not(:disabled) {
- background: #7f8c8d;
+ background: var(--button-secondary-hover);
+}
+
+.dark-mode-select {
+ background: var(--bg-secondary);
+ color: var(--text-primary);
+ border: 1px solid var(--border-color);
+ border-radius: 6px;
+ padding: 0.5rem 0.75rem;
+ font-size: 0.9rem;
+ font-family: inherit;
+ cursor: pointer;
+ transition: background-color 0.2s, border-color 0.2s;
+ min-width: 120px;
+}
+
+.dark-mode-select:hover {
+ background: var(--button-secondary);
+ border-color: var(--button-secondary-hover);
+}
+
+.dark-mode-select:focus {
+ outline: none;
+ border-color: var(--button-primary);
+ box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}
.progress-info {
font-size: 0.9rem;
- color: #7f8c8d;
+ color: var(--text-secondary);
margin-top: 1rem;
}
@@ -129,14 +205,14 @@ button.secondary:hover:not(:disabled) {
}
.completed-view h2 {
- color: #27ae60;
+ color: var(--success-text);
margin-bottom: 2rem;
}
.error {
- color: #e74c3c;
+ color: var(--error-text);
padding: 1rem;
- background: #fadbd8;
+ background: var(--error-bg);
border-radius: 6px;
margin-bottom: 1rem;
}
@@ -145,5 +221,57 @@ button.secondary:hover:not(:disabled) {
text-align: center;
padding: 2rem;
font-size: 1.2rem;
- color: #7f8c8d;
+ color: var(--text-secondary);
+}
+
+/* About Page Styles */
+.about-container {
+ max-width: 800px;
+ margin: 0 auto;
+ padding: 2rem;
+ min-height: 100vh;
+}
+
+.about-reading-view {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ min-height: 80vh;
+}
+
+.about-text {
+ font-size: 1.4rem;
+ line-height: 1.8;
+ margin-bottom: 3rem;
+ max-width: 650px;
+ color: var(--text-primary);
+}
+
+.about-text p {
+ margin-bottom: 2rem;
+}
+
+.about-controls {
+ display: flex;
+ gap: 1rem;
+ align-items: center;
+}
+
+.back-link {
+ color: var(--button-primary);
+ text-decoration: none;
+ font-size: 1rem;
+ padding: 0.75rem 1.5rem;
+ background: var(--button-primary);
+ color: white;
+ border: none;
+ border-radius: 6px;
+ cursor: pointer;
+ transition: background 0.2s;
+ font-family: inherit;
+}
+
+.back-link:hover {
+ background: var(--button-primary-hover);
} \ No newline at end of file