1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
const fcn_letterSpacingDefault=0,fcn_paragraphSpacingDefault=1.5,fcn_lineHeightDefault=1.7,fcn_siteWidthDefault=fcn_theRoot.dataset.siteWidthDefault??"960",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(fcn_theSite.classList.contains("transformed-site"))return;if(t.target.classList.contains("spoiler"))return;if(!t.target.closest("p")?.parentElement?.classList.contains("chapter-formatting"))return;if(t.target.closest(".hidden")||t.target.closest(".inside-epub"))return;if(""!=window.getSelection().toString())return;const e=t.target.closest("p[data-paragraph-id]");if(t.target.closest(".tts-interface")||t.target.closest(".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").innerHTML,c="[…] ",o=" […]";if(a.length>16&&e.replace(/\s/g,"").length){const t=Math.ceil(.25*e.length),n=a.substring(0,t+1),i=a.substring(a.length-t,a.length);e.startsWith(n)&&(c=""),e.endsWith(i)&&(o=""),a=`${c}${e}${o}`}a=`${a} ${n}`,fcn_addQuoteToStack(a),fcn_showNotification(__('Quote appended to comment!<br><a style="font-weight: 700;" href="#comments">Go to comment section.</a>',"fictioneer"))}function fcn_addQuoteToStack(t){const e=_$$$("comment");e?(e.value+=`\n[quote]${t}[/quote]\n`,fcn_textareaAdjust(_$("textarea#comment"))):"undefined"!=typeof fcn_commentStack&&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=localStorage.getItem("fcnChapterFormatting");return t=t&&fcn_isValidJSONString(t)?JSON.parse(t):fcn_defaultFormatting(),(!t||"object"!=typeof t||Object.keys(t).length<15)&&(t=fcn_defaultFormatting()),(!t.hasOwnProperty("timestamp")||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_siteWidthDefault,indent:!0,"show-sensitive-content":!0,"show-chapter-notes":!0,justify:!1,"show-comments":!0,"show-paragraph-tools":!0,timestamp:1664797604825}}function fcn_setFormatting(t){"object"==typeof t&&(fcn_formatting=t,localStorage.setItem("fcnChapterFormatting",JSON.stringify(t)))}document.addEventListener("click",(t=>{fcn_paragraphTools?.closest("p")?.contains(t.target)||fcn_toggleParagraphTools(!1)})),fcn_paragraphTools&&(document.addEventListener("mousedown",(t=>{fcn_touchParagraph(t)})),_$$$("button-close-paragraph-tools").onclick=t=>{fcn_toggleParagraphTools(!1)},_$$$("button-get-link").onclick=t=>{fcn_copyToClipboard(`${location.host}${location.pathname}#${t.target.closest("p[data-paragraph-id]").id}`,__("Link copied to clipboard!","fictioneer"))},_$$$("button-comment-stack")?.addEventListener("click",(t=>{fcn_getQuote(t)})),_$$(".paragraph-tools__bookmark-colors > div").forEach((t=>{t.onclick=t=>{fcn_bookmarkColor=t.target.dataset.color}})),_$$$("button-set-bookmark")?.addEventListener("click",(t=>{fcn_toggleBookmark(t.target.closest("p[data-paragraph-id]").dataset.paragraphId,fcn_bookmarkColor),window.matchMedia("(min-width: 1024px)").matches&&fcn_toggleParagraphTools(!1),fcn_bookmarkColor="none"}))),_$$(".open-fullscreen").forEach((t=>{t.addEventListener("click",(()=>{fcn_openFullscreen()}))})),_$$(".close-fullscreen").forEach((t=>{t.addEventListener("click",(()=>{fcn_closeFullscreen()}))}));const fcn_fontSizeText=_$$$("reader-settings-font-size-text"),fcn_fontSizeRange=_$$$("reader-settings-font-size-range"),fcn_fontSizeReset=_$$$("reader-settings-font-size-reset");function fcn_updateFontSize(t,e=!0){t=fcn_clamp(50,200,t??100),fcn_fontSizeText.value=t,fcn_fontSizeRange.value=t,fcn_fontSizeReset.classList.toggle("_modified",100!=t),_$$(".resize-font").forEach((e=>{e.style.fontSize=`${t}%`})),fcn_formatting["font-size"]=t,e&&fcn_setFormatting(fcn_formatting)}function fcn_setFontSize(){fcn_updateFontSize(this.value)}function fcn_modifyFontSize(){fcn_updateFontSize(parseFloat(fcn_formatting["font-size"])+parseFloat(this.dataset.modifier))}_$$$("reset-font")?.addEventListener("click",(()=>{fcn_updateFontSize(100)})),fcn_fontSizeReset?.addEventListener("click",(()=>{fcn_updateFontSize(100)})),fcn_fontSizeRange?.addEventListener("input",fcn_throttle(fcn_setFontSize,1e3/24)),fcn_fontSizeText?.addEventListener("input",fcn_setFontSize),_$$$("increase-font")?.addEventListener("click",fcn_modifyFontSize),_$$$("decrease-font")?.addEventListener("click",fcn_modifyFontSize),fcn_updateFontSize(fcn_formatting["font-size"],!1);const fcn_fontColorReset=_$$$("reader-settings-font-color-reset"),fcn_fontColorSelect=_$$$("reader-settings-font-color-select");function fcn_updateFontColor(t,e=!0){t=fcn_clamp(0,fictioneer_font_colors.length-1,t),fcn_fontColorReset.classList.toggle("_modified",t>0),fcn_fontColorSelect.value=t,fcn_chapterFormatting.style.setProperty("--text-chapter",fictioneer_font_colors[t].css),fcn_formatting["font-color"]=fictioneer_font_colors[t].css,e&&fcn_setFormatting(fcn_formatting)}function fcn_setFontColor(t=1){let e=(fcn_fontColorSelect.selectedIndex+parseInt(t))%fictioneer_font_colors.length;e=e<0?fictioneer_font_colors.length-1:e,fcn_updateFontColor(e)}fcn_fontColorReset.onclick=()=>{fcn_updateFontColor(0)},fcn_fontColorSelect.onchange=t=>{fcn_updateFontColor(t.target.value)},_$$(".font-color-stepper").forEach((t=>{t.addEventListener("click",(t=>{fcn_setFontColor(t.currentTarget.value)}))})),fcn_updateFontColor(fictioneer_font_colors.findIndex((t=>t.css==fcn_formatting["font-color"])),!1);const fcn_fontFamilyReset=_$$$("reader-settings-font-reset"),fcn_fontFamilySelect=_$$$("reader-settings-font-select");function fcn_updateFontFamily(t,e=!0){t=fcn_clamp(0,fictioneer_fonts.length-1,t);let n=`"${fictioneer_fonts[t].css}"`;fictioneer_fonts[t].alt&&(n=`${n}, "${fictioneer_fonts[t].alt}"`),t<0?fcn_updateFontFamily(0):(fcn_fontFamilyReset.classList.toggle("_modified",t>0),fcn_fontFamilySelect.value=t,_$$(".chapter-font-family").forEach((t=>{t.style.fontFamily='""'===n?"var(--ff-system)":n+", var(--ff-system)"})),fcn_formatting["font-name"]=fictioneer_fonts[t].css,e&&fcn_setFormatting(fcn_formatting))}function fcn_setFontFamily(t=1){let e=(fcn_fontFamilySelect.selectedIndex+parseInt(t))%fictioneer_fonts.length;e=e<0?fictioneer_fonts.length-1:e,fcn_updateFontFamily(e)}fcn_fontFamilyReset.onclick=()=>{fcn_updateFontFamily(0)},fcn_fontFamilySelect.onchange=t=>{fcn_updateFontFamily(t.target.value)},_$$(".font-stepper").forEach((t=>{t.addEventListener("click",(t=>{fcn_setFontFamily(t.currentTarget.value)}))})),fcn_updateFontFamily(fictioneer_fonts.findIndex((t=>t.css==fcn_formatting["font-name"])),!1);const fcn_fontSaturationText=_$$$("reader-settings-font-saturation-text"),fcn_fontSaturationRange=_$$$("reader-settings-font-saturation-range"),fcn_fontSaturationReset=_$$$("reader-settings-font-saturation-reset");function fcn_updateFontSaturation(t,e=!0){t=fcn_clamp(-1,1,t??0),fcn_fontSaturationText.value=parseInt(100*t),fcn_fontSaturationRange.value=t,fcn_fontSaturationReset.classList.toggle("_modified",0!=t),fcn_chapterFormatting.style.setProperty("--font-saturation",t>=0?1+Math.pow(t,2):1-Math.pow(t,2)),fcn_formatting["font-saturation"]=t,e&&fcn_setFormatting(fcn_formatting)}function fcn_setFontSaturationFromRange(){fcn_updateFontSaturation(this.value)}function fcn_setFontSaturationFromText(){fcn_updateFontSaturation(parseInt(this.value)/100)}fcn_fontSaturationReset?.addEventListener("click",(()=>{fcn_updateFontSaturation(0)})),fcn_fontSaturationRange?.addEventListener("input",fcn_throttle(fcn_setFontSaturationFromRange,1e3/24)),fcn_fontSaturationText?.addEventListener("input",fcn_setFontSaturationFromText),fcn_updateFontSaturation(fcn_formatting["font-saturation"],!1);const fcn_letterSpacingText=_$$$("reader-settings-letter-spacing-text"),fcn_letterSpacingRange=_$$$("reader-settings-letter-spacing-range"),fcn_letterSpacingReset=_$$$("reader-settings-letter-spacing-reset");function fcn_updateLetterSpacing(t,e=!0){t=fcn_clamp(-.1,.2,t??0),fcn_letterSpacingText.value=t,fcn_letterSpacingRange.value=t,fcn_letterSpacingReset.classList.toggle("_modified",0!=t),fcn_chapterFormatting.style.letterSpacing=`calc(${t}em + var(--font-letter-spacing-base))`,fcn_formatting["letter-spacing"]=t,e&&fcn_setFormatting(fcn_formatting)}function fcn_setLetterSpacing(){fcn_updateLetterSpacing(this.value)}fcn_letterSpacingReset?.addEventListener("click",(()=>{fcn_updateLetterSpacing(0)})),fcn_letterSpacingRange?.addEventListener("input",fcn_throttle(fcn_setLetterSpacing,1e3/24)),fcn_letterSpacingText?.addEventListener("input",fcn_setLetterSpacing),fcn_updateLetterSpacing(fcn_formatting["letter-spacing"],!1);const fcn_paragraphSpacingText=_$$$("reader-settings-paragraph-spacing-text"),fcn_paragraphSpacingRange=_$$$("reader-settings-paragraph-spacing-range"),fcn_paragraphSpacingReset=_$$$("reader-settings-paragraph-spacing-reset");function fcn_updateParagraphSpacing(t,e=!0){t=fcn_clamp(0,3,t??1.5),fcn_paragraphSpacingText.value=t,fcn_paragraphSpacingRange.value=t,fcn_paragraphSpacingReset.classList.toggle("_modified",1.5!=t),fcn_chapterFormatting.style.setProperty("--paragraph-spacing",`${t}em`),fcn_formatting["paragraph-spacing"]=t,e&&fcn_setFormatting(fcn_formatting)}function fcn_setParagraphSpacing(){fcn_updateParagraphSpacing(this.value)}fcn_paragraphSpacingReset?.addEventListener("click",(()=>{fcn_updateParagraphSpacing(1.5)})),fcn_paragraphSpacingRange?.addEventListener("input",fcn_throttle(fcn_setParagraphSpacing,1e3/24)),fcn_paragraphSpacingText?.addEventListener("input",fcn_setParagraphSpacing),fcn_updateParagraphSpacing(fcn_formatting["paragraph-spacing"],!1);const fcn_lineHeightText=_$$$("reader-settings-line-height-text"),fcn_lineHeightRange=_$$$("reader-settings-line-height-range"),fcn_lineHeightReset=_$$$("reader-settings-line-height-reset");function fcn_updateLineHeight(t,e=!0){t=fcn_clamp(.8,3,t??1.7),fcn_lineHeightText.value=t,fcn_lineHeightRange.value=t,fcn_lineHeightReset.classList.toggle("_modified",1.7!=t),fcn_chapterFormatting.style.lineHeight=`${t}`,fcn_formatting["line-height"]=t,e&&fcn_setFormatting(fcn_formatting)}function fcn_setLineHeight(){fcn_updateLineHeight(this.value)}fcn_lineHeightReset?.addEventListener("click",(()=>{fcn_updateLineHeight(1.7)})),fcn_lineHeightRange?.addEventListener("input",fcn_throttle(fcn_setLineHeight,1e3/24)),fcn_lineHeightText?.addEventListener("input",fcn_setLineHeight),fcn_updateLineHeight(fcn_formatting["line-height"],!1);const fcn_siteWidthText=_$$$("reader-settings-site-width-text"),fcn_siteWidthRange=_$$$("reader-settings-site-width-range"),fcn_siteWidthReset=_$$$("reader-settings-site-width-reset");function fcn_updateSiteWidth(t,e=!0){const n=_$("main");t=fcn_clamp(640,1920,t??960),fcn_siteWidthText.value=t,fcn_siteWidthRange.value=t,fcn_siteWidthReset.classList.toggle("_modified",t!=fcn_siteWidthDefault),n.style.setProperty("--site-width",`${t}px`),n.classList.toggle("_default-width",t==fcn_theRoot.dataset.siteWidthDefault),n.classList.toggle("_below-1024",t<1024&&t>=768),n.classList.toggle("_below-768",t<768&&t>640),n.classList.toggle("_640-and-below",t<=640),fcn_formatting["site-width"]=t,e&&fcn_setFormatting(fcn_formatting)}function fcn_setSiteWidth(){fcn_updateSiteWidth(this.value)}function fcn_updateIndent(t,e=!0){const n=fcn_evaluateAsBoolean(t,!0),a=_$$$("reader-settings-indent-toggle");a&&(a.checked=n,a.closest("label").ariaChecked=n),fcn_chapterFormatting.classList.toggle("no-indent",!n),fcn_formatting.indent=n,e&&fcn_setFormatting(fcn_formatting)}function fcn_updateJustify(t,e=!0){const n=fcn_evaluateAsBoolean(t,!0),a=_$$$("reader-settings-justify-toggle");a&&(a.checked=n,a.closest("label").ariaChecked=n),fcn_chapterFormatting.classList.toggle("justify",n),fcn_formatting.justify=n,e&&fcn_setFormatting(fcn_formatting)}function fcn_updateParagraphTools(t,e=!0){const n=fcn_evaluateAsBoolean(t,!0),a=_$$$("reader-settings-paragraph-tools-toggle");a&&(a.checked=n,a.closest("label").ariaChecked=n),fcn_formatting["show-paragraph-tools"]=n,e&&fcn_setFormatting(fcn_formatting)}function fcn_updateSensitiveContent(t,e=!0){const n=fcn_evaluateAsBoolean(t,!0),a=_$$$("inline-sensitive-content-toggle"),c=_$$$("reader-settings-sensitive-content-toggle");c&&(c.checked=n,c.closest("label").ariaChecked=n),a&&(a.classList.toggle("hide-sensitive",!n),a.ariaChecked=!n),fcn_chapterFormatting.classList.toggle("hide-sensitive",!n),fcn_formatting["show-sensitive-content"]=n,e&&fcn_setFormatting(fcn_formatting)}function fcn_updateChapterNotes(t,e=!0){const n=fcn_evaluateAsBoolean(t,!0),a=_$$$("reader-settings-chapter-notes-toggle");a&&(a.checked=n,a.closest("label").ariaChecked=n),_$$("#chapter-foreword, #chapter-afterword, #chapter-warning").forEach((t=>{t.classList.toggle("hidden",!n)})),fcn_formatting["show-chapter-notes"]=n,e&&fcn_setFormatting(fcn_formatting)}function fcn_updateCommentSection(t,e=!0){const n=fcn_evaluateAsBoolean(t,!0),a=_$$$("reader-settings-comments-toggle");a&&(a.checked=n,a.closest("label").ariaChecked=n),_$$(".chapter__comments").forEach((t=>{t.classList.toggle("hidden",!n)})),fcn_formatting["show-comments"]=n,e&&fcn_setFormatting(fcn_formatting)}fcn_siteWidthReset?.addEventListener("click",(()=>{fcn_updateSiteWidth(fcn_siteWidthDefault)})),fcn_siteWidthRange?.addEventListener("input",fcn_throttle(fcn_setSiteWidth,1e3/24)),fcn_siteWidthText?.addEventListener("input",fcn_setSiteWidth),fcn_updateSiteWidth(fcn_formatting["site-width"],!1),_$$$("reader-settings-indent-toggle").onclick=t=>{fcn_updateIndent(t.currentTarget.checked)},fcn_updateIndent(fcn_formatting.indent,!1),_$$$("reader-settings-justify-toggle").onclick=t=>{fcn_updateJustify(t.currentTarget.checked)},fcn_updateJustify(fcn_formatting.justify,!1),_$$$("reader-settings-paragraph-tools-toggle").onclick=t=>{fcn_updateParagraphTools(t.currentTarget.checked)},fcn_updateParagraphTools(fcn_formatting["show-paragraph-tools"],!1),_$$$("reader-settings-sensitive-content-toggle").onclick=t=>{fcn_updateSensitiveContent(t.currentTarget.checked)},fcn_updateSensitiveContent(fcn_formatting["show-sensitive-content"],!1),_$$$("reader-settings-chapter-notes-toggle").onclick=t=>{fcn_updateChapterNotes(t.currentTarget.checked)},fcn_updateChapterNotes(fcn_formatting["show-chapter-notes"],!1),_$$$("reader-settings-comments-toggle").onclick=t=>{fcn_updateCommentSection(t.currentTarget.checked)},fcn_updateCommentSection(fcn_formatting["show-comments"],!1);const fcn_progressBar=_$(".progress__bar"),fcn_chapterContent=_$$$("chapter-content");var fcn_chapterCheckmarkUpdated=!1;function fcn_trackProgress(){fcn_chapterContent&&(fcn_readingProgress(),window.addEventListener("scroll.rAF",fcn_throttle(fcn_readingProgress,1e3/48)))}function fcn_readingProgress(){if(fcn_settingMinimal.checked||!fcn_settingChapterProgressBar.checked)return;const t=fcn_chapterContent.getBoundingClientRect(),e=t.height,n=window.innerHeight,a=e-t.bottom-Math.max(t.top,0)+n/2;let c=100*a/e;if(fcn_theBody.classList.toggle("hasProgressBar",!(c<0||a>e+500)),c=fcn_clamp(0,100,c),fcn_progressBar.style.width=`${c}%`,c>=100&&!fcn_chapterCheckmarkUpdated&&fcn_isLoggedIn){const t=_$$$("story-chapter-list");if(fcn_chapterCheckmarkUpdated=!0,!t||"function"!=typeof fcn_toggleCheckmark)return;fcn_toggleCheckmark(t.dataset.storyId,"progress",parseInt(fcn_inlineStorage.postId),null,"set")}}_$("article:not(._password)")&&fcn_trackProgress(),_$$$("chapter-list-popup-toggle")?.addEventListener("click",(()=>{_$('[data-target="popup-chapter-list"]')?.appendChild(fcn_chapterList.cloneNode(!0))}),{once:!0}),document.addEventListener("keydown",(t=>{"INPUT"===t.target.tagName||"TEXTAREA"===t.target.tagName||t.target.isContentEditable||("ArrowLeft"===t.code?_$("a.button._navigation._prev")?.click():"ArrowRight"===t.code&&_$("a.button._navigation._next")?.click())})); |