11/**
2- * PaperNovel – Pure Frontend
2+ * Paper2Novel – Pure Frontend
33 * No backend needed. All logic runs in the browser:
44 * 1. Fetch paper from ar5iv (HTML) or arXiv API (metadata)
55 * 2. Chunk text by character/paragraph boundaries
@@ -635,18 +635,42 @@ function renderNovelText(text) {
635635 . replace ( / \n / g, "<br>" ) ;
636636
637637 const noteHtml = note ? `<div class="novel-note">${ note } </div>` : "" ;
638- const blockClass = note ? "novel-block" : "novel-block no-note" ;
638+
639+ // Add toggle button if note exists
640+ const toggleBtn = note ? `<button class="note-toggle" aria-label="查看注释">💡</button>` : "" ;
639641
640642 html += `
641- <div class="${ blockClass } ">
642- <div class="novel-text">${ content } </div>
643+ <div class="novel-block ">
644+ <div class="novel-text">${ content } ${ toggleBtn } </div>
643645 ${ noteHtml }
644646 </div>` ;
645647 }
646648
647649 return html ;
648650}
649651
652+ // ── Event Delegation for Notes ─────────────────────────
653+ document . addEventListener ( "click" , ( e ) => {
654+ const btn = e . target . closest ( ".note-toggle" ) ;
655+ if ( ! btn ) return ;
656+
657+ // Prevent default button behavior
658+ e . preventDefault ( ) ;
659+ e . stopPropagation ( ) ;
660+
661+ // Toggle active state on button
662+ btn . classList . toggle ( "active" ) ;
663+
664+ // Find the note (it should be in the parent .novel-block, next to .novel-text)
665+ const block = btn . closest ( ".novel-block" ) ;
666+ if ( block ) {
667+ const note = block . querySelector ( ".novel-note" ) ;
668+ if ( note ) {
669+ note . classList . toggle ( "visible" ) ;
670+ }
671+ }
672+ } ) ;
673+
650674function copyNovel ( ) {
651675 const content = document . getElementById ( "novelContent" ) ;
652676 const text = content . innerText ;
@@ -714,7 +738,7 @@ function renderDemoChapter(index) {
714738
715739 // Check for special formatting
716740 if ( text . startsWith ( "<strong" ) ) {
717- html += `<div class="novel-block no-note "><div class="novel-text" style="text-indent:0">${ text } </div></div>` ;
741+ html += `<div class="novel-block"><div class="novel-text" style="text-indent:0">${ text } </div></div>` ;
718742 } else if ( text . startsWith ( "——" ) ) {
719743 html += `<div class="demo-separator">${ text } </div>` ;
720744 } else {
@@ -724,11 +748,11 @@ function renderDemoChapter(index) {
724748 . replace ( / \* ( .+ ?) \* / g, "<em>$1</em>" ) ;
725749
726750 const noteHtml = note ? `<div class="novel-note">${ note } </div>` : "" ;
727- const blockClass = note ? "novel-block" : "novel-block no-note " ;
751+ const toggleBtn = note ? `<button class="note-toggle" aria-label="查看注释">💡</button>` : "" ;
728752
729753 html += `
730- <div class="${ blockClass } ">
731- <div class="novel-text">${ processed } </div>
754+ <div class="novel-block ">
755+ <div class="novel-text">${ processed } ${ toggleBtn } </div>
732756 ${ noteHtml }
733757 </div>` ;
734758 }
0 commit comments