diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 036283b..8370a80 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -20015,12 +20015,28 @@ class PlexMeetsHomeAssistant extends HTMLElement { }; this.loadInitialData = async () => { window.addEventListener('scroll', () => { - if (this.detailsShown && - this.activeMovieElem && - this.getTop() + 15 < parseInt(this.activeMovieElem.style.top, 10)) { - window.scroll({ - top: getOffset(this.activeMovieElem).top - 80 - }); + if (this.detailsShown && this.activeMovieElem) { + if (this.getTop() + 15 < parseInt(this.activeMovieElem.style.top, 10)) { + window.scroll({ + top: getOffset(this.activeMovieElem).top - 80 + }); + } + else { + // todo move final bottom value to class to safe performance + // todo: make it work with episodes and extras + const season = this.getElementsByClassName('seasons')[0]; + const seasonContainers = this.getElementsByClassName('seasonContainer'); + const lastSeasonContainer = seasonContainers[seasonContainers.length - 1]; + const seasonContainersBottom = parseInt(lastSeasonContainer.style.top, 10) + + parseInt(season.style.top, 10) + + getHeight(lastSeasonContainer) + + 60; + if (this.getTop() + window.innerHeight > seasonContainersBottom) { + window.scroll({ + top: seasonContainersBottom - window.innerHeight + }); + } + } } this.renderNewElementsIfNeeded(); }); diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index 03ff8ef..8464d36 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -149,15 +149,30 @@ class PlexMeetsHomeAssistant extends HTMLElement { loadInitialData = async (): Promise => { window.addEventListener('scroll', () => { - if ( - this.detailsShown && - this.activeMovieElem && - this.getTop() + 15 < parseInt(this.activeMovieElem.style.top, 10) - ) { - window.scroll({ - top: getOffset(this.activeMovieElem as Element).top - 80 - }); + if (this.detailsShown && this.activeMovieElem) { + if (this.getTop() + 15 < parseInt(this.activeMovieElem.style.top, 10)) { + window.scroll({ + top: getOffset(this.activeMovieElem as Element).top - 80 + }); + } else { + // todo move final bottom value to class to safe performance + // todo: make it work with episodes and extras + const season = this.getElementsByClassName('seasons')[0] as HTMLElement; + const seasonContainers = this.getElementsByClassName('seasonContainer'); + const lastSeasonContainer = seasonContainers[seasonContainers.length - 1] as HTMLElement; + const seasonContainersBottom = + parseInt(lastSeasonContainer.style.top, 10) + + parseInt(season.style.top, 10) + + getHeight(lastSeasonContainer) + + 60; + if (this.getTop() + window.innerHeight > seasonContainersBottom) { + window.scroll({ + top: seasonContainersBottom - window.innerHeight + }); + } + } } + this.renderNewElementsIfNeeded(); }); window.addEventListener('resize', () => {