fix: clamp review star value to 0-5 range to prevent repeat() RangeError

WeRead API returns star=100 for book reviews and star=-1 for thoughts,
causing '☆'.repeat(5-100) to throw 'Invalid count value: -95'.
This commit is contained in:
admin committed 2026-07-17 11:17:55 +08:00
1 parent ae40ed93d6
commit 4d8cc2a2d7
1 file changed
+2 -1
+2 -1
View File
@@ -813,7 +813,8 @@ function openNotes(bookId, title, author, cover) {
if (data.review_count > 0) { if (data.review_count > 0) {
html += `<div class="notes-section-title">💭 想法/点评 (${data.review_count})</div>`; html += `<div class="notes-section-title">💭 想法/点评 (${data.review_count})</div>`;
data.reviews.forEach((r) => { data.reviews.forEach((r) => {
const stars = r.star > 0 ? `<span class="review-star">${"★".repeat(r.star)}${"☆".repeat(5 - r.star)}</span>` : ""; const starVal = Math.max(0, Math.min(5, parseInt(r.star) || 0));
const stars = starVal > 0 ? `<span class="review-star">${"★".repeat(starVal)}${"☆".repeat(5 - starVal)}</span>` : "";
html += ` html += `
<div class="review-item"> <div class="review-item">
${escapeHtml(r.content)} ${escapeHtml(r.content)}