From 11c2dc3dda209f4048f91b8841c48873d8ffbf06 Mon Sep 17 00:00:00 2001 From: KiwiGaze <1244666638@qq.com> Date: Wed, 25 Sep 2024 16:05:26 +0800 Subject: [PATCH] feat: Improve lazy loading of transcript file --- index.html | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/index.html b/index.html index 608e8c1..d4f6cb0 100644 --- a/index.html +++ b/index.html @@ -99,19 +99,15 @@ const nodeJSON = document.getElementById('json'); nodeJSON.value = "Please wait..."; - const reader = new FileReader(); - reader.onload = async (event) => { - // Debugging - const jsonString = event.target.result; - console.log("Type of event result:", typeof jsonString); + const response = await fetch('./transcript/transcript.json') + if (response.ok) { + const json = await response.json(); + nodeJSON.value = JSON.stringify(json, null, 4); // Parse JSON - const json = JSON.parse(jsonString); console.log("Type of JSON:", typeof json); - nodeJSON.value = JSON.stringify(json, null, 4); - // Debugging console.log("Words from JSON:", json.words); @@ -264,20 +260,6 @@ mtimes: audio.mtimes.slice(startIndex).map(time => time - audio.wtimes[startIndex]) }; } - // Fetch transcript from the local path - async function loadTranscriptFile() { - try { - const response = await fetch('./transcript/transcript.json'); - if (!response.ok) { - throw new Error(`Failed to load transcript: ${response.statusText}`); - } - return response; - } catch (error) { - console.error('Error loading transcript:', error); - return null; - } - } - });