fictioneer/js/chapter.min.js

1 line
14 KiB
JavaScript
Raw Normal View History

const fcn_chapterFormatting=_$(".chapter-formatting");var fcn_formatting=fcn_getFormatting();const fcn_paragraphTools=_$$$("paragraph-tools");var fcn_lastSelectedParagraphId,fcn_bookmarkColor="none";function fcn_toggleParagraphTools(t=!1,e=null){e&&e.classList.contains("spoiler")&&!e.classList.contains("_open")||(_$$$(`paragraph-${fcn_lastSelectedParagraphId}`)?.classList.remove("selected-paragraph"),t&&fcn_formatting["show-paragraph-tools"]?(fcn_lastSelectedParagraphId=t,e.classList.add("selected-paragraph"),e.classList.contains("is-wrapped")||(e.innerHTML=`<span class="paragraph-inner">${e.innerHTML}</span>`,e.classList.add("is-wrapped")),e.append(fcn_paragraphTools)):fcn_lastSelectedParagraphId=null)}function fcn_touchParagraph(t){if(t.target.classList.contains("spoiler"))return;if(!t.target.closest("p")?.parentElement?.classList.contains("chapter-formatting"))return;if(t.target.closest(".hidden, .inside-epub"))return;if(""!=window.getSelection().toString())return;const e=t.target.closest("p[data-paragraph-id]");if(t.target.closest(".tts-interface, .paragraph-tools__actions"))return;if(!e)return void fcn_toggleParagraphTools(!1);let n=!!e.dataset.paragraphId&&e.dataset.paragraphId;n=n!=fcn_lastSelectedParagraphId&&n;const a=(new Date).getTime();e.addEventListener("mouseup",(()=>{(new Date).getTime()<=a+300&&fcn_toggleParagraphTools(n,e)}),{once:!0})}function fcn_getQuote(t){const e=fcn_cleanTextSelectionFromButtons(window.getSelection().toString()),n=`[anchor]${t.target.closest("p[data-paragraph-id]").id}[/anchor]`;let a=t.target.closest("p[data-paragraph-id]").querySelector(".paragraph-inner").innerText,o="[…] ",r=" […]";if(a.length>16&&e.replace(/\s/g,"").length){const t=Math.ceil(.25*e.length),n=a.substring(0,t+1),c=a.substring(a.length-t,a.length);e.startsWith(n)&&(o=""),e.endsWith(c)&&(r=""),a=`${o}${e}${r}`}a=`${a} ${n}`,fcn_addQuoteToStack(a),fcn_showNotification(fictioneer_tl.notification.quoteAppendedToComment)}function fcn_addQuoteToStack(t){const e=_$(fictioneer_comments.form_selector??"#comment");e?"TEXTAREA"==e.tagName?(e.value+=`\n[quote]${t}[/quote]\n`,fcn_textareaAdjust(_$("textarea#comment"))):"DIV"==e.tagName&&(e.innerHTML+=`\n[quote]${t}[/quote]\n`):fcn_commentStack?.push(`\n[quote]${t}[/quote]\n`)}function fcn_openFullscreen(){document.documentElement.requestFullscreen?document.documentElement.requestFullscreen():document.documentElement.webkitRequestFullscreen&&document.documentElement.webkitRequestFullscreen()}function fcn_closeFullscreen(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen&&document.webkitExitFullscreen()}function fcn_getFormatting(){let t=fcn_parseJSON(localStorage.getItem("fcnChapterFormatting"))??fcn_defaultFormatting();return Object.keys(t).length<15&&(t=fcn_defaultFormatting()),t.timestamp<1651164557584&&(t=fcn_defaultFormatting(),t.timestamp=Date.now()),fcn_setFormatting(t),t}function fcn_defaultFormatting(){return{"font-saturation":0,"font-color":fictioneer_font_colors[0].css,"font-name":fictioneer_fonts[0].css,"font-size":100,"letter-spacing":0,"line-height":1.7,"paragraph-spacing":1.5,"site-width":fcn_theRoot.dataset.siteWidthDefault??"960",indent:!0,"show-sensitive-content":!0,"show-chapter-notes":!0,justify:!1,"show-comments":!0,"show-paragraph-tools":!0,timestamp:1664797604825,...JSON.parse(fcn_theRoot.dataset.defaultFormatting??"{}")}}function fcn_setFormatting(t){"object"==typeof t&&(fcn_formatting=t,localStorage.setItem("fcnChapterFormatting",JSON.stringify(t)))}function fcn_updateToggle(t,e,n,a={}){a={save:!0,...a};const o=fcn_evaluateAsBoolean(t,!0),r=_$(e);if(r&&(r.checked=o,r.closest("label").setAttribute("aria-checked",o)),a.toggleClass&&fcn_chapterFormatting.classList.toggle(a.toggleClass,a.invertClass?!o:o),a.sensitiveContent){const t=_$$$("inline-sensitive-content-toggle");t?.classList.toggle("hide-sensitive",!o),t?.setAttribute("aria-checked",!o)}a.notes&&_$$(".chapter-note-hideable").forEach((t=>{t.classList.toggle("hidden",!o)})),a.comments&&_$$(".chapter-comments-hideable").forEach((t=>{t.classList.toggle("hidden",!o)}