- Update all readPageWithHermes calls to pass button parameter - Remove CSS styling for page reader status DOM element - Ensure all Read Page buttons use tooltips instead of separate status div 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
// Page reading functionality
|
|
import { extractWebpageContent } from "./content.js";
|
|
import { processContentWithHermes, speakText } from "./tts.js";
|
|
import { getUIText } from "./ui-translations.js";
|
|
|
|
// Function to read the entire page using Hermes
|
|
export async function readPageWithHermes(button = null) {
|
|
const content = extractWebpageContent();
|
|
|
|
// Update button tooltip instead of creating separate DOM element
|
|
if (button) {
|
|
button.title = getUIText("processingContent");
|
|
}
|
|
|
|
const processedContent = await processContentWithHermes(content);
|
|
|
|
// Generate TTS with default voice and 90% speed immediately
|
|
const { audio, blob } = await speakText(processedContent, "alloy", 0.9);
|
|
|
|
if (button) {
|
|
button.title = getUIText("readingPageClickToPause");
|
|
}
|
|
|
|
let isPaused = false;
|
|
|
|
// Make the button interactive for pause/resume
|
|
if (button) {
|
|
const originalEmoji = button.textContent;
|
|
const originalOnclick = button.onclick;
|
|
|
|
button.onclick = () => {
|
|
if (isPaused) {
|
|
audio.play();
|
|
button.title = getUIText("readingPageClickToPause");
|
|
button.textContent = originalEmoji;
|
|
} else {
|
|
audio.pause();
|
|
button.title = getUIText("pausedClickToResume");
|
|
button.textContent = "⏸️";
|
|
}
|
|
isPaused = !isPaused;
|
|
};
|
|
|
|
// Set up audio end handler
|
|
audio.onended = () => {
|
|
button.title = getUIText("readPage");
|
|
button.textContent = originalEmoji;
|
|
button.onclick = originalOnclick;
|
|
};
|
|
}
|
|
|
|
// Start playing immediately
|
|
audio.play();
|
|
|
|
// Return audio and blob for download functionality
|
|
return { audio, blob };
|
|
}
|