Repository navigation
Expand file tree
/
Copy pathpatch_baca.cjs
More file actions
127 lines (112 loc) · 4.28 KB
/
Copy pathpatch_baca.cjs
File metadata and controls
127 lines (112 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const fs = require('fs');
let code = fs.readFileSync('pages/baca.js', 'utf8');
const oldCode = ` // Get ID from URL
const urlParams = new URLSearchParams(window.location.search);
const diaryId = urlParams.get('id') || '1'; // Default to 1 if no ID
// Set Audio Source dynamically
audio.src = \`../assets/audio/diary/diary\${diaryId}.mp3\`;
audio.load();
// Load text
try {
const response = await fetch(\`../assets/diary/diary\${diaryId}.txt\`);
if (!response.ok) throw new Error("File tidak ditemukan");
fullText = await response.text();
} catch (error) {
fullText = "Teks diary tidak ditemukan.";
console.error(error);
}
// Update cover title
const bookTitleEl = document.querySelector('.book-title');
if (bookTitleEl) {
if (diaryId === '2') {
bookTitleEl.textContent = 'Sajak Untukmu';
} else if (diaryId === '3') {
bookTitleEl.textContent = 'Porsi';
} else if (diaryId === '4') {
bookTitleEl.textContent = 'Berubah Arah';
} else if (diaryId === '5') {
bookTitleEl.textContent = '10 malam';
} else if (diaryId === '6') {
bookTitleEl.textContent = '10 tahun';
} else if (diaryId === '7') {
bookTitleEl.textContent = 'Hening';
} else {
bookTitleEl.textContent = 'Dalam Lima Waktuku';
}
}
parseTextToTokens();
// Wait for fonts to load before measuring`;
const newCode = ` // Get ID from URL
const urlParams = new URLSearchParams(window.location.search);
const diaryId = urlParams.get('id');
const dbId = urlParams.get('dbId');
const bookTitleEl = document.querySelector('.book-title');
if (dbId) {
const fetchWait = async () => {
if (typeof window.fetchDiaryFromDB === "function") {
const data = await window.fetchDiaryFromDB(dbId);
if (data) {
fullText = data.content;
if (bookTitleEl) bookTitleEl.textContent = data.title;
} else {
fullText = "Teks diary tidak ditemukan.";
}
processText();
} else {
setTimeout(fetchWait, 100);
}
};
fetchWait();
audio.src = \`../assets/audio/diary/diary1.mp3\`;
audio.load();
return;
} else {
const idToUse = diaryId || '1';
audio.src = \`../assets/audio/diary/diary\${idToUse}.mp3\`;
audio.load();
try {
const response = await fetch(\`../assets/diary/diary\${idToUse}.txt\`);
if (!response.ok) throw new Error("File tidak ditemukan");
fullText = await response.text();
} catch (error) {
fullText = "Teks diary tidak ditemukan.";
console.error(error);
}
if (bookTitleEl) {
if (idToUse === '2') {
bookTitleEl.textContent = 'Sajak Untukmu';
} else if (idToUse === '3') {
bookTitleEl.textContent = 'Porsi';
} else if (idToUse === '4') {
bookTitleEl.textContent = 'Berubah Arah';
} else if (idToUse === '5') {
bookTitleEl.textContent = '10 malam';
} else if (idToUse === '6') {
bookTitleEl.textContent = '10 tahun';
} else if (idToUse === '7') {
bookTitleEl.textContent = 'Hening';
} else {
bookTitleEl.textContent = 'Dalam Lima Waktuku';
}
}
processText();
}
function processText() {
parseTextToTokens();
// Wait for fonts to load before measuring
document.fonts.ready.then(() => {
paginateText();
setTimeout(() => {
loadingScreen.classList.remove('active');
bookScreen.classList.add('active');
setTimeout(() => {
hintText.classList.add('visible');
}, 1000);
}, 1500);
});
}
// Disable rest of old code block that called document.fonts.ready
return;
// Wait for fonts to load before measuring`;
code = code.replace(oldCode, newCode);
fs.writeFileSync('pages/baca.js', code);