From e1e9fbfe1c4f93c8fb884535540c7072ae1a1bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Fri, 12 Jan 2024 19:09:13 +0100 Subject: [PATCH] Fix #98: Search in Safari only character by character --- dist/plex-meets-homeassistant.js | 2 +- src/plex-meets-homeassistant.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 8fd68d9..5a9ed66 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -663,5 +663,5 @@ found at http://polymer.github.io/PATENTS.txt button[name='playButton']:focus:after { border-color: transparent transparent transparent black !important; } -`.cssText;class dt extends HTMLElement{constructor(){super(...arguments),this.renderPageRetries=0,this.searchInputElem=document.createElement("input"),this.plexProtocol="http",this.displayType=!1,this.useHorizontalScroll=!1,this.useShuffle=!1,this.displayTitleMain=!0,this.displaySubtitleMain=!0,this.plexPort=!1,this.epgData={},this.detailsShown=!1,this.entityRegistry=[],this.runBefore="",this.playTrailer=!0,this.showExtras=!0,this.isVisible=!0,this.showSearch=!0,this.previousPageWidth=0,this.runAfter="",this.columnsCount=0,this.renderedRows=0,this.renderedItems=0,this.maxRenderCount=!1,this.minWidth=n.minimumWidth,this.minEpisodeWidth=n.minimumEpisodeWidth,this.minExpandedWidth=n.expandedWidth,this.minExpandedHeight=n.expandedHeight,this.fontSize1=14,this.fontSize2=14,this.fontSize3=28,this.fontSize4=16,this.seasonContainerClickEnabled=!0,this.looseSearch=!1,this.movieElems=[],this.searchValue="",this.activeMovieElemData={},this.seasonElemFreshlyLoaded=!1,this.episodesElemFreshlyLoaded=!1,this.seasonsElemHidden=!0,this.episodesElemHidden=!0,this.data={},this.config={},this.loading=!1,this.maxCount=!1,this.maxRows=!1,this.error="",this.contentBGHeight=0,this.initialDataLoaded=!1,this.haWindow=dt.querySelectorAllShadows("hui-view")[0],this.renderNewElementsIfNeeded=()=>{const t=G(this.content);let{scrollTop:e}=this.haWindow;et-300&&this.renderedItems>0&&this.renderedItems{if(this.isVisible){if(!this.detailsShown){let t=!1;if(this.getElementsByClassName("videoPlayer")[0].children.length>0&&(t=J(this)),this.card&&this.movieElems.length>0&&!t&&this.previousPageWidth!==this.card.offsetWidth){this.previousPageWidth=this.card.offsetWidth,this.renderPage();const t=this.getElementsByClassName("contentbg");this.contentBGHeight=G(t[0])}}this.renderNewElementsIfNeeded()}},this.loadInitialData=async()=>{this.initialDataLoaded=!0,setInterval((()=>{const t=!i.isNull(this.offsetParent);t&&!this.isVisible&&this.renderPage(),this.isVisible=t}),100),this.hassObj&&(this.entityRegistry=await K(this.hassObj.connection));const t=()=>{if(this.detailsShown&&this.activeMovieElem&&!J(this)&&this.isVisible){const t=this.getElementsByClassName("seasonContainer"),e=this.getElementsByClassName("episodeContainer"),n=this.getElementsByClassName("seasonElem");let s=this.activeMovieElem;i.forEach(n,(t=>{if(i.isEqual(t.dataset.clicked,"true"))return s=t,!1}));const r=parseInt(Z(s).top,10)-70,a=((t,e,i)=>{const n=t[t.length-1],s=e[e.length-1];let r=!1;return t.length>0&&parseInt(i.style.top,10)>0?r=G(n)+parseInt(Z(n).top,10)+10:e.length>0&&(r=G(s)+parseInt(Z(s).top,10)+10),r})(t,e,s);this.getTop()a&&(window.scroll({top:a-window.innerHeight}),this.children[0].classList.add("stop-scrolling")):-70!==r&&-10!==a&&(window.scroll({top:r}),this.children[0].classList.add("stop-scrolling")))}this.renderNewElementsIfNeeded()};this.haWindow.addEventListener("scroll",t),window.addEventListener("scroll",t),window.addEventListener("wheel",t),window.addEventListener("touchmove",t),window.addEventListener("resize",(()=>{this.resizeHandler()})),this.card&&(this.previousPageWidth=this.card.offsetWidth),this.resizeBackground()},this.renderInitialData=async()=>{let{entity:t}=JSON.parse(JSON.stringify(this.config));const e=(t,e)=>{let n=e,s=!1;i.startsWith(e,"plexPlayer | ")?(n=e.split(" | ")[3],s=!0):i.isPlainObject(e)?n=e[Object.keys(e)[0]]:(i.startsWith(e,"androidtv | ")||i.startsWith(e,"kodi | ")||i.startsWith(e,"cast | ")||i.startsWith(e,"input_select | ")||i.startsWith(e,"input_text | ")||i.startsWith(e,"vlc_telnet | ")||i.startsWith(e,"sonos | "))&&(n=e.split(" | ")[1],s=!1),s?(i.isNil(t.plexPlayer)&&(t.plexPlayer=[]),t.plexPlayer.push(n)):i.forEach(this.entityRegistry,(e=>{if(i.isEqual(e.entity_id,n))switch(e.platform){case"cast":i.isNil(t.cast)&&(t.cast=[]),t.cast.push(e.entity_id);break;case"androidtv":i.isNil(t.androidtv)&&(t.androidtv=[]),t.androidtv.push(e.entity_id);break;case"kodi":i.isNil(t.kodi)&&(t.kodi=[]),t.kodi.push(e.entity_id);break;case"input_select":i.isNil(t.inputSelect)&&(t.inputSelect=[]),t.inputSelect.push(e.entity_id);break;case"input_text":i.isNil(t.inputText)&&(t.inputText=[]),t.inputText.push(e.entity_id);break;case"vlc_telnet":i.isNil(t.vlcTelnet)&&(t.vlcTelnet=[]),t.vlcTelnet.push(e.entity_id);break;case"sonos":i.isNil(t.sonos)&&(t.sonos=[]),t.sonos.push(e.entity_id);break;default:console.error(`Entity ${e.entity_id} is not supported.`)}}))},n=t;i.isString(n)?(t={},e(t,n)):i.isArray(n)&&(t={},i.forEach(n,(i=>{e(t,i)}))),this.loading=!0,this.renderPage();try{if(this.plex&&this.hassObj){this.playController=new rt(this,this.hassObj,this.plex,t,this.runBefore,this.runAfter,this.config.libraryName,this.entityRegistry,this.useShuffle),this.playController&&await this.playController.init(),await this.plex.init();const e=await this.plex.getSections(),n=async()=>{if(this.plex)try{const t=await this.plex.getOnDeck();this.data.Deck=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Q("Deck"))}},s=async()=>{if(this.plex)try{const t=await this.plex.getContinueWatching();this.data["Continue Watching"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Q("Continue Watching"))}},r=async()=>{if(this.plex)try{const t=await this.plex.getWatchNext();this.data["Watch Next"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Q("Watch Next"))}},a=async()=>{if(this.plex)try{const t=await this.plex.getRecentyAdded();this.data["Recently Added"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;try{console.warn("PlexMeetsHomeAssistant: Using old endpoint for recently added tv shows. Consider updating your Plex server.");const t=await this.plex.getRecentyAdded(!0);this.data["Recently Added"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Q("Recently Added"))}}},o=async()=>{if(this.plex){const t=await this.plex.getLiveTV();i.forEach(t,((t,e)=>{this.data[e]=t,i.forEach(this.data[e],((t,i)=>{this.data[e][i].type="epg"}))}))}},l=async()=>{this.plex&&(this.epgData=await this.plex.getEPG())};let h=!1;i.forEach(e,(t=>!i.isEqual(t.title,this.config.libraryName)||(h=t.key,!1)));const c=[];h&&c.push(this.plex.getSectionData(h,this.displayType)),i.isEqual(this.config.libraryName,"Deck")?c.push(n()):i.isEqual(this.config.libraryName,"Continue Watching")?c.push(s()):i.isEqual(this.config.libraryName,"Watch Next")?c.push(r()):i.isEqual(this.config.libraryName,"Recently Added")&&c.push(a()),c.push(o()),c.push(l());const[u]=await Promise.all(c);i.forEach(this.epgData,((t,e)=>{i.forEach(this.data[e],((t,n)=>{i.isNil(this.epgData[e][t.channelCallSign])||(this.data[e][n].epg=this.epgData[e][t.channelCallSign])}))})),u&&h&&i.forEach(u,(t=>{this.data[t.librarySectionTitle]=t.Metadata}));const d=await this.plex.getCollections();let p={};i.forEach(d,(t=>{this.plex&&i.isEqual(t.title,this.config.libraryName)&&(p=t)})),i.isNil(p.key)||(this.data[p.title]=await this.plex.getCollectionData(p.key));const f=await this.plex.getPlaylists();let y={};i.forEach(f,(t=>{this.plex&&i.isEqual(t.title,this.config.libraryName)&&(y=t)})),i.isNil(y.key)||(this.data[y.title]=await this.plex.getPlaylistData(y.key)),void 0===this.data[this.config.libraryName]&&(this.error=`Library name ${this.config.libraryName} does not exist.`),this.loading=!1,this.render()}else setTimeout((()=>{this.renderInitialData()}),250)}catch(t){this.error=`Plex server did not respond.
Details of the error: ${F(t.message)}`,this.renderPage()}},this.render=()=>{this.renderPage()},this.searchInput=()=>{const t=document.createElement("div");return t.className="searchContainer",this.searchInputElem=document.createElement("input"),this.searchInputElem.type="text",this.searchInputElem.value=this.searchValue,this.searchInputElem.placeholder=`Search ${this.config.libraryName}...`,this.searchInputElem.addEventListener("keyup",(()=>{i.isEqual(this.searchInputElem.value,this.searchValue)||(this.searchValue=this.searchInputElem.value,this.renderPage(),this.focus())})),t.appendChild(this.searchInputElem),t},this.renderMovieElems=()=>{const t=(t,e,n,s)=>{const r=this.renderedRows,a=this.renderedItems,o=this.columnsCount;let l=0;this.contentContainer.style.width="";let h=0,c=(!this.maxCount||this.renderedItems{if(c=(!this.maxCount||this.renderedItems{if(!i.isEmpty(e)&&i.includes(i.toUpper(r.title),i.toUpper(e))||i.includes(i.toUpper(r.parentTitle),i.toUpper(e))||i.includes(i.toUpper(r.grandparentTitle),i.toUpper(e)))return t=!0,!1})),(t||i.isEmpty(n[0]))&&(o=!0)}else(i.includes(i.toUpper(r.title),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.parentTitle),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.grandparentTitle),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.tag),i.toUpper(this.searchValue))||i.includes(i.toUpper(i.get(r,"epg.title")),i.toUpper(this.searchValue)))&&(o=!0);if(o&&(u+=1,u>this.renderedItems)){if(t&&this.contentContainer.appendChild(a),this.useHorizontalScroll){this.renderedItems>0&&this.renderedItems%s==0&&(this.renderedRows+=1,a.style.clear="both");const t=10;(1===this.renderedRows||!this.maxRows||this.maxRows<2)&&(h+=parseFloat(a.style.width)+t)}this.renderedItems+=1}return t&&o&&l!==a.getBoundingClientRect().top&&!this.useHorizontalScroll&&(this.renderedRows+=1,0!==l&&0===this.columnsCount&&(this.columnsCount=this.renderedItems-1),l=a.getBoundingClientRect().top,!(t=>{const e=t.getBoundingClientRect(),i=e.top,n=e.bottom;return i>=0&&n<=window.innerHeight})(a)&&!this.maxRenderCount&&this.renderedItems>0&&(this.maxRenderCount=this.renderedItems-1+2*this.columnsCount)),this.maxRows&&this.renderedRows>this.maxRows&&!this.useHorizontalScroll&&a.remove(),!0}return!1}));const d={renderedItems:this.renderedItems};return t||(this.renderedRows=r,this.renderedItems=a,this.columnsCount=o),t&&h>0&&(this.contentContainer.style.width=`${h}px`),d},e=(!this.maxCount||this.renderedItems{let e=!1;return i.forEach(t,(t=>{if(i.isEqual(t.type,"episode"))return e=!0,!1})),e})(this.data[this.config.libraryName]),{renderedItems:a}=t(!1,r,s,n);n=a,this.maxRows&&(n=Math.ceil(a/this.maxRows)),t(!0,r,s,n)}const n=this.getElementsByClassName("contentbg")[0];this.contentBGHeight=G(n)},this.renderPage=()=>{if(this.searchInputElem.placeholder=`Search ${this.config.libraryName}...`,this.showSearch?this.searchInputElem.style.display="block":this.searchInputElem.style.display="none",this.card){const t=()=>this.card?this.card.getBoundingClientRect().width-parseInt(this.card.style.paddingRight,10)-parseInt(this.card.style.paddingLeft,10):0,e=t(),i=Math.floor(e/this.minWidth);if(e>0){const s=Math.floor(e/this.minEpisodeWidth);let r=11;i>7?r=10.3:i>3&&(r=10.7),n.width=e/i-r,n.height=n.width*n.ratio,n.episodeWidth=Math.floor(e/s-r),n.episodeHeight=Math.round(n.episodeWidth*n.episodeRatio),setTimeout((()=>{if(this.card){t()!==e&&this.renderPage()}}),1)}else this.renderPageRetries<10&&setTimeout((()=>{this.renderPageRetries+=1,this.renderPage()}),250)}this.renderedItems=0,this.renderedRows=0;const t=document.createElement("div");if(t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.innerHTML='
',this.content&&this.content.remove(),!this.card){this.card=document.createElement("ha-card"),this.card.style.transition="0.5s",this.card.style.overflow="hidden",this.card.style.padding="16px",this.card.style.paddingRight="6px";const t=document.createElement("h1");t.classList.add("card-header"),t.style.paddingRight="0px",t.style.paddingLeft="0px",t.style.paddingTop="0px",t.style.paddingBottom="0px";const e=document.createElement("div");e.classList.add("name"),e.textContent=this.config.title,t.appendChild(e),i.isNil(this.config.title)||i.isEmpty(this.config.title)?t.style.display="none":t.style.display="block",this.card.appendChild(t),this.card.appendChild(this.searchInput()),this.showSearch?this.searchInputElem.style.display="block":this.searchInputElem.style.display="none",this.appendChild(this.card)}this.content=document.createElement("div"),this.content.innerHTML=this.loadCustomStyles(),this.useHorizontalScroll&&(this.content.style.overflowX="auto",this.content.style.whiteSpace="nowrap"),""!==this.error?this.content.innerHTML+=`Error: ${this.error}`:this.data[this.config.libraryName]&&0===this.data[this.config.libraryName].length?this.content.innerHTML+=`Library ${F(this.config.libraryName)} has no items.`:this.loading&&(this.content.style.padding="16px 16px 16px",this.content.appendChild(t)),this.card.appendChild(this.content),this.contentContainer=document.createElement("div"),this.contentContainer.className="contentContainer",this.content.appendChild(this.contentContainer);const e=document.createElement("div");e.className="contentbg",this.contentContainer.appendChild(e);const s=document.createElement("div");s.className="contentArt";const r=document.createElement("div");r.className="videobg1",s.appendChild(r);const a=document.createElement("div");if(a.className="videobg2",s.appendChild(a),this.contentContainer.appendChild(s),this.detailElem=document.createElement("div"),this.detailElem.className="detail",this.detailElem.innerHTML="

\n\t\t\t

\n\t\t\t",this.playController){const t=this.playController.getPlayActionButton();t.style.fontSize=`${this.fontSize4}px`,t.style.lineHeight=`${this.fontSize4}px`,t.style.marginTop=this.fontSize4/4+"px",t.style.marginBottom=this.fontSize4/4+"px",t.style.marginRight=this.fontSize4/4+"px",t.style.padding=`${this.fontSize4/2}px ${this.fontSize4}px`,this.detailElem.appendChild(t)}this.detailElem.innerHTML+=`\n\t\t\t\n\t\t\t
\n\t\t\t\n\t\t\t
\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t
\n\t\t\t\t\t\tDirected by\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tWritten by\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tStudio\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tGenre\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
`,this.detailElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.detailElem);this.getElementsByClassName("detailPlayTrailerAction")[0].addEventListener("click",(t=>{if(t.stopPropagation(),this.videoElem){const t=this.getElementsByClassName("videoPlayer")[0].children[0];if(t.requestFullscreen)t.requestFullscreen();else if(t.webkitRequestFullscreen)t.webkitRequestFullscreen();else if(t.msRequestFullscreen)t.msRequestFullscreen();else{const e=this.getElementsByClassName("videobg1"),i=this.getElementsByClassName("videobg2");for(const t of e)t.classList.add("transparent");for(const t of i)t.classList.add("transparent");this.videoElem.classList.add("maxZIndex"),this.videoElem.classList.add("simulatedFullScreen"),t.controls=!0}}})),this.seasonsElem=document.createElement("div"),this.seasonsElem.className="seasons",this.seasonsElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.seasonsElem),this.episodesElem=document.createElement("div"),this.episodesElem.className="episodes",this.episodesElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.episodesElem),this.videoElem=document.createElement("div"),this.videoElem.className="video",this.videoElem.addEventListener("click",(t=>{const e=this.getElementsByClassName("videoPlayer")[0].children[0];if(J(this)){t.stopPropagation(),this.videoElem&&(this.videoElem.classList.remove("maxZIndex"),this.videoElem.classList.remove("simulatedFullScreen"));const i=this.getElementsByClassName("videobg1"),n=this.getElementsByClassName("videobg2");for(const t of i)t.classList.remove("transparent");for(const t of n)t.classList.remove("transparent");e.controls=!1}else this.hideBackground(),this.minimizeAll()}));const o=document.createElement("div");o.className="videobg1",this.videoElem.appendChild(o);const l=document.createElement("div");l.className="videobg2",this.videoElem.appendChild(l);const h=document.createElement("div");h.className="videoPlayer",this.videoElem.appendChild(h),this.contentContainer.appendChild(this.videoElem),setTimeout((()=>{e.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),s.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()}))}),1);const c=document.createElement("div");c.className="clear",this.contentContainer.appendChild(c),this.renderMovieElems(),this.calculatePositions(),this.loadCustomStyles()},this.calculatePositions=()=>{const t=setInterval((()=>{this.movieElems=this.getElementsByClassName("movieElem");for(let e=0;e{this.seasonsElemHidden=!1,this.seasonsElem&&i.forEach(this.seasonsElem.childNodes,(t=>{const e=t.children[0],s=t.children[1],r=t.children[2];e.style.display="block",void 0!==e.children[0].children[0]&&(e.children[0].children[0].style.display="block");const a=t=>{const a=t;a.style.marginTop="0",i.isEqual(e.dataset.type,"album")?(a.style.width=`${n.width}px`,a.style.height=`${n.width}px`):(a.style.width=`${n.width}px`,a.style.height=n.height-3+"px"),a.style.zIndex="3",a.style.marginLeft="0px",a.dataset.clicked="false",s.style.display="block",r.style.display="block",this.seasonTitleColorTimeout=setTimeout((()=>{s.style.color="rgba(255,255,255,1)",r.style.color="rgba(255,255,255,1)"}),500)};"true"===e.dataset.clicked?a(e):this.moveElemTimeout=setTimeout((()=>{a(e)}),100)}))},this.hideVideo=()=>{if(this.videoElem){this.getElementsByClassName("videoPlayer")[0].innerHTML="",this.videoElem.classList.remove("maxZIndex"),this.videoElem.classList.remove("simulatedFullScreen");const t=this.getElementsByClassName("videobg1"),e=this.getElementsByClassName("videobg2");for(const e of t)e.classList.remove("transparent");for(const t of e)t.classList.remove("transparent")}},this.minimizeAll=()=>{this.detailsShown=!1,this.activeMovieElem&&(this.activeMovieElem.style.display="block"),this.activeMovieElem=void 0;for(let t=0;t{this.movieElems[t].style.transition="0s",this.movieElems[t].style["z-index"]=1,this.movieElems[t].style.position="relative",this.movieElems[t].style.left="0px",this.movieElems[t].style.top="0px",this.movieElems[t].dataset.clicked=!1,setTimeout((()=>{this.movieElems[t].style.transition="0.5s"}),10)}),510));this.hideSeasons(),this.hideEpisodes(),this.hideDetails(),this.hideVideo(),clearInterval(this.showDetailsTimeout),clearInterval(this.showSeasonElemTimeout),clearInterval(this.seasonTitleColorTimeout),clearInterval(this.moveElemTimeout),clearInterval(this.scrollDownInactiveSeasonsTimeout),clearInterval(this.episodesLoadTimeout),clearInterval(this.episodesElemFreshlyLoadedTimeout),clearInterval(this.seasonElemFreshlyLoadedTimeout)},this.hideSeasons=()=>{if(this.seasonsElem){this.seasonsElemHidden=!0;const t=this.getTop();this.seasonsElem.style.top=`${t+2e3}px`,clearInterval(this.hideSeasonsTimeout),this.hideSeasonsTimeout=setTimeout((()=>{this.seasonsElem&&!this.seasonElemFreshlyLoaded&&(this.seasonsElem.innerHTML="",this.seasonsElem.style.display="none",this.resizeBackground())}),700)}},this.hideEpisodes=()=>{if(this.episodesElem){this.episodesElemHidden=!0;const t=this.getTop();this.episodesElem.style.top=`${t+2e3}px`,clearInterval(this.hideEpisodesTimeout),this.hideEpisodesTimeout=setTimeout((()=>{this.episodesElem&&!this.episodesElemFreshlyLoaded&&(this.episodesElem.innerHTML="",this.episodesElem.style.display="none",this.resizeBackground())}),700)}},this.scrollDownInactiveSeasons=()=>{this.seasonsElem&&(this.seasonsElemHidden=!0,i.forEach(this.seasonsElem.childNodes,(t=>{const e=t.children[0],i=t.children[1],n=t.children[2];"false"===e.dataset.clicked&&(e.style.marginTop="1000px",e.style.marginLeft="0px",this.scrollDownInactiveSeasonsTimeout=setTimeout((()=>{e.style.display="none",i.style.display="none",n.style.display="none"}),500))})))},this.hideDetails=()=>{const t=this.getTop();this.detailElem&&(this.detailElem.style.top=t-1e3+"px",this.detailElem.style.color="rgba(255,255,255,0)",this.detailElem.style.zIndex="0",this.detailElem.style.visibility="hidden"),clearTimeout(this.renderNewElementsIfNeededTimeout),this.renderNewElementsIfNeededTimeout=setTimeout((()=>{this.renderNewElementsIfNeeded()}),1e3);this.getElementsByClassName("detailPlayTrailerAction")[0].style.visibility="hidden"},this.showDetails=async t=>{this.detailsShown=!0;const e=this.getTop();if(this.detailElem&&(this.playController&&(this.playController.setPlayActionButtonType(t.type),this.playController.setPlayButtonClickFunction((e=>{e.preventDefault(),e.stopPropagation(),this.playController&&this.playController.play(t,!0)}))),this.detailElem.style.transition="0s",this.detailElem.style.top=e-1e3+"px",i.isEmpty(i.get(t,"thumb"))?this.detailElem.style.left="16px":this.detailElem.style.left=`${this.minExpandedWidth+30}px`,clearInterval(this.showDetailsTimeout),this.showDetailsTimeout=setTimeout((async()=>{if(this.detailElem&&this.plex){this.detailElem.style.visibility="visible",this.detailElem.style.transition="0.7s",this.detailElem.style.top=`${e}px`;let n=t;i.isEqual(t.type,"season")&&(n=await this.plex.getDetails(t.parentKey.split("/")[3]),n.title=`${n.title} - ${t.title}`);const s=this.getElementsByClassName("metaInfoDetailsData")[0];s.style.fontSize=`${this.fontSize4}px`,s.style.lineHeight=`${this.fontSize4}px`,s.style.marginTop=this.fontSize4/4+"px",s.style.marginBottom=this.fontSize4/4+"px",s.style.display="block",s.parentElement&&(n.Director&&n.Director.length>0?(s.innerHTML=F(n.Director[0].tag),s.parentElement.style.display="table-row"):s.parentElement.style.display="none");const r=this.getElementsByClassName("metaInfoDetailsData")[1];r.style.fontSize=`${this.fontSize4}px`,r.style.lineHeight=`${this.fontSize4}px`,r.style.marginTop=this.fontSize4/4+"px",r.style.marginBottom=this.fontSize4/4+"px",r.style.display="block",r.parentElement&&(n.Writer&&n.Writer.length>0?(r.innerHTML=F(n.Writer[0].tag),r.parentElement.style.display="table-row"):r.parentElement.style.display="none");const a=this.getElementsByClassName("metaInfoDetailsData")[2];a.style.fontSize=`${this.fontSize4}px`,a.style.lineHeight=`${this.fontSize4}px`,a.style.marginTop=this.fontSize4/4+"px",a.style.marginBottom=this.fontSize4/4+"px",a.style.display="block",a.parentElement&&(n.studio?(a.innerHTML=F(n.studio),a.parentElement.style.display="table-row"):a.parentElement.style.display="none");const o=this.getElementsByClassName("metaInfoDetailsData")[3];if(o.style.fontSize=`${this.fontSize4}px`,o.style.lineHeight=`${this.fontSize4}px`,o.style.marginTop=this.fontSize4/4+"px",o.style.marginBottom=this.fontSize4/4+"px",o.style.display="block",o.parentElement)if(n.Genre&&n.Genre.length>0){let t="";i.forEach(n.Genre,(e=>{t+=`${e.tag}, `})),o.innerHTML=F(t.slice(0,-2)),o.parentElement.style.display="table-row"}else o.parentElement.style.display="none";const l=this.getElementsByClassName("detailsTitle")[0];i.isNil(n.channelCallSign)?l.innerHTML=F(n.title):l.innerHTML=F(n.channelCallSign),l.style.lineHeight=`${this.fontSize3}px`,l.style.fontSize=`${this.fontSize3}px`,l.style.marginBottom=this.fontSize3/4+"px";const h=this.getElementsByClassName("detailsYear")[0];h.style.display="block",h.style.fontSize=`${this.fontSize4}px`,h.style.lineHeight=`${this.fontSize4}px`,h.style.marginTop="0px",h.style.marginBottom=this.fontSize4/4+"px",i.isNil(n.year)?i.isNil(n.epg)||i.isNil(n.epg.title)?(h.style.display="none",h.innerHTML=""):h.innerHTML=F(n.epg.title):h.innerHTML=F(n.year),this.getElementsByClassName("metaInfo")[0].innerHTML=(void 0!==n.duration?`${Math.round(parseInt(F(n.duration),10)/60/1e3)} min`:"")+(void 0!==n.contentRating?`${F(n.contentRating)}`:"")+(void 0!==n.rating?`${n.rating<5?"🗑":"⭐"} ${Math.round(10*parseFloat(F(n.rating)))/10}`:"")+"
";const c=this.getElementsByClassName("detailDesc")[0];c.style.fontSize=`${this.fontSize4}px`,c.style.lineHeight=`${this.fontSize4}px`,c.style.marginTop=this.fontSize4/4+"px",c.style.marginBottom=this.fontSize4/4+"px",c.style.display="block",i.isNil(n.summary)?i.isNil(n.epg)||i.isNil(n.epg.summary)?(c.innerHTML="",c.style.display="none"):c.innerHTML=F(n.epg.summary):c.innerHTML=F(n.summary),this.detailElem.style.color="rgba(255,255,255,1)",this.detailElem.style.zIndex="4",this.detailElem.style.width=`calc(100% - ${this.minExpandedWidth+30+20}px)`,this.activeMovieElem?this.detailElem.style.maxHeight=`${G(this.activeMovieElem)+40}px`:this.detailElem.style.maxHeight=`${this.minExpandedHeight+20}px`}}),200)),this.plex){let s={};i.isEqual(t.type,"episode")?s=await this.plex.getLibraryData(`${t.grandparentKey}/children`):(t.childCount>0||i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder"))&&(s=await this.plex.getLibraryData(t.key)),this.playController&&(i.includes(t.key,"folder")?this.playController.setPlayActionDisplay("none"):this.playController.setPlayActionDisplay("block"));let r={};if(!i.isNil(t.key)&&(i.includes(t.key,"folder")||(r=await this.plex.getDetails(t.key.split("/")[3])),this.videoElem)){const n=this.plex.authorizeURL(this.plex.getBasicURL()+t.art);if(""===(t=>{let e="";return t.Extras&&t.Extras.Metadata&&t.Extras.Metadata.length>0&&i.forEach(t.Extras.Metadata,(t=>{if("trailer"===t.subtype)return e=t.Media[0].Part[0].key,!1})),e})(r)||i.isEqual(this.playTrailer,!1)){if(!i.isEmpty(n)){const t=this.getElementsByClassName("contentArt")[0],i=this.getElementsByClassName("contentbg")[0];t.style.width=`${window.innerWidth}px`,t.style.height=`${window.innerHeight}px`,t.style.backgroundImage=`url('${n}')`,t.style.top=e-8+"px",t.style.transition="0.5s",t.style.display="block",i.classList.add("no-transparency")}}else{const t=this.getElementsByClassName("videoPlayer")[0],n=document.createElement("video");n.style.height="100%",n.style.width="100%",n.controls=!1,i.isEqual(this.playTrailer,"muted")&&(n.muted=!0);const s=document.createElement("source");s.type="video/mp4",s.src=this.plex.authorizeURL(`${this.plex.getBasicURL()}${r.Extras.Metadata[0].Media[0].Part[0].key}`),n.appendChild(s),t.appendChild(n),n.load(),n.play();let a=!1;const o=this.getElementsByClassName("videobg1"),l=this.getElementsByClassName("videobg2");n.addEventListener("click",(t=>{J(this)&&t.stopPropagation()}));const h=()=>{if(this.videoElem)if(J(this)){for(const t of o)t.classList.add("transparent");for(const t of l)t.classList.add("transparent");this.videoElem.classList.add("maxZIndex"),n.controls=!0,n.muted=!1}else{for(const t of o)t.classList.remove("transparent");for(const t of l)t.classList.remove("transparent");this.videoElem.classList.remove("maxZIndex"),n.controls=!1,window.scroll({top:Z(this.activeMovieElem).top-70,behavior:"smooth"}),i.isEqual(this.playTrailer,"muted")&&(n.muted=!0)}};n.addEventListener("fullscreenchange",h),n.addEventListener("mozfullscreenchange",h),n.addEventListener("webkitfullscreenchange",h),n.addEventListener("msfullscreenchange",h),n.addEventListener("playing",(()=>{if(this.videoElem&&!a){const t=this.getElementsByClassName("contentbg")[0],i=this.getElementsByClassName("detailPlayTrailerAction")[0];i.style.fontSize=`${this.fontSize4}px`,i.style.lineHeight=`${this.fontSize4}px`,i.style.marginTop=this.fontSize4/4+"px",i.style.marginBottom=this.fontSize4/4+"px",i.style.marginRight=this.fontSize4/4+"px",i.style.padding=`${this.fontSize4/2}px ${this.fontSize4}px`,i.style.visibility="visible",t.classList.add("no-transparency"),a=!0,this.videoElem.style.width=`${this.getElementsByClassName("searchContainer")[0].offsetWidth}px`,this.videoElem.style.visibility="visible",this.videoElem.style.top=`${e}px`}}))}}if(i.isEmpty(s)){if(this.episodesElemFreshlyLoaded=!0,this.episodesElem){if(this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`,i.isEqual(t.type,"season")){const e=await this.plex.getLibraryData(t.key);i.forEach(e,(t=>{this.episodesElem&&this.playController&&this.plex&&this.episodesElem.append(st(this.playController,this.plex,t,this.fontSize1,this.fontSize2))}))}else if(this.showExtras&&!i.isNil(r.Extras)){const t=r.Extras.Metadata;i.forEach(t,(t=>{this.episodesElem&&this.playController&&this.plex&&this.episodesElem.append(st(this.playController,this.plex,t,this.fontSize1,this.fontSize2))}))}clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}else if(this.seasonElemFreshlyLoaded=!0,this.seasonsElem&&(this.seasonsElem.style.display="block",this.seasonsElem.innerHTML="",this.seasonsElem.style.transition="0s",this.seasonsElem.style.top=`${e+2e3}px`),i.isEqual(i.get(s[0],"type"),"track")){if(this.episodesElem){this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`;const n=document.createElement("table");n.style.width="calc(100% - 10px)",n.style.border="none",n.cellSpacing="0",n.cellPadding="0",this.episodesElem.append(n);let r=!1;i.forEach(s,(t=>{this.episodesElem&&this.playController&&this.plex&&(i.isEqual(t.type,"track")?(n.append(nt(this.playController,this.plex,t,this.fontSize1,this.fontSize2,r)),r=!r):this.episodesElem.append(st(this.playController,this.plex,t,this.fontSize1,this.fontSize2)))})),clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.activeMovieElem?i.isEmpty(i.get(t,"thumb"))?this.detailElem?this.episodesElem.style.top=`${e+G(this.detailElem)}px`:this.episodesElem.style.top=`${e}px`:this.episodesElem.style.top=`${e+G(this.activeMovieElem)+32}px`:this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}else i.forEach(s,(t=>{if(this.seasonsElem&&this.plex){this.seasonsElemHidden=!1;const s=document.createElement("div");s.className="seasonContainer",s.style.width=`${n.width}px`;const r=`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.thumb}&X-Plex-Token=${this.config.token}`,a=document.createElement("div");a.className="seasonElem",a.style.width=`${n.width}px`,i.isEqual(t.type,"album")?a.style.height=`${n.width}px`:a.style.height=n.height-3+"px",a.style.backgroundImage=`url('${r}')`,a.dataset.clicked="false",this.playController&&!this.playController.isPlaySupported(t)&&(a.style.cursor="pointer");const o=document.createElement("div");if(o.className="interactiveArea",t.leafCount-t.viewedLeafCount>0){const e=document.createElement("div");e.className="toViewSeason",e.innerHTML=(t.leafCount-t.viewedLeafCount).toString(),e.style.fontSize=`${this.fontSize4}px`,e.style.lineHeight=`${this.fontSize4}px`,e.style.padding=this.fontSize4/2+"px",o.appendChild(e)}if(this.playController){const e=this.playController.getPlayButton(t.type);this.playController.isPlaySupported(t)&&e.classList.remove("disabled"),e.addEventListener("click",(e=>{e.stopPropagation(),this.plex&&this.playController&&this.playController.play(t,!0)})),o.append(e)}a.append(o),s.append(a);const l=document.createElement("div");l.className="seasonTitleElem",l.innerHTML=F(t.title),l.style.fontSize=`${this.fontSize1}px`,l.style.lineHeight=`${this.fontSize1}px`,s.append(l);const h=document.createElement("div");h.className="seasonEpisodesCount",t.leafCount>0?h.innerHTML=`${F(t.leafCount)} episodes`:i.isNil(t.year)||(h.innerHTML=`${F(t.year)} `),h.style.fontSize=`${this.fontSize2}px`,h.style.lineHeight=`${this.fontSize2}px`,s.append(h),s.addEventListener("click",(n=>{if(n.stopPropagation(),this.seasonContainerClickEnabled&&(this.seasonContainerClickEnabled=!1,setTimeout((()=>{this.seasonContainerClickEnabled=!0}),500),this.activeMovieElem))if("false"===a.dataset.clicked)this.playController&&(this.playController.setPlayActionButtonType(t.type),this.playController.setPlayButtonClickFunction((e=>{e.preventDefault(),e.stopPropagation(),this.playController&&this.playController.play(t,!0)}))),void 0!==a.children[0].children[0]&&(a.children[0].children[0].style.display="none"),a.dataset.clicked="true",this.activeMovieElem.style.top=e-1e3+"px",setTimeout((()=>{this.activeMovieElem&&(this.activeMovieElem.style.display="none")}),500),this.scrollDownInactiveSeasons(),this.activeMovieElem?s.style.top=-G(this.activeMovieElem)+"px":s.style.top=-this.minExpandedHeight+"px",a.dataset.type=t.type,a.style.width=`${this.minExpandedWidth}px`,i.isEqual(t.type,"album")?a.style.height=`${this.minExpandedWidth}px`:a.style.height=this.minExpandedHeight-6+"px",a.style.zIndex="3",a.style.marginLeft=`-${Z(a).left-Z(this.activeMovieElem).left}px`,l.style.color="rgba(255,255,255,0)",h.style.color="rgba(255,255,255,0)",this.detailElem&&(this.detailElem.children[1].innerHTML=t.title),(async()=>{if(this.plex&&(t.leafCount>0||i.isEqual(t.type,"album"))){this.episodesElemFreshlyLoaded=!0;const n=await this.plex.getLibraryData(t.key);if(this.episodesElem){this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`;const s=document.createElement("table");s.style.width="calc(100% - 10px)",s.style.border="none",s.cellSpacing="0",s.cellPadding="0",i.isEqual(t.type,"album")&&this.episodesElem.append(s);let r=!1;i.forEach(n,(t=>{this.episodesElem&&this.playController&&this.plex&&(i.isEqual(t.type,"track")?(s.append(nt(this.playController,this.plex,t,this.fontSize1,this.fontSize2,r)),r=!r):this.episodesElem.append(st(this.playController,this.plex,t,this.fontSize1,this.fontSize2)))})),clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.activeMovieElem?this.episodesElem.style.top=`${e+G(this.activeMovieElem)+32}px`:this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}})();else if(this.playController&&this.playController.setPlayActionButtonType(t.type),s.style.top=`${s.dataset.top}px`,this.minimizeSeasons(),this.hideEpisodes(),this.activeMovieElem.style.display="block",setTimeout((()=>{this.activeMovieElem&&(this.activeMovieElem.style.top=`${e+16}px`)}),10),this.detailElem&&this.detailElem.children[1]){const{year:t}=this.detailElem.children[1].dataset;t&&(this.detailElem.children[1].innerHTML=t)}})),this.seasonsElem.append(s)}})),i.forEach(this.seasonsElem.children,(t=>{const e=t,i=e.offsetLeft,n=e.offsetTop;e.style.left=`${i}px`,e.dataset.left=`${i}`,e.style.top=`${n}px`,e.dataset.top=`${n}`})),i.forEach(this.seasonsElem.children,(t=>{t.style.position="absolute"})),clearInterval(this.seasonElemFreshlyLoadedTimeout),this.seasonElemFreshlyLoadedTimeout=setTimeout((()=>{this.seasonElemFreshlyLoaded=!1}),700),clearInterval(this.showSeasonElemTimeout),this.showSeasonElemTimeout=setTimeout((()=>{this.seasonsElem&&(this.seasonsElem.style.transition="0.7s",this.activeMovieElem?this.seasonsElem.style.top=`${e+G(this.activeMovieElem)+32}px`:this.seasonsElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200)}},this.resizeBackground=()=>{if(this.seasonsElem&&this.episodesElem&&this.card){const t=this.getElementsByClassName("contentbg")[0];this.contentBGHeight=G(t);const e=parseInt(this.seasonsElem.style.top.replace("px",""),10)+this.seasonsElem.scrollHeight,i=parseInt(this.episodesElem.style.top.replace("px",""),10)+this.episodesElem.scrollHeight;e>this.contentBGHeight&&!this.seasonsElemHidden?this.card.style.height=`${e+16}px`:i>this.contentBGHeight&&!this.episodesElemHidden?this.card.style.height=`${i+16}px`:this.card.style.height="100%"}},this.showBackground=()=>{const t=this.getElementsByClassName("contentbg");t[0].style.zIndex="2",t[0].style.backgroundColor="rgba(0,0,0,0.9)",t[0].style.display="block"},this.hideBackground=()=>{const t=this.getElementsByClassName("contentbg")[0];t.classList.remove("no-transparency"),t.style.zIndex="1",t.style.backgroundColor="rgba(0,0,0,0)",t.style.display="none";this.getElementsByClassName("contentArt")[0].style.display="none"},this.activateMovieElem=t=>{const e=t;if("true"===t.dataset.clicked)this.minimizeAll(),this.activeMovieElem=void 0,this.hideDetails(),setTimeout((()=>{e.dataset.clicked="false"}),500),this.hideBackground();else{const n=this.getTop();e.style.transition="0s",e.style.left=e.offsetLeft-this.content.scrollLeft+"px",e.style.top=`${e.offsetTop}px`,e.style.position="absolute",e.dataset.left=`${e.offsetLeft}`,e.dataset.top=`${e.offsetTop}`,e.style.zIndex="3",setTimeout((()=>{e.style.transition="0.5s",this.showDetails(this.activeMovieElemData),this.showBackground(),i.isEqual(t.style.width,t.style.height)?(e.style.width=`${this.minExpandedWidth}px`,e.style.height=`${this.minExpandedWidth}px`):(e.style.width=`${this.minExpandedWidth}px`,e.style.height=`${this.minExpandedHeight}px`),e.style.left="16px",e.style.top=`${n+16}px`,e.dataset.clicked="true",this.activeMovieElem=e}),1)}},this.getTop=()=>{if(this.card){const t=document.documentElement,e=(window.pageYOffset||t.scrollTop)-(t.clientTop||0),i=Z(this.card).top;return e{let s="";this.plex&&(s=i.isEqual(t.type,"episode")?`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.grandparentThumb}&X-Plex-Token=${this.config.token}`:`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.thumb}&X-Plex-Token=${this.config.token}`);const r=document.createElement("div");r.className="plexMeetsContainer",r.style.width=`${n.width}px`,this.displayTitleMain||this.displaySubtitleMain?r.style.marginBottom="10px":r.style.marginBottom="5px",i.isNil(t.channelCallSign)||(r.style.marginBottom="10px");const a=document.createElement("div");a.className="movieElem",a.style.width=`${n.width}px`,a.style.height=`${n.height}px`,(!i.isNil(t.channelCallSign)||i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder"))&&(i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder")||(a.style.backgroundSize="80%"),a.style.backgroundColor="rgba(0,0,0,0.2)",a.style.backgroundPosition="center",a.style.height=`${n.width}px`),a.style.backgroundImage=`url('${s}')`,this.playController&&!this.playController.isPlaySupported(t)&&(a.style.cursor="pointer"),a.addEventListener("click",(()=>{this.activeMovieElemData=t,this.activateMovieElem(a)}));const o=document.createElement("div");if(!(t.viewCount&&t.viewCount>0)&&"movie"===t.type){const t=document.createElement("div");t.className="toViewEpisode",o.appendChild(t)}if(t.leafCount-t.viewedLeafCount>0&&"show"===t.type){const e=document.createElement("div");e.className="toViewSeason",e.innerHTML=(t.leafCount-t.viewedLeafCount).toString(),e.style.fontSize=`${this.fontSize4}px`,e.style.lineHeight=`${this.fontSize4}px`,e.style.padding=this.fontSize4/2+"px",o.appendChild(e)}if(t.viewOffset>0&&t.duration>0){const e=document.createElement("div");e.className="viewProgress",e.style.width=t.viewOffset/t.duration*100+"%",o.appendChild(e)}if(o.className="interactiveArea",this.playController){const e=this.playController.getPlayButton(t.type);this.playController.isPlaySupported(t)&&e.classList.remove("disabled"),o.append(e),((t,e,i)=>{let n=!1,s=null;const r=t=>{t.stopPropagation(),null!==s&&(clearTimeout(s),s=null)},a=t=>{t.stopPropagation(),"click"===t.type&&0!==t.button||(n=!1,s=setTimeout((()=>{i(t),n=!0}),1e3))};t.addEventListener("mousedown",a),t.addEventListener("touchstart",a),t.addEventListener("click",(t=>(t.stopPropagation(),null!==s&&(clearTimeout(s),s=null),!n&&(e(t),!0)))),t.addEventListener("mouseout",r),t.addEventListener("touchend",r),t.addEventListener("touchleave",r),t.addEventListener("touchcancel",r)})(e,(e=>{e.stopPropagation(),this.hassObj&&this.playController&&this.playController.play(t,!0)}),(t=>{console.log("Play version... will be here!"),t.stopPropagation()}))}a.append(o);const l=document.createElement("div");i.isEqual(t.type,"episode")?l.innerHTML=F(t.grandparentTitle):i.isNil(t.channelCallSign)?l.innerHTML=F(t.title):l.innerHTML=F(t.channelCallSign);const h=this.fontSize1/4,c=this.fontSize2/4;l.className="titleElem",i.isNil(t.channelCallSign)?l.style.marginTop=`${h}px`:l.style.marginTop="0px",l.style.fontSize=`${this.fontSize1}px`,l.style.marginBottom=`${h}px`,l.style.lineHeight=`${this.fontSize1}px`;const u=document.createElement("div");i.isEqual(t.type,"episode")?u.innerHTML=F(t.title):i.isNil(t.year)?i.isNil(t.epg)?u.innerHTML=" ":u.innerHTML=F(t.epg.title):u.innerHTML=F(t.year),u.className="yearElem",u.style.fontSize=`${this.fontSize2}px`,u.style.lineHeight=`${this.fontSize2}px`,u.style.marginTop=`${c}px`,u.style.marginBottom=`${c}px`;const d=document.createElement("div");return i.isEqual(t.type,"episode")&&(d.innerHTML=F(`S${t.parentIndex} E${t.index}`),d.className="additionalElem",d.style.fontSize=`${this.fontSize2}px`,d.style.lineHeight=`${this.fontSize2}px`,d.style.marginTop=`${c}px`,d.style.marginBottom=`${c}px`),r.appendChild(a),this.displayTitleMain&&r.appendChild(l),this.displaySubtitleMain&&(r.appendChild(u),r.appendChild(d)),r},this.loadCustomStyles=()=>``,this.setConfig=t=>{if(this.plexProtocol="http",!t.ip)throw new Error("You need to define a Plex IP Address");if(!t.token)throw new Error("You need to define a Plex Token");if(!t.libraryName)throw new Error("You need to define a libraryName");if(!t.entity||0===t.entity.length)throw new Error("You need to define at least one entity");if(i.isPlainObject(t.entity)){let e=!1;if(i.forEach(t.entity,((t,i)=>{if(s[i])return e=!0,!1})),!e)throw new Error("You need to define at least one supported entity")}else if(!i.isString(t.entity)&&!i.isArray(t.entity))throw new Error("You need to define at least one supported entity");this.config=t,t.protocol&&(this.plexProtocol=t.protocol),t.displayType&&!i.isEmpty(t.displayType)&&(this.displayType=t.displayType),t.useHorizontalScroll&&i.isEqual(t.useHorizontalScroll,"Yes")&&(this.useHorizontalScroll=!0),t.useShuffle&&i.isEqual(t.useShuffle,"Yes")&&(this.useShuffle=!0),t.displayTitleMain&&i.isEqual(t.displayTitleMain,"No")&&(this.displayTitleMain=!1),t.displaySubtitleMain&&i.isEqual(t.displaySubtitleMain,"No")&&(this.displaySubtitleMain=!1),t.port&&!i.isEqual(t.port,"")?this.plexPort=t.port:this.plexPort=!1,t.maxCount&&""!==t.maxCount&&(this.maxCount=t.maxCount),t.maxRows&&""!==t.maxRows&&"0"!==t.maxRows&&0!==t.maxRows?this.maxRows=t.maxRows:this.maxRows=!1,t.minWidth&&""!==t.minWidth&&"0"!==t.minWidth&&0!==t.minWidth&&(this.minWidth=parseInt(t.minWidth,10)),t.minEpisodeWidth&&""!==t.minEpisodeWidth&&"0"!==t.minEpisodeWidth&&0!==t.minEpisodeWidth&&(this.minEpisodeWidth=parseInt(t.minEpisodeWidth,10)),t.minExpandedWidth&&""!==t.minExpandedWidth&&"0"!==t.minExpandedWidth&&0!==t.minExpandedWidth&&(this.minExpandedWidth=parseInt(t.minExpandedWidth,10)),t.fontSize1&&""!==t.fontSize1&&"0"!==t.fontSize1&&0!==t.fontSize1&&(this.fontSize1=parseInt(t.fontSize1,10)),t.fontSize2&&""!==t.fontSize2&&"0"!==t.fontSize2&&0!==t.fontSize2&&(this.fontSize2=parseInt(t.fontSize2,10)),t.fontSize3&&""!==t.fontSize3&&"0"!==t.fontSize3&&0!==t.fontSize3&&(this.fontSize3=parseInt(t.fontSize3,10)),t.fontSize4&&""!==t.fontSize4&&"0"!==t.fontSize4&&0!==t.fontSize4&&(this.fontSize4=parseInt(t.fontSize4,10)),t.minExpandedHeight&&""!==t.minExpandedHeight&&"0"!==t.minExpandedHeight&&0!==t.minExpandedHeight&&(this.minExpandedHeight=parseInt(t.minExpandedHeight,10)),t.runBefore&&!i.isEqual(t.runBefore,"")&&(this.runBefore=t.runBefore),t.runAfter&&!i.isEqual(t.runAfter,"")&&(this.runAfter=t.runAfter),i.isNil(t.playTrailer)||(this.playTrailer=t.playTrailer),i.isNil(t.showExtras)||(this.showExtras=t.showExtras),i.isNil(t.showSearch)||(this.showSearch=t.showSearch),this.plex=new V(this.config.ip,this.plexPort,this.config.token,this.plexProtocol,this.config.sort),this.data={},this.error="",this.renderInitialData()},this.getCardSize=()=>3}set hass(t){this.hassObj=t,this.initialDataLoaded||this.loadInitialData()}static getConfigElement(){return document.createElement("plex-meets-homeassistant-editor")}}dt.querySelectorAllShadows=(t,e=document.body)=>{const i=Array.from(e.querySelectorAll("*")).map((t=>t.shadowRoot)).filter(Boolean).map((e=>dt.querySelectorAllShadows(t,e)));return Array.from(e.querySelectorAll(t)).concat(i).flat()},customElements.define("plex-meets-homeassistant-editor",at),customElements.define("plex-meets-homeassistant",dt),window.customCards=window.customCards||[],window.customCards.push({type:"plex-meets-homeassistant",name:"Plex meets Home Assistant",preview:!1,description:"Integrates Plex into Home Assistant. Browse and launch media with a simple click."}); +`.cssText;class dt extends HTMLElement{constructor(){super(...arguments),this.renderPageRetries=0,this.searchInputElem=document.createElement("input"),this.plexProtocol="http",this.displayType=!1,this.useHorizontalScroll=!1,this.useShuffle=!1,this.displayTitleMain=!0,this.displaySubtitleMain=!0,this.plexPort=!1,this.epgData={},this.detailsShown=!1,this.entityRegistry=[],this.runBefore="",this.playTrailer=!0,this.showExtras=!0,this.isVisible=!0,this.showSearch=!0,this.previousPageWidth=0,this.runAfter="",this.columnsCount=0,this.renderedRows=0,this.renderedItems=0,this.maxRenderCount=!1,this.minWidth=n.minimumWidth,this.minEpisodeWidth=n.minimumEpisodeWidth,this.minExpandedWidth=n.expandedWidth,this.minExpandedHeight=n.expandedHeight,this.fontSize1=14,this.fontSize2=14,this.fontSize3=28,this.fontSize4=16,this.seasonContainerClickEnabled=!0,this.looseSearch=!1,this.movieElems=[],this.searchValue="",this.activeMovieElemData={},this.seasonElemFreshlyLoaded=!1,this.episodesElemFreshlyLoaded=!1,this.seasonsElemHidden=!0,this.episodesElemHidden=!0,this.data={},this.config={},this.loading=!1,this.maxCount=!1,this.maxRows=!1,this.error="",this.contentBGHeight=0,this.initialDataLoaded=!1,this.haWindow=dt.querySelectorAllShadows("hui-view")[0],this.renderNewElementsIfNeeded=()=>{const t=G(this.content);let{scrollTop:e}=this.haWindow;et-300&&this.renderedItems>0&&this.renderedItems{if(this.isVisible){if(!this.detailsShown){let t=!1;if(this.getElementsByClassName("videoPlayer")[0].children.length>0&&(t=J(this)),this.card&&this.movieElems.length>0&&!t&&this.previousPageWidth!==this.card.offsetWidth){this.previousPageWidth=this.card.offsetWidth,this.renderPage();const t=this.getElementsByClassName("contentbg");this.contentBGHeight=G(t[0])}}this.renderNewElementsIfNeeded()}},this.loadInitialData=async()=>{this.initialDataLoaded=!0,setInterval((()=>{const t=!i.isNull(this.offsetParent);t&&!this.isVisible&&this.renderPage(),this.isVisible=t}),100),this.hassObj&&(this.entityRegistry=await K(this.hassObj.connection));const t=()=>{if(this.detailsShown&&this.activeMovieElem&&!J(this)&&this.isVisible){const t=this.getElementsByClassName("seasonContainer"),e=this.getElementsByClassName("episodeContainer"),n=this.getElementsByClassName("seasonElem");let s=this.activeMovieElem;i.forEach(n,(t=>{if(i.isEqual(t.dataset.clicked,"true"))return s=t,!1}));const r=parseInt(Z(s).top,10)-70,a=((t,e,i)=>{const n=t[t.length-1],s=e[e.length-1];let r=!1;return t.length>0&&parseInt(i.style.top,10)>0?r=G(n)+parseInt(Z(n).top,10)+10:e.length>0&&(r=G(s)+parseInt(Z(s).top,10)+10),r})(t,e,s);this.getTop()a&&(window.scroll({top:a-window.innerHeight}),this.children[0].classList.add("stop-scrolling")):-70!==r&&-10!==a&&(window.scroll({top:r}),this.children[0].classList.add("stop-scrolling")))}this.renderNewElementsIfNeeded()};this.haWindow.addEventListener("scroll",t),window.addEventListener("scroll",t),window.addEventListener("wheel",t),window.addEventListener("touchmove",t),window.addEventListener("resize",(()=>{this.resizeHandler()})),this.card&&(this.previousPageWidth=this.card.offsetWidth),this.resizeBackground()},this.renderInitialData=async()=>{let{entity:t}=JSON.parse(JSON.stringify(this.config));const e=(t,e)=>{let n=e,s=!1;i.startsWith(e,"plexPlayer | ")?(n=e.split(" | ")[3],s=!0):i.isPlainObject(e)?n=e[Object.keys(e)[0]]:(i.startsWith(e,"androidtv | ")||i.startsWith(e,"kodi | ")||i.startsWith(e,"cast | ")||i.startsWith(e,"input_select | ")||i.startsWith(e,"input_text | ")||i.startsWith(e,"vlc_telnet | ")||i.startsWith(e,"sonos | "))&&(n=e.split(" | ")[1],s=!1),s?(i.isNil(t.plexPlayer)&&(t.plexPlayer=[]),t.plexPlayer.push(n)):i.forEach(this.entityRegistry,(e=>{if(i.isEqual(e.entity_id,n))switch(e.platform){case"cast":i.isNil(t.cast)&&(t.cast=[]),t.cast.push(e.entity_id);break;case"androidtv":i.isNil(t.androidtv)&&(t.androidtv=[]),t.androidtv.push(e.entity_id);break;case"kodi":i.isNil(t.kodi)&&(t.kodi=[]),t.kodi.push(e.entity_id);break;case"input_select":i.isNil(t.inputSelect)&&(t.inputSelect=[]),t.inputSelect.push(e.entity_id);break;case"input_text":i.isNil(t.inputText)&&(t.inputText=[]),t.inputText.push(e.entity_id);break;case"vlc_telnet":i.isNil(t.vlcTelnet)&&(t.vlcTelnet=[]),t.vlcTelnet.push(e.entity_id);break;case"sonos":i.isNil(t.sonos)&&(t.sonos=[]),t.sonos.push(e.entity_id);break;default:console.error(`Entity ${e.entity_id} is not supported.`)}}))},n=t;i.isString(n)?(t={},e(t,n)):i.isArray(n)&&(t={},i.forEach(n,(i=>{e(t,i)}))),this.loading=!0,this.renderPage();try{if(this.plex&&this.hassObj){this.playController=new rt(this,this.hassObj,this.plex,t,this.runBefore,this.runAfter,this.config.libraryName,this.entityRegistry,this.useShuffle),this.playController&&await this.playController.init(),await this.plex.init();const e=await this.plex.getSections(),n=async()=>{if(this.plex)try{const t=await this.plex.getOnDeck();this.data.Deck=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Q("Deck"))}},s=async()=>{if(this.plex)try{const t=await this.plex.getContinueWatching();this.data["Continue Watching"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Q("Continue Watching"))}},r=async()=>{if(this.plex)try{const t=await this.plex.getWatchNext();this.data["Watch Next"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Q("Watch Next"))}},a=async()=>{if(this.plex)try{const t=await this.plex.getRecentyAdded();this.data["Recently Added"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;try{console.warn("PlexMeetsHomeAssistant: Using old endpoint for recently added tv shows. Consider updating your Plex server.");const t=await this.plex.getRecentyAdded(!0);this.data["Recently Added"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Q("Recently Added"))}}},o=async()=>{if(this.plex){const t=await this.plex.getLiveTV();i.forEach(t,((t,e)=>{this.data[e]=t,i.forEach(this.data[e],((t,i)=>{this.data[e][i].type="epg"}))}))}},l=async()=>{this.plex&&(this.epgData=await this.plex.getEPG())};let h=!1;i.forEach(e,(t=>!i.isEqual(t.title,this.config.libraryName)||(h=t.key,!1)));const c=[];h&&c.push(this.plex.getSectionData(h,this.displayType)),i.isEqual(this.config.libraryName,"Deck")?c.push(n()):i.isEqual(this.config.libraryName,"Continue Watching")?c.push(s()):i.isEqual(this.config.libraryName,"Watch Next")?c.push(r()):i.isEqual(this.config.libraryName,"Recently Added")&&c.push(a()),c.push(o()),c.push(l());const[u]=await Promise.all(c);i.forEach(this.epgData,((t,e)=>{i.forEach(this.data[e],((t,n)=>{i.isNil(this.epgData[e][t.channelCallSign])||(this.data[e][n].epg=this.epgData[e][t.channelCallSign])}))})),u&&h&&i.forEach(u,(t=>{this.data[t.librarySectionTitle]=t.Metadata}));const d=await this.plex.getCollections();let p={};i.forEach(d,(t=>{this.plex&&i.isEqual(t.title,this.config.libraryName)&&(p=t)})),i.isNil(p.key)||(this.data[p.title]=await this.plex.getCollectionData(p.key));const f=await this.plex.getPlaylists();let y={};i.forEach(f,(t=>{this.plex&&i.isEqual(t.title,this.config.libraryName)&&(y=t)})),i.isNil(y.key)||(this.data[y.title]=await this.plex.getPlaylistData(y.key)),void 0===this.data[this.config.libraryName]&&(this.error=`Library name ${this.config.libraryName} does not exist.`),this.loading=!1,this.render()}else setTimeout((()=>{this.renderInitialData()}),250)}catch(t){this.error=`Plex server did not respond.
Details of the error: ${F(t.message)}`,this.renderPage()}},this.render=()=>{this.renderPage()},this.searchInput=()=>{const t=document.createElement("div");return t.className="searchContainer",this.searchInputElem=document.createElement("input"),this.searchInputElem.type="text",this.searchInputElem.value=this.searchValue,this.searchInputElem.placeholder=`Search ${this.config.libraryName}...`,this.searchInputElem.addEventListener("keyup",(()=>{i.isEqual(this.searchInputElem.value,this.searchValue)||(this.searchValue=this.searchInputElem.value,this.renderPage())})),t.appendChild(this.searchInputElem),t},this.renderMovieElems=()=>{const t=(t,e,n,s)=>{const r=this.renderedRows,a=this.renderedItems,o=this.columnsCount;let l=0;this.contentContainer.style.width="";let h=0,c=(!this.maxCount||this.renderedItems{if(c=(!this.maxCount||this.renderedItems{if(!i.isEmpty(e)&&i.includes(i.toUpper(r.title),i.toUpper(e))||i.includes(i.toUpper(r.parentTitle),i.toUpper(e))||i.includes(i.toUpper(r.grandparentTitle),i.toUpper(e)))return t=!0,!1})),(t||i.isEmpty(n[0]))&&(o=!0)}else(i.includes(i.toUpper(r.title),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.parentTitle),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.grandparentTitle),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.tag),i.toUpper(this.searchValue))||i.includes(i.toUpper(i.get(r,"epg.title")),i.toUpper(this.searchValue)))&&(o=!0);if(o&&(u+=1,u>this.renderedItems)){if(t&&this.contentContainer.appendChild(a),this.useHorizontalScroll){this.renderedItems>0&&this.renderedItems%s==0&&(this.renderedRows+=1,a.style.clear="both");const t=10;(1===this.renderedRows||!this.maxRows||this.maxRows<2)&&(h+=parseFloat(a.style.width)+t)}this.renderedItems+=1}return t&&o&&l!==a.getBoundingClientRect().top&&!this.useHorizontalScroll&&(this.renderedRows+=1,0!==l&&0===this.columnsCount&&(this.columnsCount=this.renderedItems-1),l=a.getBoundingClientRect().top,!(t=>{const e=t.getBoundingClientRect(),i=e.top,n=e.bottom;return i>=0&&n<=window.innerHeight})(a)&&!this.maxRenderCount&&this.renderedItems>0&&(this.maxRenderCount=this.renderedItems-1+2*this.columnsCount)),this.maxRows&&this.renderedRows>this.maxRows&&!this.useHorizontalScroll&&a.remove(),!0}return!1}));const d={renderedItems:this.renderedItems};return t||(this.renderedRows=r,this.renderedItems=a,this.columnsCount=o),t&&h>0&&(this.contentContainer.style.width=`${h}px`),d},e=(!this.maxCount||this.renderedItems{let e=!1;return i.forEach(t,(t=>{if(i.isEqual(t.type,"episode"))return e=!0,!1})),e})(this.data[this.config.libraryName]),{renderedItems:a}=t(!1,r,s,n);n=a,this.maxRows&&(n=Math.ceil(a/this.maxRows)),t(!0,r,s,n)}const n=this.getElementsByClassName("contentbg")[0];this.contentBGHeight=G(n)},this.renderPage=()=>{if(this.searchInputElem.placeholder=`Search ${this.config.libraryName}...`,this.showSearch?this.searchInputElem.style.display="block":this.searchInputElem.style.display="none",this.card){const t=()=>this.card?this.card.getBoundingClientRect().width-parseInt(this.card.style.paddingRight,10)-parseInt(this.card.style.paddingLeft,10):0,e=t(),i=Math.floor(e/this.minWidth);if(e>0){const s=Math.floor(e/this.minEpisodeWidth);let r=11;i>7?r=10.3:i>3&&(r=10.7),n.width=e/i-r,n.height=n.width*n.ratio,n.episodeWidth=Math.floor(e/s-r),n.episodeHeight=Math.round(n.episodeWidth*n.episodeRatio),setTimeout((()=>{if(this.card){t()!==e&&this.renderPage()}}),1)}else this.renderPageRetries<10&&setTimeout((()=>{this.renderPageRetries+=1,this.renderPage()}),250)}this.renderedItems=0,this.renderedRows=0;const t=document.createElement("div");if(t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.innerHTML='
',this.content&&this.content.remove(),!this.card){this.card=document.createElement("ha-card"),this.card.style.transition="0.5s",this.card.style.overflow="hidden",this.card.style.padding="16px",this.card.style.paddingRight="6px";const t=document.createElement("h1");t.classList.add("card-header"),t.style.paddingRight="0px",t.style.paddingLeft="0px",t.style.paddingTop="0px",t.style.paddingBottom="0px";const e=document.createElement("div");e.classList.add("name"),e.textContent=this.config.title,t.appendChild(e),i.isNil(this.config.title)||i.isEmpty(this.config.title)?t.style.display="none":t.style.display="block",this.card.appendChild(t),this.card.appendChild(this.searchInput()),this.showSearch?this.searchInputElem.style.display="block":this.searchInputElem.style.display="none",this.appendChild(this.card)}this.content=document.createElement("div"),this.content.innerHTML=this.loadCustomStyles(),this.useHorizontalScroll&&(this.content.style.overflowX="auto",this.content.style.whiteSpace="nowrap"),""!==this.error?this.content.innerHTML+=`Error: ${this.error}`:this.data[this.config.libraryName]&&0===this.data[this.config.libraryName].length?this.content.innerHTML+=`Library ${F(this.config.libraryName)} has no items.`:this.loading&&(this.content.style.padding="16px 16px 16px",this.content.appendChild(t)),this.card.appendChild(this.content),this.contentContainer=document.createElement("div"),this.contentContainer.className="contentContainer",this.content.appendChild(this.contentContainer);const e=document.createElement("div");e.className="contentbg",this.contentContainer.appendChild(e);const s=document.createElement("div");s.className="contentArt";const r=document.createElement("div");r.className="videobg1",s.appendChild(r);const a=document.createElement("div");if(a.className="videobg2",s.appendChild(a),this.contentContainer.appendChild(s),this.detailElem=document.createElement("div"),this.detailElem.className="detail",this.detailElem.innerHTML="

\n\t\t\t

\n\t\t\t",this.playController){const t=this.playController.getPlayActionButton();t.style.fontSize=`${this.fontSize4}px`,t.style.lineHeight=`${this.fontSize4}px`,t.style.marginTop=this.fontSize4/4+"px",t.style.marginBottom=this.fontSize4/4+"px",t.style.marginRight=this.fontSize4/4+"px",t.style.padding=`${this.fontSize4/2}px ${this.fontSize4}px`,this.detailElem.appendChild(t)}this.detailElem.innerHTML+=`\n\t\t\t\n\t\t\t
\n\t\t\t\n\t\t\t
\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t
\n\t\t\t\t\t\tDirected by\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tWritten by\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tStudio\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tGenre\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
`,this.detailElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.detailElem);this.getElementsByClassName("detailPlayTrailerAction")[0].addEventListener("click",(t=>{if(t.stopPropagation(),this.videoElem){const t=this.getElementsByClassName("videoPlayer")[0].children[0];if(t.requestFullscreen)t.requestFullscreen();else if(t.webkitRequestFullscreen)t.webkitRequestFullscreen();else if(t.msRequestFullscreen)t.msRequestFullscreen();else{const e=this.getElementsByClassName("videobg1"),i=this.getElementsByClassName("videobg2");for(const t of e)t.classList.add("transparent");for(const t of i)t.classList.add("transparent");this.videoElem.classList.add("maxZIndex"),this.videoElem.classList.add("simulatedFullScreen"),t.controls=!0}}})),this.seasonsElem=document.createElement("div"),this.seasonsElem.className="seasons",this.seasonsElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.seasonsElem),this.episodesElem=document.createElement("div"),this.episodesElem.className="episodes",this.episodesElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.episodesElem),this.videoElem=document.createElement("div"),this.videoElem.className="video",this.videoElem.addEventListener("click",(t=>{const e=this.getElementsByClassName("videoPlayer")[0].children[0];if(J(this)){t.stopPropagation(),this.videoElem&&(this.videoElem.classList.remove("maxZIndex"),this.videoElem.classList.remove("simulatedFullScreen"));const i=this.getElementsByClassName("videobg1"),n=this.getElementsByClassName("videobg2");for(const t of i)t.classList.remove("transparent");for(const t of n)t.classList.remove("transparent");e.controls=!1}else this.hideBackground(),this.minimizeAll()}));const o=document.createElement("div");o.className="videobg1",this.videoElem.appendChild(o);const l=document.createElement("div");l.className="videobg2",this.videoElem.appendChild(l);const h=document.createElement("div");h.className="videoPlayer",this.videoElem.appendChild(h),this.contentContainer.appendChild(this.videoElem),setTimeout((()=>{e.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),s.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()}))}),1);const c=document.createElement("div");c.className="clear",this.contentContainer.appendChild(c),this.renderMovieElems(),this.calculatePositions(),this.loadCustomStyles()},this.calculatePositions=()=>{const t=setInterval((()=>{this.movieElems=this.getElementsByClassName("movieElem");for(let e=0;e{this.seasonsElemHidden=!1,this.seasonsElem&&i.forEach(this.seasonsElem.childNodes,(t=>{const e=t.children[0],s=t.children[1],r=t.children[2];e.style.display="block",void 0!==e.children[0].children[0]&&(e.children[0].children[0].style.display="block");const a=t=>{const a=t;a.style.marginTop="0",i.isEqual(e.dataset.type,"album")?(a.style.width=`${n.width}px`,a.style.height=`${n.width}px`):(a.style.width=`${n.width}px`,a.style.height=n.height-3+"px"),a.style.zIndex="3",a.style.marginLeft="0px",a.dataset.clicked="false",s.style.display="block",r.style.display="block",this.seasonTitleColorTimeout=setTimeout((()=>{s.style.color="rgba(255,255,255,1)",r.style.color="rgba(255,255,255,1)"}),500)};"true"===e.dataset.clicked?a(e):this.moveElemTimeout=setTimeout((()=>{a(e)}),100)}))},this.hideVideo=()=>{if(this.videoElem){this.getElementsByClassName("videoPlayer")[0].innerHTML="",this.videoElem.classList.remove("maxZIndex"),this.videoElem.classList.remove("simulatedFullScreen");const t=this.getElementsByClassName("videobg1"),e=this.getElementsByClassName("videobg2");for(const e of t)e.classList.remove("transparent");for(const t of e)t.classList.remove("transparent")}},this.minimizeAll=()=>{this.detailsShown=!1,this.activeMovieElem&&(this.activeMovieElem.style.display="block"),this.activeMovieElem=void 0;for(let t=0;t{this.movieElems[t].style.transition="0s",this.movieElems[t].style["z-index"]=1,this.movieElems[t].style.position="relative",this.movieElems[t].style.left="0px",this.movieElems[t].style.top="0px",this.movieElems[t].dataset.clicked=!1,setTimeout((()=>{this.movieElems[t].style.transition="0.5s"}),10)}),510));this.hideSeasons(),this.hideEpisodes(),this.hideDetails(),this.hideVideo(),clearInterval(this.showDetailsTimeout),clearInterval(this.showSeasonElemTimeout),clearInterval(this.seasonTitleColorTimeout),clearInterval(this.moveElemTimeout),clearInterval(this.scrollDownInactiveSeasonsTimeout),clearInterval(this.episodesLoadTimeout),clearInterval(this.episodesElemFreshlyLoadedTimeout),clearInterval(this.seasonElemFreshlyLoadedTimeout)},this.hideSeasons=()=>{if(this.seasonsElem){this.seasonsElemHidden=!0;const t=this.getTop();this.seasonsElem.style.top=`${t+2e3}px`,clearInterval(this.hideSeasonsTimeout),this.hideSeasonsTimeout=setTimeout((()=>{this.seasonsElem&&!this.seasonElemFreshlyLoaded&&(this.seasonsElem.innerHTML="",this.seasonsElem.style.display="none",this.resizeBackground())}),700)}},this.hideEpisodes=()=>{if(this.episodesElem){this.episodesElemHidden=!0;const t=this.getTop();this.episodesElem.style.top=`${t+2e3}px`,clearInterval(this.hideEpisodesTimeout),this.hideEpisodesTimeout=setTimeout((()=>{this.episodesElem&&!this.episodesElemFreshlyLoaded&&(this.episodesElem.innerHTML="",this.episodesElem.style.display="none",this.resizeBackground())}),700)}},this.scrollDownInactiveSeasons=()=>{this.seasonsElem&&(this.seasonsElemHidden=!0,i.forEach(this.seasonsElem.childNodes,(t=>{const e=t.children[0],i=t.children[1],n=t.children[2];"false"===e.dataset.clicked&&(e.style.marginTop="1000px",e.style.marginLeft="0px",this.scrollDownInactiveSeasonsTimeout=setTimeout((()=>{e.style.display="none",i.style.display="none",n.style.display="none"}),500))})))},this.hideDetails=()=>{const t=this.getTop();this.detailElem&&(this.detailElem.style.top=t-1e3+"px",this.detailElem.style.color="rgba(255,255,255,0)",this.detailElem.style.zIndex="0",this.detailElem.style.visibility="hidden"),clearTimeout(this.renderNewElementsIfNeededTimeout),this.renderNewElementsIfNeededTimeout=setTimeout((()=>{this.renderNewElementsIfNeeded()}),1e3);this.getElementsByClassName("detailPlayTrailerAction")[0].style.visibility="hidden"},this.showDetails=async t=>{this.detailsShown=!0;const e=this.getTop();if(this.detailElem&&(this.playController&&(this.playController.setPlayActionButtonType(t.type),this.playController.setPlayButtonClickFunction((e=>{e.preventDefault(),e.stopPropagation(),this.playController&&this.playController.play(t,!0)}))),this.detailElem.style.transition="0s",this.detailElem.style.top=e-1e3+"px",i.isEmpty(i.get(t,"thumb"))?this.detailElem.style.left="16px":this.detailElem.style.left=`${this.minExpandedWidth+30}px`,clearInterval(this.showDetailsTimeout),this.showDetailsTimeout=setTimeout((async()=>{if(this.detailElem&&this.plex){this.detailElem.style.visibility="visible",this.detailElem.style.transition="0.7s",this.detailElem.style.top=`${e}px`;let n=t;i.isEqual(t.type,"season")&&(n=await this.plex.getDetails(t.parentKey.split("/")[3]),n.title=`${n.title} - ${t.title}`);const s=this.getElementsByClassName("metaInfoDetailsData")[0];s.style.fontSize=`${this.fontSize4}px`,s.style.lineHeight=`${this.fontSize4}px`,s.style.marginTop=this.fontSize4/4+"px",s.style.marginBottom=this.fontSize4/4+"px",s.style.display="block",s.parentElement&&(n.Director&&n.Director.length>0?(s.innerHTML=F(n.Director[0].tag),s.parentElement.style.display="table-row"):s.parentElement.style.display="none");const r=this.getElementsByClassName("metaInfoDetailsData")[1];r.style.fontSize=`${this.fontSize4}px`,r.style.lineHeight=`${this.fontSize4}px`,r.style.marginTop=this.fontSize4/4+"px",r.style.marginBottom=this.fontSize4/4+"px",r.style.display="block",r.parentElement&&(n.Writer&&n.Writer.length>0?(r.innerHTML=F(n.Writer[0].tag),r.parentElement.style.display="table-row"):r.parentElement.style.display="none");const a=this.getElementsByClassName("metaInfoDetailsData")[2];a.style.fontSize=`${this.fontSize4}px`,a.style.lineHeight=`${this.fontSize4}px`,a.style.marginTop=this.fontSize4/4+"px",a.style.marginBottom=this.fontSize4/4+"px",a.style.display="block",a.parentElement&&(n.studio?(a.innerHTML=F(n.studio),a.parentElement.style.display="table-row"):a.parentElement.style.display="none");const o=this.getElementsByClassName("metaInfoDetailsData")[3];if(o.style.fontSize=`${this.fontSize4}px`,o.style.lineHeight=`${this.fontSize4}px`,o.style.marginTop=this.fontSize4/4+"px",o.style.marginBottom=this.fontSize4/4+"px",o.style.display="block",o.parentElement)if(n.Genre&&n.Genre.length>0){let t="";i.forEach(n.Genre,(e=>{t+=`${e.tag}, `})),o.innerHTML=F(t.slice(0,-2)),o.parentElement.style.display="table-row"}else o.parentElement.style.display="none";const l=this.getElementsByClassName("detailsTitle")[0];i.isNil(n.channelCallSign)?l.innerHTML=F(n.title):l.innerHTML=F(n.channelCallSign),l.style.lineHeight=`${this.fontSize3}px`,l.style.fontSize=`${this.fontSize3}px`,l.style.marginBottom=this.fontSize3/4+"px";const h=this.getElementsByClassName("detailsYear")[0];h.style.display="block",h.style.fontSize=`${this.fontSize4}px`,h.style.lineHeight=`${this.fontSize4}px`,h.style.marginTop="0px",h.style.marginBottom=this.fontSize4/4+"px",i.isNil(n.year)?i.isNil(n.epg)||i.isNil(n.epg.title)?(h.style.display="none",h.innerHTML=""):h.innerHTML=F(n.epg.title):h.innerHTML=F(n.year),this.getElementsByClassName("metaInfo")[0].innerHTML=(void 0!==n.duration?`${Math.round(parseInt(F(n.duration),10)/60/1e3)} min`:"")+(void 0!==n.contentRating?`${F(n.contentRating)}`:"")+(void 0!==n.rating?`${n.rating<5?"🗑":"⭐"} ${Math.round(10*parseFloat(F(n.rating)))/10}`:"")+"
";const c=this.getElementsByClassName("detailDesc")[0];c.style.fontSize=`${this.fontSize4}px`,c.style.lineHeight=`${this.fontSize4}px`,c.style.marginTop=this.fontSize4/4+"px",c.style.marginBottom=this.fontSize4/4+"px",c.style.display="block",i.isNil(n.summary)?i.isNil(n.epg)||i.isNil(n.epg.summary)?(c.innerHTML="",c.style.display="none"):c.innerHTML=F(n.epg.summary):c.innerHTML=F(n.summary),this.detailElem.style.color="rgba(255,255,255,1)",this.detailElem.style.zIndex="4",this.detailElem.style.width=`calc(100% - ${this.minExpandedWidth+30+20}px)`,this.activeMovieElem?this.detailElem.style.maxHeight=`${G(this.activeMovieElem)+40}px`:this.detailElem.style.maxHeight=`${this.minExpandedHeight+20}px`}}),200)),this.plex){let s={};i.isEqual(t.type,"episode")?s=await this.plex.getLibraryData(`${t.grandparentKey}/children`):(t.childCount>0||i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder"))&&(s=await this.plex.getLibraryData(t.key)),this.playController&&(i.includes(t.key,"folder")?this.playController.setPlayActionDisplay("none"):this.playController.setPlayActionDisplay("block"));let r={};if(!i.isNil(t.key)&&(i.includes(t.key,"folder")||(r=await this.plex.getDetails(t.key.split("/")[3])),this.videoElem)){const n=this.plex.authorizeURL(this.plex.getBasicURL()+t.art);if(""===(t=>{let e="";return t.Extras&&t.Extras.Metadata&&t.Extras.Metadata.length>0&&i.forEach(t.Extras.Metadata,(t=>{if("trailer"===t.subtype)return e=t.Media[0].Part[0].key,!1})),e})(r)||i.isEqual(this.playTrailer,!1)){if(!i.isEmpty(n)){const t=this.getElementsByClassName("contentArt")[0],i=this.getElementsByClassName("contentbg")[0];t.style.width=`${window.innerWidth}px`,t.style.height=`${window.innerHeight}px`,t.style.backgroundImage=`url('${n}')`,t.style.top=e-8+"px",t.style.transition="0.5s",t.style.display="block",i.classList.add("no-transparency")}}else{const t=this.getElementsByClassName("videoPlayer")[0],n=document.createElement("video");n.style.height="100%",n.style.width="100%",n.controls=!1,i.isEqual(this.playTrailer,"muted")&&(n.muted=!0);const s=document.createElement("source");s.type="video/mp4",s.src=this.plex.authorizeURL(`${this.plex.getBasicURL()}${r.Extras.Metadata[0].Media[0].Part[0].key}`),n.appendChild(s),t.appendChild(n),n.load(),n.play();let a=!1;const o=this.getElementsByClassName("videobg1"),l=this.getElementsByClassName("videobg2");n.addEventListener("click",(t=>{J(this)&&t.stopPropagation()}));const h=()=>{if(this.videoElem)if(J(this)){for(const t of o)t.classList.add("transparent");for(const t of l)t.classList.add("transparent");this.videoElem.classList.add("maxZIndex"),n.controls=!0,n.muted=!1}else{for(const t of o)t.classList.remove("transparent");for(const t of l)t.classList.remove("transparent");this.videoElem.classList.remove("maxZIndex"),n.controls=!1,window.scroll({top:Z(this.activeMovieElem).top-70,behavior:"smooth"}),i.isEqual(this.playTrailer,"muted")&&(n.muted=!0)}};n.addEventListener("fullscreenchange",h),n.addEventListener("mozfullscreenchange",h),n.addEventListener("webkitfullscreenchange",h),n.addEventListener("msfullscreenchange",h),n.addEventListener("playing",(()=>{if(this.videoElem&&!a){const t=this.getElementsByClassName("contentbg")[0],i=this.getElementsByClassName("detailPlayTrailerAction")[0];i.style.fontSize=`${this.fontSize4}px`,i.style.lineHeight=`${this.fontSize4}px`,i.style.marginTop=this.fontSize4/4+"px",i.style.marginBottom=this.fontSize4/4+"px",i.style.marginRight=this.fontSize4/4+"px",i.style.padding=`${this.fontSize4/2}px ${this.fontSize4}px`,i.style.visibility="visible",t.classList.add("no-transparency"),a=!0,this.videoElem.style.width=`${this.getElementsByClassName("searchContainer")[0].offsetWidth}px`,this.videoElem.style.visibility="visible",this.videoElem.style.top=`${e}px`}}))}}if(i.isEmpty(s)){if(this.episodesElemFreshlyLoaded=!0,this.episodesElem){if(this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`,i.isEqual(t.type,"season")){const e=await this.plex.getLibraryData(t.key);i.forEach(e,(t=>{this.episodesElem&&this.playController&&this.plex&&this.episodesElem.append(st(this.playController,this.plex,t,this.fontSize1,this.fontSize2))}))}else if(this.showExtras&&!i.isNil(r.Extras)){const t=r.Extras.Metadata;i.forEach(t,(t=>{this.episodesElem&&this.playController&&this.plex&&this.episodesElem.append(st(this.playController,this.plex,t,this.fontSize1,this.fontSize2))}))}clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}else if(this.seasonElemFreshlyLoaded=!0,this.seasonsElem&&(this.seasonsElem.style.display="block",this.seasonsElem.innerHTML="",this.seasonsElem.style.transition="0s",this.seasonsElem.style.top=`${e+2e3}px`),i.isEqual(i.get(s[0],"type"),"track")){if(this.episodesElem){this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`;const n=document.createElement("table");n.style.width="calc(100% - 10px)",n.style.border="none",n.cellSpacing="0",n.cellPadding="0",this.episodesElem.append(n);let r=!1;i.forEach(s,(t=>{this.episodesElem&&this.playController&&this.plex&&(i.isEqual(t.type,"track")?(n.append(nt(this.playController,this.plex,t,this.fontSize1,this.fontSize2,r)),r=!r):this.episodesElem.append(st(this.playController,this.plex,t,this.fontSize1,this.fontSize2)))})),clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.activeMovieElem?i.isEmpty(i.get(t,"thumb"))?this.detailElem?this.episodesElem.style.top=`${e+G(this.detailElem)}px`:this.episodesElem.style.top=`${e}px`:this.episodesElem.style.top=`${e+G(this.activeMovieElem)+32}px`:this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}else i.forEach(s,(t=>{if(this.seasonsElem&&this.plex){this.seasonsElemHidden=!1;const s=document.createElement("div");s.className="seasonContainer",s.style.width=`${n.width}px`;const r=`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.thumb}&X-Plex-Token=${this.config.token}`,a=document.createElement("div");a.className="seasonElem",a.style.width=`${n.width}px`,i.isEqual(t.type,"album")?a.style.height=`${n.width}px`:a.style.height=n.height-3+"px",a.style.backgroundImage=`url('${r}')`,a.dataset.clicked="false",this.playController&&!this.playController.isPlaySupported(t)&&(a.style.cursor="pointer");const o=document.createElement("div");if(o.className="interactiveArea",t.leafCount-t.viewedLeafCount>0){const e=document.createElement("div");e.className="toViewSeason",e.innerHTML=(t.leafCount-t.viewedLeafCount).toString(),e.style.fontSize=`${this.fontSize4}px`,e.style.lineHeight=`${this.fontSize4}px`,e.style.padding=this.fontSize4/2+"px",o.appendChild(e)}if(this.playController){const e=this.playController.getPlayButton(t.type);this.playController.isPlaySupported(t)&&e.classList.remove("disabled"),e.addEventListener("click",(e=>{e.stopPropagation(),this.plex&&this.playController&&this.playController.play(t,!0)})),o.append(e)}a.append(o),s.append(a);const l=document.createElement("div");l.className="seasonTitleElem",l.innerHTML=F(t.title),l.style.fontSize=`${this.fontSize1}px`,l.style.lineHeight=`${this.fontSize1}px`,s.append(l);const h=document.createElement("div");h.className="seasonEpisodesCount",t.leafCount>0?h.innerHTML=`${F(t.leafCount)} episodes`:i.isNil(t.year)||(h.innerHTML=`${F(t.year)} `),h.style.fontSize=`${this.fontSize2}px`,h.style.lineHeight=`${this.fontSize2}px`,s.append(h),s.addEventListener("click",(n=>{if(n.stopPropagation(),this.seasonContainerClickEnabled&&(this.seasonContainerClickEnabled=!1,setTimeout((()=>{this.seasonContainerClickEnabled=!0}),500),this.activeMovieElem))if("false"===a.dataset.clicked)this.playController&&(this.playController.setPlayActionButtonType(t.type),this.playController.setPlayButtonClickFunction((e=>{e.preventDefault(),e.stopPropagation(),this.playController&&this.playController.play(t,!0)}))),void 0!==a.children[0].children[0]&&(a.children[0].children[0].style.display="none"),a.dataset.clicked="true",this.activeMovieElem.style.top=e-1e3+"px",setTimeout((()=>{this.activeMovieElem&&(this.activeMovieElem.style.display="none")}),500),this.scrollDownInactiveSeasons(),this.activeMovieElem?s.style.top=-G(this.activeMovieElem)+"px":s.style.top=-this.minExpandedHeight+"px",a.dataset.type=t.type,a.style.width=`${this.minExpandedWidth}px`,i.isEqual(t.type,"album")?a.style.height=`${this.minExpandedWidth}px`:a.style.height=this.minExpandedHeight-6+"px",a.style.zIndex="3",a.style.marginLeft=`-${Z(a).left-Z(this.activeMovieElem).left}px`,l.style.color="rgba(255,255,255,0)",h.style.color="rgba(255,255,255,0)",this.detailElem&&(this.detailElem.children[1].innerHTML=t.title),(async()=>{if(this.plex&&(t.leafCount>0||i.isEqual(t.type,"album"))){this.episodesElemFreshlyLoaded=!0;const n=await this.plex.getLibraryData(t.key);if(this.episodesElem){this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`;const s=document.createElement("table");s.style.width="calc(100% - 10px)",s.style.border="none",s.cellSpacing="0",s.cellPadding="0",i.isEqual(t.type,"album")&&this.episodesElem.append(s);let r=!1;i.forEach(n,(t=>{this.episodesElem&&this.playController&&this.plex&&(i.isEqual(t.type,"track")?(s.append(nt(this.playController,this.plex,t,this.fontSize1,this.fontSize2,r)),r=!r):this.episodesElem.append(st(this.playController,this.plex,t,this.fontSize1,this.fontSize2)))})),clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.activeMovieElem?this.episodesElem.style.top=`${e+G(this.activeMovieElem)+32}px`:this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}})();else if(this.playController&&this.playController.setPlayActionButtonType(t.type),s.style.top=`${s.dataset.top}px`,this.minimizeSeasons(),this.hideEpisodes(),this.activeMovieElem.style.display="block",setTimeout((()=>{this.activeMovieElem&&(this.activeMovieElem.style.top=`${e+16}px`)}),10),this.detailElem&&this.detailElem.children[1]){const{year:t}=this.detailElem.children[1].dataset;t&&(this.detailElem.children[1].innerHTML=t)}})),this.seasonsElem.append(s)}})),i.forEach(this.seasonsElem.children,(t=>{const e=t,i=e.offsetLeft,n=e.offsetTop;e.style.left=`${i}px`,e.dataset.left=`${i}`,e.style.top=`${n}px`,e.dataset.top=`${n}`})),i.forEach(this.seasonsElem.children,(t=>{t.style.position="absolute"})),clearInterval(this.seasonElemFreshlyLoadedTimeout),this.seasonElemFreshlyLoadedTimeout=setTimeout((()=>{this.seasonElemFreshlyLoaded=!1}),700),clearInterval(this.showSeasonElemTimeout),this.showSeasonElemTimeout=setTimeout((()=>{this.seasonsElem&&(this.seasonsElem.style.transition="0.7s",this.activeMovieElem?this.seasonsElem.style.top=`${e+G(this.activeMovieElem)+32}px`:this.seasonsElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200)}},this.resizeBackground=()=>{if(this.seasonsElem&&this.episodesElem&&this.card){const t=this.getElementsByClassName("contentbg")[0];this.contentBGHeight=G(t);const e=parseInt(this.seasonsElem.style.top.replace("px",""),10)+this.seasonsElem.scrollHeight,i=parseInt(this.episodesElem.style.top.replace("px",""),10)+this.episodesElem.scrollHeight;e>this.contentBGHeight&&!this.seasonsElemHidden?this.card.style.height=`${e+16}px`:i>this.contentBGHeight&&!this.episodesElemHidden?this.card.style.height=`${i+16}px`:this.card.style.height="100%"}},this.showBackground=()=>{const t=this.getElementsByClassName("contentbg");t[0].style.zIndex="2",t[0].style.backgroundColor="rgba(0,0,0,0.9)",t[0].style.display="block"},this.hideBackground=()=>{const t=this.getElementsByClassName("contentbg")[0];t.classList.remove("no-transparency"),t.style.zIndex="1",t.style.backgroundColor="rgba(0,0,0,0)",t.style.display="none";this.getElementsByClassName("contentArt")[0].style.display="none"},this.activateMovieElem=t=>{const e=t;if("true"===t.dataset.clicked)this.minimizeAll(),this.activeMovieElem=void 0,this.hideDetails(),setTimeout((()=>{e.dataset.clicked="false"}),500),this.hideBackground();else{const n=this.getTop();e.style.transition="0s",e.style.left=e.offsetLeft-this.content.scrollLeft+"px",e.style.top=`${e.offsetTop}px`,e.style.position="absolute",e.dataset.left=`${e.offsetLeft}`,e.dataset.top=`${e.offsetTop}`,e.style.zIndex="3",setTimeout((()=>{e.style.transition="0.5s",this.showDetails(this.activeMovieElemData),this.showBackground(),i.isEqual(t.style.width,t.style.height)?(e.style.width=`${this.minExpandedWidth}px`,e.style.height=`${this.minExpandedWidth}px`):(e.style.width=`${this.minExpandedWidth}px`,e.style.height=`${this.minExpandedHeight}px`),e.style.left="16px",e.style.top=`${n+16}px`,e.dataset.clicked="true",this.activeMovieElem=e}),1)}},this.getTop=()=>{if(this.card){const t=document.documentElement,e=(window.pageYOffset||t.scrollTop)-(t.clientTop||0),i=Z(this.card).top;return e{let s="";this.plex&&(s=i.isEqual(t.type,"episode")?`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.grandparentThumb}&X-Plex-Token=${this.config.token}`:`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.thumb}&X-Plex-Token=${this.config.token}`);const r=document.createElement("div");r.className="plexMeetsContainer",r.style.width=`${n.width}px`,this.displayTitleMain||this.displaySubtitleMain?r.style.marginBottom="10px":r.style.marginBottom="5px",i.isNil(t.channelCallSign)||(r.style.marginBottom="10px");const a=document.createElement("div");a.className="movieElem",a.style.width=`${n.width}px`,a.style.height=`${n.height}px`,(!i.isNil(t.channelCallSign)||i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder"))&&(i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder")||(a.style.backgroundSize="80%"),a.style.backgroundColor="rgba(0,0,0,0.2)",a.style.backgroundPosition="center",a.style.height=`${n.width}px`),a.style.backgroundImage=`url('${s}')`,this.playController&&!this.playController.isPlaySupported(t)&&(a.style.cursor="pointer"),a.addEventListener("click",(()=>{this.activeMovieElemData=t,this.activateMovieElem(a)}));const o=document.createElement("div");if(!(t.viewCount&&t.viewCount>0)&&"movie"===t.type){const t=document.createElement("div");t.className="toViewEpisode",o.appendChild(t)}if(t.leafCount-t.viewedLeafCount>0&&"show"===t.type){const e=document.createElement("div");e.className="toViewSeason",e.innerHTML=(t.leafCount-t.viewedLeafCount).toString(),e.style.fontSize=`${this.fontSize4}px`,e.style.lineHeight=`${this.fontSize4}px`,e.style.padding=this.fontSize4/2+"px",o.appendChild(e)}if(t.viewOffset>0&&t.duration>0){const e=document.createElement("div");e.className="viewProgress",e.style.width=t.viewOffset/t.duration*100+"%",o.appendChild(e)}if(o.className="interactiveArea",this.playController){const e=this.playController.getPlayButton(t.type);this.playController.isPlaySupported(t)&&e.classList.remove("disabled"),o.append(e),((t,e,i)=>{let n=!1,s=null;const r=t=>{t.stopPropagation(),null!==s&&(clearTimeout(s),s=null)},a=t=>{t.stopPropagation(),"click"===t.type&&0!==t.button||(n=!1,s=setTimeout((()=>{i(t),n=!0}),1e3))};t.addEventListener("mousedown",a),t.addEventListener("touchstart",a),t.addEventListener("click",(t=>(t.stopPropagation(),null!==s&&(clearTimeout(s),s=null),!n&&(e(t),!0)))),t.addEventListener("mouseout",r),t.addEventListener("touchend",r),t.addEventListener("touchleave",r),t.addEventListener("touchcancel",r)})(e,(e=>{e.stopPropagation(),this.hassObj&&this.playController&&this.playController.play(t,!0)}),(t=>{console.log("Play version... will be here!"),t.stopPropagation()}))}a.append(o);const l=document.createElement("div");i.isEqual(t.type,"episode")?l.innerHTML=F(t.grandparentTitle):i.isNil(t.channelCallSign)?l.innerHTML=F(t.title):l.innerHTML=F(t.channelCallSign);const h=this.fontSize1/4,c=this.fontSize2/4;l.className="titleElem",i.isNil(t.channelCallSign)?l.style.marginTop=`${h}px`:l.style.marginTop="0px",l.style.fontSize=`${this.fontSize1}px`,l.style.marginBottom=`${h}px`,l.style.lineHeight=`${this.fontSize1}px`;const u=document.createElement("div");i.isEqual(t.type,"episode")?u.innerHTML=F(t.title):i.isNil(t.year)?i.isNil(t.epg)?u.innerHTML=" ":u.innerHTML=F(t.epg.title):u.innerHTML=F(t.year),u.className="yearElem",u.style.fontSize=`${this.fontSize2}px`,u.style.lineHeight=`${this.fontSize2}px`,u.style.marginTop=`${c}px`,u.style.marginBottom=`${c}px`;const d=document.createElement("div");return i.isEqual(t.type,"episode")&&(d.innerHTML=F(`S${t.parentIndex} E${t.index}`),d.className="additionalElem",d.style.fontSize=`${this.fontSize2}px`,d.style.lineHeight=`${this.fontSize2}px`,d.style.marginTop=`${c}px`,d.style.marginBottom=`${c}px`),r.appendChild(a),this.displayTitleMain&&r.appendChild(l),this.displaySubtitleMain&&(r.appendChild(u),r.appendChild(d)),r},this.loadCustomStyles=()=>``,this.setConfig=t=>{if(this.plexProtocol="http",!t.ip)throw new Error("You need to define a Plex IP Address");if(!t.token)throw new Error("You need to define a Plex Token");if(!t.libraryName)throw new Error("You need to define a libraryName");if(!t.entity||0===t.entity.length)throw new Error("You need to define at least one entity");if(i.isPlainObject(t.entity)){let e=!1;if(i.forEach(t.entity,((t,i)=>{if(s[i])return e=!0,!1})),!e)throw new Error("You need to define at least one supported entity")}else if(!i.isString(t.entity)&&!i.isArray(t.entity))throw new Error("You need to define at least one supported entity");this.config=t,t.protocol&&(this.plexProtocol=t.protocol),t.displayType&&!i.isEmpty(t.displayType)&&(this.displayType=t.displayType),t.useHorizontalScroll&&i.isEqual(t.useHorizontalScroll,"Yes")&&(this.useHorizontalScroll=!0),t.useShuffle&&i.isEqual(t.useShuffle,"Yes")&&(this.useShuffle=!0),t.displayTitleMain&&i.isEqual(t.displayTitleMain,"No")&&(this.displayTitleMain=!1),t.displaySubtitleMain&&i.isEqual(t.displaySubtitleMain,"No")&&(this.displaySubtitleMain=!1),t.port&&!i.isEqual(t.port,"")?this.plexPort=t.port:this.plexPort=!1,t.maxCount&&""!==t.maxCount&&(this.maxCount=t.maxCount),t.maxRows&&""!==t.maxRows&&"0"!==t.maxRows&&0!==t.maxRows?this.maxRows=t.maxRows:this.maxRows=!1,t.minWidth&&""!==t.minWidth&&"0"!==t.minWidth&&0!==t.minWidth&&(this.minWidth=parseInt(t.minWidth,10)),t.minEpisodeWidth&&""!==t.minEpisodeWidth&&"0"!==t.minEpisodeWidth&&0!==t.minEpisodeWidth&&(this.minEpisodeWidth=parseInt(t.minEpisodeWidth,10)),t.minExpandedWidth&&""!==t.minExpandedWidth&&"0"!==t.minExpandedWidth&&0!==t.minExpandedWidth&&(this.minExpandedWidth=parseInt(t.minExpandedWidth,10)),t.fontSize1&&""!==t.fontSize1&&"0"!==t.fontSize1&&0!==t.fontSize1&&(this.fontSize1=parseInt(t.fontSize1,10)),t.fontSize2&&""!==t.fontSize2&&"0"!==t.fontSize2&&0!==t.fontSize2&&(this.fontSize2=parseInt(t.fontSize2,10)),t.fontSize3&&""!==t.fontSize3&&"0"!==t.fontSize3&&0!==t.fontSize3&&(this.fontSize3=parseInt(t.fontSize3,10)),t.fontSize4&&""!==t.fontSize4&&"0"!==t.fontSize4&&0!==t.fontSize4&&(this.fontSize4=parseInt(t.fontSize4,10)),t.minExpandedHeight&&""!==t.minExpandedHeight&&"0"!==t.minExpandedHeight&&0!==t.minExpandedHeight&&(this.minExpandedHeight=parseInt(t.minExpandedHeight,10)),t.runBefore&&!i.isEqual(t.runBefore,"")&&(this.runBefore=t.runBefore),t.runAfter&&!i.isEqual(t.runAfter,"")&&(this.runAfter=t.runAfter),i.isNil(t.playTrailer)||(this.playTrailer=t.playTrailer),i.isNil(t.showExtras)||(this.showExtras=t.showExtras),i.isNil(t.showSearch)||(this.showSearch=t.showSearch),this.plex=new V(this.config.ip,this.plexPort,this.config.token,this.plexProtocol,this.config.sort),this.data={},this.error="",this.renderInitialData()},this.getCardSize=()=>3}set hass(t){this.hassObj=t,this.initialDataLoaded||this.loadInitialData()}static getConfigElement(){return document.createElement("plex-meets-homeassistant-editor")}}dt.querySelectorAllShadows=(t,e=document.body)=>{const i=Array.from(e.querySelectorAll("*")).map((t=>t.shadowRoot)).filter(Boolean).map((e=>dt.querySelectorAllShadows(t,e)));return Array.from(e.querySelectorAll(t)).concat(i).flat()},customElements.define("plex-meets-homeassistant-editor",at),customElements.define("plex-meets-homeassistant",dt),window.customCards=window.customCards||[],window.customCards.push({type:"plex-meets-homeassistant",name:"Plex meets Home Assistant",preview:!1,description:"Integrates Plex into Home Assistant. Browse and launch media with a simple click."}); //# sourceMappingURL=plex-meets-homeassistant.js.map diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index d9c71c5..6b553d5 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -620,7 +620,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { if (!_.isEqual(this.searchInputElem.value, this.searchValue)) { this.searchValue = this.searchInputElem.value; this.renderPage(); - this.focus(); + // this.focus(); //causes issues on iphone/safari and looks like is no longer needed } });