Newer
Older
anicusi / js / dist / all.min.js
@Eugene Eugene on 11 Apr 32 KB init
class Alert{constructor(e,t,A,a){this.id="alert-id-"+(new Date).getTime()+Math.random(),(alertsList[this.id]=this).type=e,this.content=t||"",this.isSingleton=A||!1,this.isClosable=a||!1;e=document.querySelector('.component.alert[data-id="alert-id-reference"]');if(!e)return console.error("Reference of alert component not found");this.template=e.cloneNode(!0),this.template.getInstance=()=>this,this.initComponent()}initComponent(){this.template.classList.add("alert-"+this.type),this.template.setAttribute("data-id",this.id),this.template.querySelector(".content").innerHTML=this.content,this.template.querySelector(".close-alert").addEventListener("click",e=>{e.preventDefault(),this.close()})}showIn(e){return!!this.template&&(this.isSingleton&&(e.innerHTML=""),e.append(this.template),setTimeout(()=>{this.template.classList.add("show")},10),this)}close(){this.template.classList.remove("show"),setTimeout(()=>{this.template.remove(),delete alertsList[this.id]},150)}changeContent(e){this.template.querySelector(".content").innerHTML=e}}const closeAlertComponent=e=>alertsList[e]?.close(),createAlertComponent=(e,t,A,a)=>new Alert(e,t,A,a),createGlobalAlertComponent=(e,t,A,a)=>{e=createAlertComponent(e,t,A,a);return e.showIn(document.querySelector(".global-alerts-container")),e},alertsList=(document.addEventListener("DOMContentLoaded",e=>{document.querySelectorAll(".component.alert .close-alert").forEach(e=>{e.addEventListener("click",e=>{e.preventDefault();e=e.currentTarget.getAttribute("data-close-alert-id");closeAlertComponent(e)})})}),{});class App{constructor(){this.router=new Router(".page-container","home","not-found"),this.auth=new Auth("#login .login-form form"),this.renderer=new Renderer,this.postRender=new PostRender,this.loader=new Loader,this.cacheProvider=new CacheProvider,this.storedPlayerDataManager=new StoredPlayerDataManager,this.sync=new Sync,setTimeout(()=>{this.init()},10)}init(){initers(this),this.router.urlMonitor(),this.initDisplayingAuthBtns(),this.initPreloadSpinner(),this.initBaseEvents(),this.initGenres(),this.initGoToTopBtn(),this.initNightMode()}initNightMode(){var e=(new Date).getHours();e<=8||20<=e?document.querySelector("body").classList.add("night-mode"):document.querySelector("body").classList.remove("night-mode"),setTimeout(()=>this.initNightMode(),6e4)}initPreloadSpinner(){document.querySelectorAll(".preload-spinner").forEach(e=>{e.innerHTML=this.renderer.renderPreloadSpinner()})}initBaseEvents(){document.querySelector(".logout-btn").addEventListener("click",e=>{this.auth.logout()}),document.querySelector(".btn-nav-on-mob-show").addEventListener("click",e=>{(e.currentTarget.classList.contains("active")?hideMobNav:showMobNav)()}),document.querySelector('[name="search"]').addEventListener("keyup",e=>{var t;e.preventDefault(),13==e.keyCode&&(t=e.currentTarget.value.trim(),document.location.hash="page:search;sq:"+t,e.currentTarget.blur())});const s={home:this.loader.homePageUpToLoad,search:this.loader.searchPageUpToLoad,genres:this.loader.genresPageUpToLoad};for(let a in s){const r=document.querySelector("#"+a);r.querySelector(".more-btn").addEventListener("click",e=>{const t=r.querySelector(".render-container");var A=Math.ceil(t.childNodes.length/_CONF.perPage[a])+1;r.querySelector(".more-btn-wrap .preload-spinner").classList.remove("dnone"),r.querySelector(".more-btn").classList.add("dnone"),s[a](A,e=>{r.querySelector(".more-btn-wrap .preload-spinner").classList.add("dnone"),e.list.length&&r.querySelector(".more-btn").classList.remove("dnone"),insertListToRenderContainer(t,e.list)})})}}initGenres(){this.loader.genresList(e=>{document.querySelector("#genres .render-genres").appendChild(this.renderer.renderGenresList(e).node)})}initDisplayingAuthBtns(){getSessionId()?(document.querySelector(".logout-btn").classList.remove("dnone"),document.querySelector(".go-login-page-btn").classList.add("dnone")):(document.querySelector(".logout-btn").classList.add("dnone"),document.querySelector(".go-login-page-btn").classList.remove("dnone"))}initGoToTopBtn(){const e=document.querySelector(".go-to-top"),t=()=>{500<window.pageYOffset?e.classList.contains("show")||e.classList.add("show"):e.classList.contains("show")&&e.classList.remove("show")};t(),window.addEventListener("scroll",e=>{t()}),e.addEventListener("click",e=>{const t=Math.round(window.pageYOffset/50),A=setInterval(()=>{var e=Math.max(0,window.pageYOffset-t);if(window.scrollTo({top:e}),!e)return clearInterval(A)},1)})}}document.addEventListener("DOMContentLoaded",e=>{const t=new App;window.app=()=>t});class Auth{constructor(e){this.formSelector=e,this.form=document.querySelector(this.formSelector),this.submitBtn=this.form.querySelector(".submit-btn"),this.initForm()}initForm(){this.form.addEventListener("submit",e=>{if(e.preventDefault(),!this.submitBtn.classList.contains("disable")){this.submitBtn.classList.add("disable");const s=this.form.querySelector("#email").value;e=this.form.querySelector("#passwd").value;const r=new XMLHttpRequest;r.open("POST","https://www.anilibria.tv/public/login.php"),r.onload=()=>{if(this.submitBtn.classList.remove("disable"),200==r.status){var e=JSON.parse(r.response);if("ok"==e.err){localStorage.setItem("sessionId",e.sessionId),localStorage.setItem("uemail",s);const t=createGlobalAlertComponent("success","Успешно!");setTimeout(()=>{t.close()},2e3),document.location.hash="#",document.querySelector(".logout-btn").classList.remove("dnone"),document.querySelector(".go-login-page-btn").classList.add("dnone")}else{const A=createGlobalAlertComponent("danger",e.mes);setTimeout(()=>{A.close()},4500)}}else{const a=createGlobalAlertComponent("danger","Сервер не доступен");setTimeout(()=>{a.close()},4500)}};var t=new FormData;t.append("mail",s),t.append("passwd",e),t.append("fa2code",""),t.append("csrf","1"),r.send(t)}})}logout(){localStorage.removeItem("sessionId"),document.location.hash="#page:login",document.querySelector(".logout-btn").classList.add("dnone"),document.querySelector(".go-login-page-btn").classList.remove("dnone"),app().cacheProvider.unsetCache("favouritesList")}}class CacheProvider{constructor(){this.cache={},this.lifetime={},this.createAt={},this.init(),setInterval(()=>{this.manager()},1e3)}init(){var e=localStorage.getItem("cache");e&&(e=JSON.parse(e),this.cache=e.cache,this.lifetime=e.lifetime,this.createAt=e.createAt)}setCache(e,t,A){this.cache[e]=t,this.lifetime[e]=A,this.createAt[e]=Math.round((new Date).getTime()/1e3),this.saveCache()}saveCache(){localStorage.setItem("cache",JSON.stringify({cache:this.cache,lifetime:this.lifetime,createAt:this.createAt}))}cacheable(t,e,A,a){if(this.cache[t])return A(this.cache[t]);e(e=>{this.setCache(t,e,a),A(e)})}unsetCache(e){this.cache[e]&&(delete this.cache[e],delete this.lifetime[e],delete this.createAt[e],this.saveCache())}manager(){var e,t=Math.round((new Date).getTime()/1e3);for(e in this.cache)this.lifetime[e]&&t-this.createAt[e]>this.lifetime[e]&&this.unsetCache(e)}}class Loader{constructor(){}homePageUpToLoad(e,t){anilibriaRequest("title/updates",{page:e,items_per_page:_CONF.perPage.home,filter:getItemCardFields()},e=>t(e))}searchPageUpToLoad(e,t){var A=decodeURI(document.location.hash.split("sq:")[1]);anilibriaRequest("title/search",{page:e,items_per_page:_CONF.perPage.search,filter:getItemCardFields(),search:A},e=>t(e))}genresPageUpToLoad(e,t){var A=getSelectedGenres();anilibriaRequest("title/search",{search:"",filter:getItemCardFields(),genres:A.join(","),page:e,items_per_page:_CONF.perPage.search},e=>t(e))}favouritesList(e){const A=getSessionId();if(!A)return setTimeout(()=>document.location.hash="#page:login",20);app().cacheProvider.cacheable("favouritesList",t=>{anilibriaRequest("v2.13:getFavorites",{session:A,limit:1e3,filter:getItemCardFields(!0)},e=>t(e))},e,300)}genresList(e){app().cacheProvider.cacheable("genresList",t=>{anilibriaRequest("genres",{sorting_type:1},e=>t(e))},e,10800)}scheduleList(e){app().cacheProvider.cacheable("scheduleList",e=>{anilibriaRequest("title/schedule",{filter:getItemCardFields()},e)},e,10800)}}class PostRender{constructor(){}itemCard(e){e=nodeFromHTML(e);return e.querySelector(".thumbnail-img").addEventListener("load",e=>{e.currentTarget.parentNode.parentNode.classList.add("load-ready")}),e}single(e,t){var A,e=nodeFromHTML(e),a=this.tabs(app().renderer.renderTabs({name:"video",tabs:{"player-container":{btn:'<span class="mdi mdi-television-play"></span> Смотреть',content:`<div class="player" id="main-player-${t.id}"></div>`},"torrents-container":{btn:'<span class="mdi mdi-download"></span> Скачать',content:app().renderer.renderTorrents(t)}},active:"player-container"}));e.querySelector(".video-container").appendChild(a);const s={id:"main-player-"+t.id,default_quality:"720p",preroll_deny:"",file:[]};for(A in t.player.list){let e="[480p]https://"+t.player.host+t.player.list[A].hls.sd;t.player.list[A].hls.hd&&(e+=",[720p]https://"+t.player.host+t.player.list[A].hls.hd),t.player.list[A].hls.fhd&&(e+=",[1080p]https://"+t.player.host+t.player.list[A].hls.fhd),s.file.push({id:"s"+A,skip:t.player.list[A].skips.opening.length?t.player.list[A].skips.opening.join("-"):null,title:"Серия "+A,poster:t.player.list[A].preview?"//"+_CONF.domen+t.player.list[A].preview:null,download:null,file:e})}return setTimeout(()=>{new Playerjs(s);playerPatch(s.id)},30),e.querySelector(".fav-btn-wrap").appendChild(app().renderer.renderFavoriteBtn(t).node),e.querySelector(".thumbnail-img").addEventListener("load",e=>{e.currentTarget.parentNode.classList.add("load-ready")}),e}favoriteBtn(e,A){const a=nodeFromHTML(e);return getSessionId()&&(a.querySelector(".state.unset-from").classList.add("dnone"),a.querySelector(".state.set-to").classList.remove("dnone"),app().loader.favouritesList(t=>{for(let e=0;e<t.length;e++)if(A==t[e].id){a.querySelector(".state.unset-from").classList.remove("dnone"),a.querySelector(".state.set-to").classList.add("dnone");break}a.classList.remove("dnone")}),a.addEventListener("click",e=>{e.currentTarget.querySelector(".unset-from").classList.contains("dnone")?addToFavourites(A,e=>{a.querySelector(".state.unset-from").classList.remove("dnone"),a.querySelector(".state.set-to").classList.add("dnone")}):removeFromFavourites(A,e=>{a.querySelector(".state.unset-from").classList.add("dnone"),a.querySelector(".state.set-to").classList.remove("dnone")})})),a}genreBtn(e){e=nodeFromHTML(e);return e.addEventListener("click",e=>{e.preventDefault();var t=e.currentTarget.getAttribute("data-genre-name");let A=document.location.hash.split("sg:")[1];var a=(A=A?A.split(",").map(e=>decodeURI(e)):[]).indexOf(t);-1===a?(A.push(t),e.currentTarget.classList.add("active")):(A.splice(a,1),e.currentTarget.classList.remove("active")),document.location.hash="page:genres;sg:"+A.join(",")}),e}tabs(e){const A=nodeFromHTML(e);return A.querySelectorAll(".tabs-nav .tab").forEach(e=>{e.addEventListener("click",e=>{A.querySelector(".tabs-nav .tab.active").classList.remove("active"),A.querySelector(".tabs-content .tab-content.active").classList.remove("active");var t=e.currentTarget.getAttribute("data-tab");e.currentTarget.classList.add("active"),A.querySelector(`.tab-content[data-tab="${t}"]`).classList.add("active")})}),A}}class Renderer{constructor(){}renderThumbnail(e){let t=e.status.string||"Завершен";e.inSchedule&&(t=e.inSchedule.isToday?'<span class="mdi mdi-flag-checkered"></span> Сегодня':'<span class="mdi mdi-flag-checkered"></span> '+(e.inSchedule.string.charAt(0).toUpperCase()+e.inSchedule.string.slice(1)));var A=e.localPlayerData&&e.localPlayerData.currentEpisode==e.player.episodes.last?'<div class="thumb-label watched">Просмотрено</div>':"";return`
			<div class="component thumbnail">
				<img src="http://anilibria.tv${e.posters.medium.url}" class="thumbnail-img">
				<img 
					src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAH0AV4DASIAAhEBAxEB/8QAHAABAQACAwEBAAAAAAAAAAAAAAcDBgECBQgE/8QANhABAAIBAwIDBgQFAwUAAAAAAAECAwQFEQYhEjFBB1FhgZGhExQVcSJCUnKxIzLBJGKCwuH/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8AmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/9k=" 
					class="poster-placeholder"
				>
				<div class="hover-effect">
					<span class="mdi mdi-arrow-right"></span>
				</div>
				${A}
				<div class="thumb-label status">${t}</div>
				<div class="thumb-label series">Серий ${e.player.episodes.last}</div>
			</div>
		`}renderItemCard(e){var t=e.genres.join(", "),A=this.renderThumbnail(e),A=`<a href="#page:single;id${e.id}" class="no-decoration item-link">
			<div class="component card item-card" data-id="${e.id}">
				${A}
				<div class="info">
					<div class="title">${e.names.ru} (<span class="year">${e.season.year}</span>)</div>
					<div class="meta">
						<div class="genres">${t}</div>
						<div class="type">${e.type.full_string}</div>
					</div>
				</div>
			</div>
		</a>`;return{string:A,node:app().postRender.itemCard(A)}}renderTorrents(A){let a='<div class="component torrents">';for(let t=0;t<A.torrents.list.length;t++){var s=A.torrents.list[t];let e=s.total_size/1024/1024;e=1024<e?(e/1024).toString().split(".")[0]+"."+(e/1024).toString().split(".")[1].substr(0,2)+" ГБ":e.toString().split(".")[0]+"."+e.toString().split(".")[1].substr(0,2)+" МБ",a+=`
				<div class="torrent" data-torrent-id="${s.torrent_id}">
					<div class="series">Серии ${s.episodes.string}</div>
					<div class="quality">${s.quality.string}</div>
					
					<div class="seed-leech">
						<span class="seed">
							<span class="mdi mdi-arrow-up"></span>
							${s.seeders}
						</span>
						<span class="leech">
							<span class="mdi mdi-arrow-down"></span>
							${s.leechers}
						</span>
					</div>
					<div class="download">
						<a href="http://anilibria.tv${s.url}" class="std-btn btn-success" target="_blank">
							<span class="mdi mdi-download"></span>
							<span class="btn-label">Скачать</span>
							<span class="btn-tsize">${e}</span>
						</a>
					</div>
				</div>
			`}return a+="</div>"}renderFavoriteBtn(e){var t=`<button class="std-btn btn-warning fav-btn dnone" data-id="${e.id}">
			<span class="state unset-from">
				<span class="mdi mdi-star"></span>
				В избранном
			</span>
			<span class="state set-to">
				<span class="mdi mdi-star-outline"></span>
				Добавить в избранное
			</span>
		</button>`;return{html:t,node:app().postRender.favoriteBtn(t,e.id)}}renderTabs(e){let t='<div class="tabs-nav">',A='<div class="tabs-content">';for(var a in e.tabs){var s=e.active==a?"active":"";t+=`<div class="tab ${s}" data-tab="${a}">${e.tabs[a].btn}</div>`,A+=`<div class="tab-content ${a} ${s}" data-tab="${a}">${e.tabs[a].content}</div>`}return t+="</div>",A+="</div>",`<div class="component tabs ${e.name}" id="${e.name}">
			${t}
			${A}
		</div>`}renderSingle(e){var t=this.renderGenresList(e.genres).html,A=this.renderThumbnail(e),a=e.team.voice.join(", "),s=e.inSchedule?`<div class=""><span class="mdi mdi-flag-checkered"></span> Новая серия: ${e.inSchedule.isToday?"сегодня":e.inSchedule.string}</div>`:"",A=`<div class="component single-item">
			<div class="std-row">
				${A}
				<div class="item-info">
					<h2 class="title"><strong>${e.names.ru}</strong> / ${e.names.en}</h2>
					<div class="time-period">${e.season.string||""} ${e.season.year}</div>
					<div class="genres">${t}</div>
					<div class="type">${e.type.full_string}</div>
					${s}
					<div class="team">
						<div class="voice">
							<strong>Голоса:</strong>
							${a}
						</div>
					</div>
					<div class="description">${e.description}</div>
					<div class="control-panel">
						<div class="fav-btn-wrap"></div>
					</div>
				</div>
			</div>

			<div class="video-container"></div>
		</div>`;return{string:A,node:app().postRender.single(A,e)}}renderPreloadSpinner(){return`<div class="loadingio-spinner-dual-ball-9pyhqeozhs"><div class="ldio-jyt13pqa73">
			<div></div><div></div><div></div>
			</div></div>`}renderGenreBtn(e){e=`<a 
			href="#page:genres;sg:${e}" 
			class="std-btn genre-btn" 
			data-genre-name="${e}"
		>
			${e}
		</a>`;return{html:e,node:app().postRender.genreBtn(e)}}renderGenresList(t){var A=document.createElement("DIV");A.classList.add("genres-wrap");let a='<div class="genres-wrap">';for(let e=0;e<t.length;e++){var s=this.renderGenreBtn(t[e]);A.appendChild(s.node),a+=s.html}return{html:a+="</div>",node:A}}}class Router{constructor(e,t,A){this.containerSelector=e,this.container=document.querySelector(this.containerSelector),this.defaultPageId=t,this.notFoundPageId=A,this.initers={};var a=this.container.querySelectorAll(".page[id]");this.pages={};for(let e=0;e<a.length;e++)this.pages[a[e].getAttribute("id")]=a[e];this.currentPage="default-val",this.currentPath="default-val",this.zindex=1}goToPage(e){return void 0===e?document.location.hash="page:"+this.defaultPageId:void 0===this.pages[e]?this.goToPage(this.notFoundPageId):(this.container.querySelectorAll(".page.show").forEach(e=>e.classList.remove("show")),void 0!==this.pages[e]&&(this.initers._page&&this.initers._page(this,e),this.initers[e]&&this.initers[e](this),this.pages[e].style.zIndex=this.zindex,this.zindex++),this.pages[e]?.classList.add("show"),window.scrollTo({top:0}),this.currentPage=e,void(this.currentPath=document.location.hash))}urlMonitor(){setInterval(()=>{var e=document.location.hash.split("page:")[1];document.location.hash!=this.currentPath&&this.goToPage(e?.split(";")[0])},10)}initPage(e,t){this.initers[e]=t}}class StoredPlayerDataManager{constructor(){this.localStorageItemName="player_data_backup",this.restorePlayerDataFromBackup(),this.cleanupBackupedPlayerData(),setInterval(()=>{this.backupPlayerData()},3e3),setInterval(()=>{this.cleanupBackupedPlayerData()},3e5)}backupPlayerData(e){var t,A=e||getStorablePlayerData(),a=this.getBackupedPlayerData();for(t in A)a[t]?(a[t].currentEpisode=A[t].currentEpisode,a[t].timing.watched=A[t].timing.watched,a[t].timing.len=A[t].timing.len):a[t]=A[t];localStorage.setItem(this.localStorageItemName,JSON.stringify(a))}getBackupedPlayerData(){var e=localStorage.getItem(this.localStorageItemName);return e?JSON.parse(e):{}}restorePlayerDataFromBackup(){var e,t=this.getBackupedPlayerData(),A=document.location.host+document.location.pathname,a=(new Date).getTime();for(e in t){var s=t[e].currentEpisode,r=t[e].timing.watched,n=t[e].timing.len||0;localStorage.setItem("pljsplayfrom_main-player-"+e+A,`{x-${s-1}-s${s}}${r}.0--${n}.0--`+a)}}cleanupBackupedPlayerData(){var e,t=this.getBackupedPlayerData();if(Object.keys(t).length<=300)return!1;let A=-1,a=Number.MAX_VALUE;for(e in t)t[e].timing.watchedAt<a&&(A=e,a=t[e].timing.watchedAt);t[A]&&delete t[A],localStorage.setItem(this.localStorageItemName,JSON.stringify(t))}}class Sync{constructor(){this.errFlag=!1,this.sync(),setInterval(()=>this.sync(),3e4)}sync(){const s=localStorage.getItem("uemail");var e;!this.errFlag&&getSessionId()&&s?(console.log("sync start"),(e=stdXHR("GET",_CONF.sync.url+("?uemail="+s),e=>{var t,A=JSON.parse(e.response).result,a=(A.uemail!=s&&console.error(`User like a "${$uemail}" not found`),app().storedPlayerDataManager.getBackupedPlayerData());for(t in A.data)(!a[t]||A.data[t].timing.watchedAt>a[t].timing.watchedAt)&&(a[t]=A.data[t]);app().storedPlayerDataManager.backupPlayerData(a),app().storedPlayerDataManager.restorePlayerDataFromBackup(),this.push()})).onerror=()=>{},e.send()):this.errFlag=!0}push(){var e,t=localStorage.getItem("uemail");getSessionId()&&t?((e=new FormData).append("uemail",t),e.append("data",JSON.stringify(app().storedPlayerDataManager.getBackupedPlayerData())),(t=stdXHR("POST",_CONF.sync.url,e=>{console.log("finished")})).onerror=()=>{},t.send(e)):this.errFlag=!0}}const _CONF={domen:"anilibria.tv",api:{domen:"api.anilibria.tv",ver:"v3"},perPage:{home:20,search:80,genres:80},numbOfRelevant:12,sync:{url:"//192.168.0.100/anilibria-cusi/sync/sync.php"}},getSessionId=()=>{var e=localStorage.getItem("sessionId");return e||!1},stdXHR=(e,t,A)=>{const a=new XMLHttpRequest;return a.open(e,t),a.setRequestHeader("Cache-Control","no-cache, no-store, max-age=0"),a.onload=()=>{if(200==a.status)A(a);else{404==a.status&&app().router.goToPage("not-found");const e=createGlobalAlertComponent("danger","Ошибка загрузки данных");setTimeout(()=>e.close(),3e3)}},a.onerror=()=>{const e=createGlobalAlertComponent("danger","Сервер не доступен");setTimeout(()=>e.close(),3e3)},a},showMobNav=()=>{document.querySelector(".btn-nav-on-mob-show").classList.add("active"),document.querySelectorAll(".navigation-main-wrapper, .userbar-wrapper").forEach(e=>{e.classList.add("show")})},hideMobNav=()=>{document.querySelector(".btn-nav-on-mob-show").classList.remove("active"),document.querySelectorAll(".navigation-main-wrapper, .userbar-wrapper").forEach(e=>{e.classList.remove("show")})},makeSelectedGenresActivated=()=>{let t=document.location.hash.split("sg:")[1];t=t?t.split(",").map(e=>decodeURI(e)):[],document.querySelectorAll("#genres .render-genres .genre-btn.active").forEach(e=>e.classList.remove("active"));for(let e=0;e<t.length;e++)document.querySelector(`#genres .render-genres .genre-btn[data-genre-name="${t[e]}"]`)?.classList.add("active")},getItemCardFields=e=>!0===e?["id","code","names","genres","posters","status","player","season","type"]:["id","code","names","genres","posters.medium.url","status","player.episodes","season","type"],setPageTitle=e=>{document.querySelector("head title").innerHTML=e},nodeFromHTML=e=>{var t=document.createElement("DIV");return t.innerHTML=e,item=t.childNodes[0]},addToFavourites=(e,t)=>{var A=getSessionId();A&&anilibriaRequest("user/favorites",{session:A,title_id:e},e=>{app().cacheProvider.unsetCache("favouritesList"),t(e)},"PUT")},removeFromFavourites=(e,t)=>{var A=getSessionId();A&&anilibriaRequest("user/favorites",{session:A,title_id:e},e=>{app().cacheProvider.unsetCache("favouritesList"),t(e)},"DELETE")},insertListToRenderContainer=(t,A)=>{for(let e=0;e<A.length;e++)t.appendChild(app().renderer.renderItemCard(A[e]).node)},anilibriaRequest=(e,t,A,a)=>{t=t||{},a=a||"GET";let s=_CONF.api.ver,r=(-1!=e.indexOf(":")&&([s,e]=e.split(":")),`https://${_CONF.api.domen}/api/${s}/`+e);t.filter&&(t.filter=t.filter.join(",")),0===t.after&&delete t.after;e=new URLSearchParams(t).toString();e&&(r+="?"+e),stdXHR(a,r,e=>{e=JSON.parse(e.response);A(e)}).send()},getSelectedGenres=()=>{var e=document.location.hash.split("sg:")[1];return(e=decodeURI(e)).length?e.split(","):[]},getStorablePlayerData=()=>{var e,t,A,a={};for(e of Object.keys(localStorage))-1!=e.indexOf("pljsplayfrom_main-player-")&&(t=parseInt(e.split("pljsplayfrom_main-player-")[1].replaceAll(document.location.hostname,"")),A=localStorage.getItem(e),[watched,len,watchedAt]=A.split("}")[1].split("--"),a[t]={currentEpisode:A.split("}")[0].split("s")[1],timing:{watched:parseInt(watched),len:parseInt(len),watchedAt:watchedAt}});return a},transformScheduleList=e=>{var t,A={},a=(new Date).getDay(),s=["понедельник","вторник","среда","четверг","пятница","суббота","воскресенье"];for(t in e)for(var r in e[t].list)A[e[t].list[r].id]||(A[e[t].list[r].id]={day:{num:e[t].day,string:s[e[t].day],isToday:e[t].day==a-1},item:e[t].list[r]});return A},initers=n=>{n.router.initPage("_page",(e,t)=>{document.querySelectorAll("#single .render-container").forEach(e=>{e.innerHTML=""}),document.querySelector(`#${t} .preload-spinner`)?.classList.remove("dnone"),document.querySelector('[name="search"]').value="",document.querySelectorAll(".page .more-btn").forEach(e=>e.classList.add("dnone")),hideMobNav();t=document.querySelector("#"+t)?.getAttribute("data-title");setPageTitle(t)}),n.router.initPage("login",e=>{getSessionId()&&(document.location.hash="page:"+e.notFoundPageId)}),n.router.initPage("home",e=>{n.loader.homePageUpToLoad(1,e=>{var t=document.querySelector("#home .render-container"),A=document.querySelector("#home .preload-spinner");t.innerHTML="",A.classList.add("dnone"),e.list.length&&document.querySelector(".more-btn").classList.remove("dnone"),e.pagination.current_page==e.pagination.pages&&A.classList.add("dnone"),insertListToRenderContainer(t,e.list)})}),n.router.initPage("single",e=>{const r=document.location.hash.split("id")[1];anilibriaRequest("title",{id:r,include:"raw_poster"},t=>{setPageTitle(t.names.ru);const s=t.genres,A=document.querySelector("#single .render-container.main-render");n.loader.scheduleList(e=>{e=transformScheduleList(e),t.inSchedule=!!e[t.id]&&e[t.id].day,A.innerHTML="",document.querySelector("#single .preload-spinner").classList.add("dnone"),A.appendChild(n.renderer.renderSingle(t).node)});t.names.ru,getItemCardFields().join(",");n.cacheProvider.cacheable("relatedTitles_id"+t.id,e=>{anilibriaRequest("title/search",{search:t.names.ru,after:0,limit:_CONF.numbOfRelevant,filter:getItemCardFields()},e)},e=>{e.list.splice(_CONF.numbOfRelevant,e.list.length);const A=e.list.map(e=>e.id),a=document.querySelector("#single .render-container.relevant-items-render");a.innerHTML="",insertListToRenderContainer(a,e.list.filter(e=>e.id!=r)),0<_CONF.numbOfRelevant-a.childNodes.length&&n.cacheProvider.cacheable("additionRelatedTitles_id"+r,e=>{anilibriaRequest("title/search",{search:"",genres:s.splice(0,4).join(","),after:0,limit:_CONF.numbOfRelevant+1,filter:getItemCardFields()},e)},t=>{t.list=t.list.filter(e=>e.id!=r);for(let e=0;e<t.list.length;e++){if(a.childNodes.length>=_CONF.numbOfRelevant)return!1;-1<A.indexOf(t.list[e].id)||a.appendChild(n.renderer.renderItemCard(t.list[e]).node)}},10800)},10800)})}),n.router.initPage("favourites",e=>{n.loader.favouritesList(A=>{const a=document.querySelector("#favourites .render-container");document.querySelector("#favourites .preload-spinner").classList.add("dnone"),a.innerHTML="",n.loader.scheduleList(t=>{t=transformScheduleList(t);for(let e=A.length-1;0<=e;e--)A[e].player.episodes=A[e].player.series,A[e].inSchedule=!!t[A[e].id]&&t[A[e].id].day,a.appendChild(n.renderer.renderItemCard(A[e]).node)})})}),n.router.initPage("search",e=>{var t=decodeURI(document.location.hash.split("sq:")[1]);document.querySelector('[name="search"]').value=t,n.loader.searchPageUpToLoad(1,e=>{var t=document.querySelector("#search .render-container"),A=document.querySelector("#search .more-btn");t.innerHTML="",document.querySelector("#search .preload-spinner").classList.add("dnone"),e.list.length&&A.classList.remove("dnone"),e.pagination.current_page==e.pagination.pages&&A.classList.add("dnone"),insertListToRenderContainer(t,e.list)})}),n.router.initPage("new-series",e=>{n.cacheProvider.cacheable("new-series",e=>{anilibriaRequest("title/updates",{after:0,limit:60,filter:getItemCardFields()},e)},s=>{const r=document.querySelector("#new-series .render-container");r.innerHTML="",document.querySelector("#new-series .preload-spinner").classList.add("dnone"),n.loader.favouritesList(A=>{var a=getStorablePlayerData();for(let t=0;t<s.list.length;t++)for(let e=0;e<A.length;e++)if(A[e].id==s.list[t].id){a[s.list[t].id]&&(s.list[t].localPlayerData=a[s.list[t].id]),r.appendChild(n.renderer.renderItemCard(s.list[t]).node);break}})},300)}),n.router.initPage("genres",e=>{var t=document.location.hash.split("sg:")[1],A=(setTimeout(()=>{makeSelectedGenresActivated()},30),document.querySelector("#genres .render-container"));t?n.loader.genresPageUpToLoad(1,e=>{var t=document.querySelector("#genres .render-container"),A=document.querySelector("#genres .more-btn");t.innerHTML="",document.querySelector("#genres .preload-spinner").classList.add("dnone"),e.list.length&&A.classList.remove("dnone"),e.pagination.current_page==e.pagination.pages&&A.classList.add("dnone"),insertListToRenderContainer(t,e.list)}):(A.innerHTML="",document.querySelector("#genres .preload-spinner").classList.add("dnone"))})},playerPatch=e=>{const t=document.querySelector("#"+e),A=t.childNodes[0].childNodes[21].childNodes[0].childNodes[0];t.childNodes[0].addEventListener("contextmenu",e=>{e.stopImmediatePropagation()},!0);A.style.borderRadius="6px",A.style.border="0",t.childNodes[0].childNodes[16].childNodes[0].childNodes[0].style.borderRadius="0 4px 4px 0",window.player={container:t,element:t.querySelector("video"),api:{next:()=>{t.childNodes[0].childNodes[8].childNodes[2].click()},back:()=>{t.childNodes[0].childNodes[6].childNodes[2].click()},playPause:()=>{t.childNodes[0].childNodes[7].childNodes[2].click()},muteUnmute:()=>{t.childNodes[0].childNodes[11].childNodes[2].click()},isMute:()=>"hidden"==t.childNodes[0].childNodes[11].childNodes[1].childNodes[0].style.visibility,mute:()=>{window.player.api.isMute()||window.player.api.muteUnmute()},unmute:()=>{window.player.api.isMute()&&window.player.api.muteUnmute()},isPlaying:()=>"hidden"==t.childNodes[0].childNodes[7].childNodes[1].childNodes[0].style.visibility,play:()=>{window.player.api.isPlaying()||window.player.api.playPause()},pause:()=>{window.player.api.isPlaying()&&window.player.api.playPause()},skipOpening:()=>{"none"!=t.childNodes[0].childNodes[21].style.display&&A.click()}}},player.element.addEventListener("ended",e=>{player.api.next()}),player.element.addEventListener("pause",e=>{player.element.style.filter="brightness(.6)"}),player.element.addEventListener("play",e=>{player.element.style.filter="brightness(1)"}),document.addEventListener("keyup",e=>{78==e.keyCode&&player.api.next(),66==e.keyCode&&player.api.back(),83==e.keyCode&&player.api.skipOpening()})};
//# sourceMappingURL=all.min.js.map