corrad-af-2024/composables/useVoiceReader.js
Md Afiq Iskandar ef5526baf1 Refactor Application Creation and Management Logic
- Simplified the application creation process by consolidating form fields and enhancing validation.
- Updated the create application page to streamline user experience with clearer provider options and improved layout.
- Implemented SweetAlert for success and error notifications during user actions, replacing traditional alerts.
- Enhanced the applications index page with dynamic filtering and improved data fetching from the Authentik API.
- Refactored API endpoints to utilize slugs for application identification, ensuring consistency with Authentik's structure.
- Improved authentication handling by updating the requireAuth utility to support cookie-based authentication.
2025-06-17 11:53:15 +08:00

56 lines
1.2 KiB
JavaScript

export function useVoiceReader() {
const isReading = ref(false);
const announceElement = ref(null);
let speechSynthesis;
let speechUtterance;
onMounted(() => {
speechSynthesis = window.speechSynthesis;
speechUtterance = new SpeechSynthesisUtterance();
window.addEventListener("keydown", handleKeydown);
});
onUnmounted(() => {
if (speechSynthesis) {
speechSynthesis.cancel();
}
window.removeEventListener("keydown", handleKeydown);
});
const toggleReading = () => {
if (!speechSynthesis) return;
if (isReading.value) {
speechSynthesis.pause();
isReading.value = false;
announce("Reading paused");
} else {
const textToRead = document.body.innerText;
speechUtterance.text = textToRead;
speechSynthesis.speak(speechUtterance);
isReading.value = true;
announce("Reading started");
}
};
const handleKeydown = (event) => {
// if (event.ctrlKey && event.key === "r") {
// event.preventDefault();
// toggleReading();
// }
};
const announce = (message) => {
if (announceElement.value) {
announceElement.value.textContent = message;
}
};
return {
isReading,
toggleReading,
announceElement,
};
}