From dec47f900b10b0d364f44a08cc4257e122676152 Mon Sep 17 00:00:00 2001 From: projectdx Date: Sun, 10 Apr 2022 14:24:23 +0900 Subject: [PATCH] anime-downloader bug fix 21. add search routine check download fix --- .../anime_downloader_ohli24_category.html | 144 +++- .../anime_downloader_ohli24_request.html | 647 +++++++++--------- 2 files changed, 442 insertions(+), 349 deletions(-) diff --git a/templates/anime_downloader_ohli24_category.html b/templates/anime_downloader_ohli24_category.html index 129a401..78d5502 100644 --- a/templates/anime_downloader_ohli24_category.html +++ b/templates/anime_downloader_ohli24_category.html @@ -22,7 +22,7 @@ aria-label="Basic example" > - + @@ -53,13 +53,16 @@ const sub = "{{arg['sub'] }}"; const ohli24_url = "{{arg['ohli24_url']}}"; let current_data = null; + let page = 1; + let next_page = Number + let current_cate = '' const observer = lozad('.lozad', { - rootMargin: '10px 0px', // syntax similar to that of CSS Margin - threshold: 0.1, // ratio of element convergence - enableAutoReload: true // it will reload the new image when validating attributes changes + rootMargin: '10px 0px', // syntax similar to that of CSS Margin + threshold: 0.1, // ratio of element convergence + enableAutoReload: true // it will reload the new image when validating attributes changes }); - observer.observe(); + observer.observe(); const get_anime_list = (type, page) => { @@ -70,12 +73,19 @@ switch (type) { case 'ing': url = '/' + package_name + '/ajax/'+sub+'/anime_list' + current_cate = 'ing' break; case 'movie': - url = '/' + package_name + '/ajax/'+sub+'screen_movie_list' + url = '/' + package_name + '/ajax/'+sub+'/screen_movie_list' + current_cate = 'movie' break; - case 'complete': - url = '/' + package_name + '/ajax/'+sub+'screen_movie_list' + case 'theater': + url = '/' + package_name + '/ajax/'+sub+'/anime_list' + current_cate = 'theater' + break; + case 'fin': + url = '/' + package_name + '/ajax/'+sub+'/complete_list' + current_cate = 'fin' break default: break; @@ -93,13 +103,16 @@ if (current_screen_movie_data !== '') { if (type === "ing") { - make_airing_list(ret.data, page) - // setTimeout(() => { - // observer.observe(); - // }, 1000); - observer.observe(); + make_airing_list(ret.data, page) + observer.observe(); + } else if (type === "fin") { + make_screen_movie_list(ret.data, page) + observer.observe(); + } else if (type === "theater") { + make_screen_movie_list(ret.data, page) + observer.observe(); } else { - make_screen_movie_list(ret, page) + make_screen_movie_list(ret.data, page) } div_visible = true console.log(div_visible) @@ -165,6 +178,14 @@ str += ''; str += '
'; for (let i in data.anime_list) { + if (data.anime_list[i].wr_id !== '') { + const re = /bo_table=([^&]+)/ + const bo_table = data.anime_list[i].link.match(re) + // console.log(bo_table) + request_url = './request?code=' + data.anime_list[i].code + '&wr_id='+ data.anime_list[i].wr_id + '&bo_table='+bo_table[1] + } else { + request_url = './request?code=' + data.anime_list[i].code + } tmp = '
'; tmp += '
'; @@ -174,7 +195,7 @@ // {# '' + data.episode[i].code + '
';#} tmp += '
' + data.anime_list[i].title + '
'; tmp += '

' + data.anime_list[i].code + '

'; - tmp += '' + data.anime_list[i].title + ''; + tmp += '' + data.anime_list[i].title + ''; tmp += '
'; tmp += '
'; tmp += ''; @@ -215,11 +236,9 @@ tmp += '
'; tmp += ''; tmp += '
' - {#tmp += '
';#} tmp += '
' + data.anime_list[i].title + '
'; tmp += '

' + data.anime_list[i].code + '

'; - tmp += '' + data.episode[i].title + ''; + tmp += '' + data.anime_list[i].title + ''; tmp += '
'; tmp += ''; tmp += ''; @@ -299,10 +318,24 @@ }); $('#anime_category #ing').on("click", function() { + // {#console.log(this.id)#} + let spinner = document.getElementById('spinner'); + spinner.style.visibility = 'visible'; + get_anime_list("ing", 1) + }) + + $('#anime_category #complete_anilist').on("click", function() { // {#console.log(this.id)#} let spinner = document.getElementById('spinner'); spinner.style.visibility = 'visible'; - get_anime_list("ing", 1) + get_anime_list("fin", 1) + }) + + $('#anime_category #theater').on("click", function() { + // {#console.log(this.id)#} + let spinner = document.getElementById('spinner'); + spinner.style.visibility = 'visible'; + get_anime_list("theater", 1) }) // 분석 버튼 클릭시 호출 @@ -368,14 +401,77 @@ }); }); // const observer = lozad(); - - - - - // const el = document.querySelector('img'); // const observer = lozad(el); // passing a `NodeList` (e.g. `document.querySelectorAll()`) is also valid // observer.observe(); + const loadNextAnimes = (cate, page) => { + spinner.style.display = "block"; + const data = { type: cate, page: String(page) }; + let url = '' + switch (cate) { + case 'ing': + url = '/' + package_name + '/ajax/'+sub+'/anime_list' + current_cate = 'ing' + break; + case 'movie': + url = '/' + package_name + '/ajax/'+sub+'/screen_movie_list' + current_cate = 'movie' + break; + case 'theater': + url = '/' + package_name + '/ajax/'+sub+'/anime_list' + current_cate = 'theater' + break; + case 'fin': + url = '/' + package_name + '/ajax/'+sub+'/complete_list' + current_cate = 'fin' + break + default: + break; + } + + fetch(url, { + method: "POST", + cache: "no-cache", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + body: new URLSearchParams(data), + }) + .then((res) => res.json()) + .then((response) => { + console.log("Success:", JSON.stringify(response)); + // {#imagesContainer.appendChild()#} + console.log("return page:::> ", response.page); + // {#page = response.page#} + make_screen_movie_list(response.data, response.page); + page++; + next_page++; + }) + .catch((error) => console.error("Error:", error)); + }; + + + const onScroll = (e) => { + console.dir(e.target.scrollingElement.scrollHeight); + const { scrollTop, scrollHeight, clientHeight } = e.target.scrollingElement; + if (Math.round(scrollHeight - scrollTop) <= clientHeight) { + document.getElementById("spinner").style.display = "block"; + console.log("loading"); + console.log("now page::> ", page); + console.log("next_page::> ", next_page); + loadNextAnimes(current_cate, next_page); + } + }; + + const debounce = (func, delay) => { + let timeoutId = null; + return (...args) => { + clearTimeout(timeoutId); + timeoutId = setTimeout(func.bind(null, ...args), delay); + }; + }; + + document.addEventListener("scroll", debounce(onScroll, 300)); -{% endblock %} \ No newline at end of file +{% endblock %}