fix: complete tooltip implementation and remove DOM status element
- 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>
This commit is contained in:
parent
40a95fa7a6
commit
30e80b98b3
5 changed files with 42 additions and 81 deletions
|
|
@ -1,74 +1,57 @@
|
|||
// 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() {
|
||||
export async function readPageWithHermes(button = null) {
|
||||
const content = extractWebpageContent();
|
||||
|
||||
// Create status indicator
|
||||
const statusDiv = document.createElement("div");
|
||||
statusDiv.className = "uncloseai-page-reader-status";
|
||||
document.body.appendChild(statusDiv);
|
||||
|
||||
statusDiv.textContent = "Processing content and generating speech...";
|
||||
// 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);
|
||||
|
||||
statusDiv.textContent = "Reading page... ";
|
||||
if (button) {
|
||||
button.title = getUIText("readingPageClickToPause");
|
||||
}
|
||||
|
||||
let isPaused = false;
|
||||
|
||||
// Add pause/resume button
|
||||
const pauseButton = document.createElement("button");
|
||||
pauseButton.textContent = "Pause Reading";
|
||||
pauseButton.className = "uncloseai-btn-margin-left";
|
||||
statusDiv.appendChild(pauseButton);
|
||||
// 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;
|
||||
};
|
||||
|
||||
// Add download button
|
||||
const downloadButton = document.createElement("button");
|
||||
downloadButton.textContent = "Download MP3";
|
||||
downloadButton.className = "uncloseai-btn-margin-left";
|
||||
downloadButton.onclick = async () => {
|
||||
try {
|
||||
const { generateTitleForTTS } = await import("./tts.js");
|
||||
console.log("Generating title for Read Page content:", processedContent.substring(0, 200) + "...");
|
||||
const filename = await generateTitleForTTS(processedContent);
|
||||
console.log("Generated filename:", filename);
|
||||
const a = document.createElement("a");
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = `${filename}.mp3`;
|
||||
a.click();
|
||||
} catch (error) {
|
||||
console.error("Error generating filename for Read Page:", error);
|
||||
// Fallback to document title
|
||||
const a = document.createElement("a");
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = `${document.title.replace(/\s+/g, "-").toLowerCase()}.mp3`;
|
||||
a.click();
|
||||
}
|
||||
};
|
||||
statusDiv.appendChild(downloadButton);
|
||||
|
||||
pauseButton.onclick = () => {
|
||||
if (isPaused) {
|
||||
audio.play();
|
||||
pauseButton.textContent = "Pause Reading";
|
||||
} else {
|
||||
audio.pause();
|
||||
pauseButton.textContent = "Resume Reading";
|
||||
}
|
||||
isPaused = !isPaused;
|
||||
};
|
||||
|
||||
// Set up audio end handler
|
||||
audio.onended = () => {
|
||||
statusDiv.remove();
|
||||
};
|
||||
// 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 };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ export function initializeChatInterface() {
|
|||
export function addReadPageButton() {
|
||||
const button = document.createElement("button");
|
||||
button.textContent = "Read Page";
|
||||
button.onclick = readPageWithHermes;
|
||||
button.onclick = (event) => readPageWithHermes(event.target);
|
||||
button.className = "uncloseai-ui-button-margin";
|
||||
|
||||
const ttsButton = document.createElement("button");
|
||||
|
|
|
|||
|
|
@ -1101,18 +1101,7 @@ dialog#uncloseai-embedded-modal[data-theme="dark"] .user-message {
|
|||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
/* Page reader status div - tooltip style */
|
||||
.uncloseai-page-reader-status {
|
||||
position: fixed;
|
||||
bottom: 80px;
|
||||
right: 20px;
|
||||
padding: 8px 12px;
|
||||
background: rgba(0, 0, 0, 0.85);
|
||||
color: white;
|
||||
border-radius: 6px;
|
||||
z-index: 1001;
|
||||
font-size: 12px;
|
||||
line-height: 1.3;
|
||||
/* Page reader status div - REMOVED (using tooltips now) */
|
||||
max-width: 280px;
|
||||
backdrop-filter: blur(4px);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
|
||||
|
|
|
|||
|
|
@ -1149,18 +1149,7 @@ dialog#uncloseai-embedded-modal[data-theme="dark"] .user-message {
|
|||
background: rgba(255, 255, 255, 0.3) !important;
|
||||
}
|
||||
|
||||
/* Page reader status div - tooltip style */
|
||||
.uncloseai-page-reader-status {
|
||||
position: fixed !important;
|
||||
bottom: 80px !important;
|
||||
right: 20px !important;
|
||||
padding: 8px 12px !important;
|
||||
background: rgba(0, 0, 0, 0.85) !important;
|
||||
color: white !important;
|
||||
border-radius: 6px !important;
|
||||
z-index: 1001 !important;
|
||||
font-size: 12px !important;
|
||||
line-height: 1.3 !important;
|
||||
/* Page reader status div - REMOVED (using tooltips now) */
|
||||
max-width: 280px !important;
|
||||
backdrop-filter: blur(4px) !important;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4) !important;
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ export function createFullInterface(container) {
|
|||
const controlsDiv = document.createElement("div");
|
||||
controlsDiv.className = "widget-custom-grid";
|
||||
|
||||
const readBtn = createButton(getUIText("readPage"), () =>
|
||||
readPageWithHermes(),
|
||||
const readBtn = createButton(getUIText("readPage"), (event) =>
|
||||
readPageWithHermes(event.target),
|
||||
);
|
||||
const ttsBtn = createButton(getUIText("ttsAnything"), () => openTTSModal());
|
||||
const translateBtn = createButton(getUIText("translate"), () =>
|
||||
|
|
@ -167,7 +167,7 @@ export function createReadFeature(container) {
|
|||
button.textContent = getUIText("readPage");
|
||||
button.setAttribute("data-i18n", "readPage");
|
||||
button.className = "widget-send-btn";
|
||||
button.onclick = readPageWithHermes;
|
||||
button.onclick = (event) => readPageWithHermes(event.target);
|
||||
|
||||
readDiv.appendChild(heading);
|
||||
readDiv.appendChild(description);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue