fictioneer/js/application.min.js

2 lines
39 KiB
JavaScript
Raw Permalink Normal View History

const FcnGlobals={eSite:_$$$("site"),urlParams:Object.fromEntries(new URLSearchParams(window.location.search).entries()),pageLoadTimestamp:Date.now(),ajaxLimitThreshold:Date.now()-parseInt(fictioneer_ajax.ttl),ajaxURL:fictioneer_ajax.ajax_url,restURL:fictioneer_ajax.rest_url,ffcnrURL:fictioneer_ajax.ffcnr_url,ffcnrAuth:fictioneer_ajax.ffcnr_auth,debounceRate:fictioneer_ajax.post_debounce_rate,ajaxAuth:document.documentElement.dataset.fictioneerAjaxAuthValue??!1,fonts:fictioneer_fonts??[],fontColors:fictioneer_font_colors??[],commentFormSelector:fictioneer_comments?.selector??"#comment",commentStack:[]};function fcn(){const e=window.FictioneerApp?.Controllers?.fictioneer;return e||{userData:FcnUtils.userData,setUserData:FcnUtils.setUserData,resetUserData:FcnUtils.resetUserData,removeUserData:FcnUtils.removeUserData}}function fcn_getUserData(){return FcnUtils.userData()}function fcn_setUserData(e){return FcnUtils.setUserData(e)}function fcn_cleanUpWebStorage(){["fcnBookshelfContent"].forEach((e=>localStorage.removeItem(e))),fcn().resetUserData()}function fcn_cleanUpGuestView(){document.body.classList.remove("logged-in","is-admin","is-moderator","is-editor","is-author"),_$$$("fictioneer-ajax-nonce")?.remove(),_$$(".only-moderators, .only-admins, .only-authors, .only-editors, .only-logged-in").forEach((e=>{e.remove()}))}function fcn_setLoggedInState(){const e=fcn().userData(),t=!0===e.loggedIn;document.body.classList.toggle("logged-in",t),document.body.classList.toggle("is-admin",e.isAdmin),document.body.classList.toggle("is-moderator",e.isModerator),document.body.classList.toggle("is-author",e.isAuthor),document.body.classList.toggle("is-editor",e.isEditor);const n=[];t&&(n.push('[data-fictioneer-id-param="login-modal"]'),n.push("#login-modal")),e.isAdmin||(n.push(".only-admins"),e.isModerator||n.push(".only-moderators"),e.isAuthor||n.push(".only-authors"),e.isEditor||n.push(".only-editors")),_$$(n.join(", ")).forEach((e=>e.remove()))}function fcn_setAvatar(){const e=fcn().userData()?.avatarUrl;e&&_$$('[data-fictioneer-target="avatarWrapper"]').forEach((t=>{const n=document.createElement("img");n.classList.add("user-profile-image"),n.src=e,t.firstChild.remove(),t.appendChild(n)}))}Object.freeze(FcnGlobals),window.FictioneerApp=window.FictioneerApp||{},window.FictioneerApp.Controllers=window.FictioneerApp.Controllers||{},application.register("fictioneer",class extends Stimulus.Controller{static get targets(){return["avatarWrapper","modal","mobileMenuToggle","dcjProtected"]}static values={fingerprint:String,ageConfirmation:{type:Boolean,default:!1},ajaxAuth:{type:Boolean,default:!1},ajaxSubmit:{type:Boolean,default:!1},cachingActive:{type:Boolean,default:!1},publicCaching:{type:Boolean,default:!1},forceChildTheme:{type:Boolean,default:!1},editTime:{type:Number,default:15}};userReady=!1;lastModalToggle=null;currentModal=null;dcjProtection=!0;initialize(){if(FcnUtils.loggedIn()||this.ajaxAuthValue)this.fetchUserData();else{fcn_cleanUpWebStorage();const e=new CustomEvent("fcnUserDataReady",{detail:{data:this.userData(),time:new Date,loggedOut:!0},bubbles:!0,cancelable:!1});document.dispatchEvent(e)}this.hasDcjProtectedTarget&&["mousemove","touchstart","keydown"].forEach((e=>{window.addEventListener(e,this.liftProtection.bind(this),{once:!0})}))}liftProtection(){this.dcjProtection&&this.hasDcjProtectedTarget&&(this.dcjProtectedTargets.forEach((e=>e.disabled=!1)),this.dcjProtection=!1)}connect(){window.FictioneerApp.Controllers.fictioneer=this}userData(){return FcnUtils.userData()}setUserData(e){FcnUtils.setUserData(e)}resetUserData(){FcnUtils.resetUserData()}removeUserData(){FcnUtils.removeUserData()}fetchUserData(){let e=this.userData();if(FcnUtils.loggedIn()&&!1===e.loggedIn&&(this.removeUserData(),e=this.userData()),(FcnGlobals.ajaxLimitThreshold<e.lastLoaded||!1===e.loggedIn)&&("pending"!==e.loggedIn||this.ajaxAuthValue)){const t=new CustomEvent("fcnUserDataReady",{detail:{data:e,time:new Date,cached:!0},bubbles:!e.loggedIn,cancelable:e.loggedIn});return fcn_setAvatar(),e.nonceHtml&&this.#e(e.nonceHtml),document.dispatchEven
2025-01-16 18:44:28 +01:00
_$$$("age-confirmation-confirm")?.addEventListener("click",(e=>{document.documentElement.classList.remove("age-modal-open"),e.currentTarget.closest(".modal").remove(),localStorage.setItem("fcnAgeConfirmation","1")})),t?.addEventListener("click",(()=>{window.location.href=t.dataset.redirect??"https://search.brave.com/",localStorage.removeItem("fcnAgeConfirmation")}))}_$$(".search-form").forEach((e=>{if(e.classList.contains("_simple"))return;const t=[];e.querySelectorAll(".keyword-input__input").forEach((e=>{t.push(new FCN_KeywordInput(e))})),e.querySelector(".allow-list")?.remove(),e.addEventListener("change",(t=>{t.target.classList.contains("search-form__advanced-control")||t.target.classList.contains("search-form__string")||(e.querySelector(".search-form__current").innerHTML="")})),e.querySelectorAll(".reset").forEach((n=>{n.addEventListener("click",(()=>{fcn_resetSearchForm(n,e,t)}))}))})),_$$(".search-form__advanced-toggle").forEach((e=>{e.addEventListener("click",(e=>{const t=e.currentTarget.closest("form");t.dataset.advanced="true"==t.dataset.advanced?"false":"true"}))})),window.addEventListener("keydown",fcn_handleTabInput),window.addEventListener("scroll.rAF",FcnUtils.throttle(fcn_popupPosition,250)),document.body.addEventListener("click",(e=>{const t=e.target.closest("[href]"),n=t?.getAttribute("href");if(!t||"A"===!t.tagName||!n.startsWith("#")||n.length<2||"#respond"===n)return;const s=n.replace("#",""),i=_$$(`[name="${s}"], [id="${s}"]`)[0],a=t.closest(".comment._story-comment");a&&(window.location.href=a.querySelector(".fictioneer-comment__link").href+n),i&&(e.preventDefault(),i.scrollIntoView({behavior:"smooth",block:t.dataset?.block??"start"}))})),fcn_markCurrentMenuItem(),_$$$("age-confirmation-modal")&&"1"!==localStorage.getItem("fcnAgeConfirmation")&&!FcnUtils.isSearchEngineCrawler()?fcn_showAgeConfirmationModal():_$$$("age-confirmation-modal")?.remove(),document.addEventListener("DOMContentLoaded",(()=>{_$$(".splide:not(.no-auto-splide, .is-initialized)").forEach((e=>{e.querySelector(".splide__list")&&"undefined"!=typeof Splide&&(e.classList.remove("_splide-placeholder"),new Splide(e).mount())})),_$$(".temp-script, .splide-placeholder-styles").forEach((e=>{e.remove()}))})),application.register("fictioneer-large-card",class extends Stimulus.Controller{static get targets(){return["controls","menu"]}static values={postId:Number,storyId:Number};initialize(){fcn()?.userReady?this.#n=!0:document.addEventListener("fcnUserDataReady",(()=>{this.#s(),this.#n=!0,this.#i()}))}connect(){if(window.FictioneerApp.Controllers.fictioneerLargeCard=this,this.#n&&(this.#s(),this.#i()),document.addEventListener("click",(e=>{e.target.closest(`.card.post-${this.postIdValue}`)||this.#a()})),document.addEventListener("toggledLastClick",(e=>{this.#o(e.detail.target,e.detail.force)})),this.hasMenuTarget)for(this.menuFragment=document.createDocumentFragment();this.menuTarget.firstChild;)this.menuFragment.appendChild(this.menuTarget.firstChild)}disconnect(){this.#c()}isFollowed(){return!(!this.#r()||!this.#l()?.follows?.data?.[this.storyIdValue])}isRemembered(){return!(!this.#r()||!this.#l()?.reminders?.data?.[this.storyIdValue])}isRead(){if(!this.#r())return!1;const e=this.#l()?.checkmarks?.data?.[this.storyIdValue];return!!e&&(e.includes(this.postIdValue)||e.includes(this.storyIdValue))}cardClick(e){e.target.closest(".card__controls")||this.#d()}toggleMenu(){this.menuTarget.querySelector("*")?this.#d():this.#u()}toggleFollow(){this.#r()?(fcn_toggleFollow(this.storyIdValue,!this.isFollowed()),this.#h()):_$('[data-fictioneer-id-param="login-modal"]')?.click()}toggleReminder(){this.#r()?(fcn_toggleReminder(this.storyIdValue,!this.isRemembered()),this.#g()):_$('[data-fictioneer-id-param="login-modal"]')?.click()}toggleCheckmarks(){this.#r()?(fcn_toggleCheckmark(this.storyIdValue,this.postIdValue),this.#f()):_$('[data-fictioneer-id-param="login-modal"]')?.click()}setCheckmarks(e){this.toggleCheckmarks("set",e.params?.type??"story")}unsetCheckmarks(e){this.toggleCheckmarks("unset",e.params?.type??"story")}#m=!1;#n=!1;#_=!1;#r(){const e