Feature/#161 autoscroll w2g #176
|
@ -17,13 +17,15 @@ export function init(): void {
|
||||||
|
|
||||||
function observeSearchResults(searchRes: Element): void {
|
function observeSearchResults(searchRes: Element): void {
|
||||||
let observer = new MutationObserver(mutations => {
|
let observer = new MutationObserver(mutations => {
|
||||||
mutations.forEach(mutation => {
|
let scrollTarget = searchRes.querySelector('.ep-view md-list-item:not(.animelist-completed)') as HTMLElement;
|
||||||
let scrollTarget = searchRes.querySelector('.ep-view md-list-item:not(.animelist-completed)');
|
|
||||||
if (assigned(scrollTarget)) {
|
if (assigned(scrollTarget)) {
|
||||||
scrollTarget.scrollIntoView();
|
// scroll container to episode first
|
||||||
|
searchRes.scrollTop = scrollTarget.offsetTop;
|
||||||
|
|
||||||
|
// then scroll page to episode if neccessarry
|
||||||
|
scrollTarget.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(searchRes, {
|
observer.observe(searchRes, {
|
||||||
childList: true,
|
childList: true,
|
||||||
|
@ -31,11 +33,6 @@ function observeSearchResults(searchRes: Element): void {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function scrollTo(el: Element, pos: number): void {
|
|
||||||
let offset: number = 24;
|
|
||||||
el.scrollTo(0, pos * 72 + offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
function findSearchResults(): Element {
|
function findSearchResults(): Element {
|
||||||
let searchResults = document.getElementsByClassName('search-results');
|
let searchResults = document.getElementsByClassName('search-results');
|
||||||
if (searchResults[0] instanceof Element) {
|
if (searchResults[0] instanceof Element) {
|
||||||
|
|
Loading…
Reference in a new issue