From cc4be07487ff17c369ee2c1db504def73d2170d5 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Thu, 20 Jan 2022 14:01:11 +0900 Subject: [PATCH] Created gallery.js --- assets/js/dev/gallery.js | 56 ++++++++++++++++++++++++++++++++++++++++ hitomi-dev.html | 1 + hitomi-dev.html.ver | 2 +- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 assets/js/dev/gallery.js diff --git a/assets/js/dev/gallery.js b/assets/js/dev/gallery.js new file mode 100644 index 00000000..ed870d07 --- /dev/null +++ b/assets/js/dev/gallery.js @@ -0,0 +1,56 @@ +async function get_gallery_url(galleryid) { + const url = `https://hitomi.la/galleries/${galleryid}.html`; + + const response = await fetch(url); + const html = await response.text(); + + const doc = new DOMParser().parseFromString(html, 'text/html'); + + return doc.querySelector('link').getAttribute('href'); +} + +async function get_gallery(galleryid) { + const url = await get_gallery_url(galleryid); + + const response = await fetch(url); + const html = await response.text(); + + const doc = new DOMParser().parseFromString(rewrite_tn_paths(html), 'text/html'); + + //related + eval(Array.from(doc.getElementsByTagName('script')).find(elm => elm.innerHTML.includes('var related')).innerHTML); + + const lang_list = Array.from(doc.querySelectorAll('#lang-list a'), elm => [elm.innerText, elm.getAttribute('href').slice(11, -5)]); + + const cover = `https:${doc.querySelector('.cover img').getAttribute('src')}`; + + const title = doc.querySelector('.gallery h1 a').innerText; + const artists = Array.from(doc.querySelectorAll('.gallery h2 a'), elm => elm.innerText); + const groups = Array.from(doc.querySelectorAll('.gallery-info a[href^="/group."]'), elm => elm.innerText); + const type = doc.querySelector('.gallery-info a[href^="/type/"]').innerText.trim(); + + const language = doc.querySelector('.gallery-info a[href^="/index"][href$=".html"]').getAttribute('href').slice(7, -5); + + const series = decodeURIComponent(doc.querySelector('.gallery-info a[href^="/series/"]').getAttribute('href')).slice(8, -9); + const characters = Array.from(doc.querySelectorAll('.gallery-info a[href^="/character/"]'), elm => elm.innerText); + + const tags = Array.from(doc.querySelectorAll('.gallery-info a[href^="/tag/"]'), elm => decodeURIComponent(elm.getAttribute('href')).slice(5, -9)); + + const gallery_info = await get_gallery_info(galleryid); + const thumbnails = gallery_info.files.map(file => url_from_url_from_hash(galleryid, file, 'smalltn', 'jpg', 'tn')); + + return { + related: related, + langList: lang_list, + cover: cover, + title: title, + artists: artists, + groups: groups, + type: type, + language: language, + series: series, + characters: characters, + tags: tags, + thumbnails: thumbnails + }; +} \ No newline at end of file diff --git a/hitomi-dev.html b/hitomi-dev.html index dff6d9dc..7ddc7f75 100644 --- a/hitomi-dev.html +++ b/hitomi-dev.html @@ -3,6 +3,7 @@ + diff --git a/hitomi-dev.html.ver b/hitomi-dev.html.ver index 1f06e5c5..6f359d5d 100644 --- a/hitomi-dev.html.ver +++ b/hitomi-dev.html.ver @@ -1 +1 @@ -0.0.6-DEV02 +0.0.7-DEV01