Created gallery.js
This commit is contained in:
56
assets/js/dev/gallery.js
Normal file
56
assets/js/dev/gallery.js
Normal file
@@ -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
|
||||
};
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
<script src="https://tom5079.github.io/Pupil/assets/js/dev/common.js"></script>
|
||||
<script src="https://tom5079.github.io/Pupil/assets/js/dev/misc.js"></script>
|
||||
<script src="https://tom5079.github.io/Pupil/assets/js/dev/galleryblock.js"></script>
|
||||
<script src="https://tom5079.github.io/Pupil/assets/js/dev/gallery.js"></script>
|
||||
<script src="https://ltn.hitomi.la/search.js"></script>
|
||||
<script src="https://ltn.hitomi.la/searchlib.js"></script>
|
||||
<script src="https://ltn.hitomi.la/results.js"></script>
|
||||
|
||||
@@ -1 +1 @@
|
||||
0.0.6-DEV02
|
||||
0.0.7-DEV01
|
||||
|
||||
Reference in New Issue
Block a user