Created galleryblock.js

This commit is contained in:
tom5079
2022-01-20 13:04:45 +09:00
parent ada8600722
commit f1caf65d0c
6 changed files with 114 additions and 7 deletions

15
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8000/hitomi-dev.html",
"webRoot": "${workspaceFolder}"
}
]
}

View File

@@ -0,0 +1,35 @@
async function get_gallery_block(galleryid) {
const uri = `//${domain}/${galleryblockdir}/${galleryid}${galleryblockextension}`;
const response = await fetch(uri);
const html = await response.text();
const doc = new DOMParser().parseFromString(rewrite_tn_paths(html), 'text/html');
const title_elm = doc.querySelector('h1 > a');
const gallery_url = title_elm.getAttribute('href');
const title = title_elm.textContent;
const thumbnails = Array.from(doc.querySelectorAll('.dj-img-cont img'), elm => elm.getAttribute('data-src'));
const artists = Array.from(doc.querySelectorAll('.artist-list a'), elm => elm.innerText);
const series = Array.from(doc.querySelectorAll('a[href^="/series/"]'), elm => elm.innerText);
const type = doc.querySelector('a[href^="/type/"]').innerText;
const language = doc.querySelector('a[href^="/index"][href$=".html"]').getAttribute('href').slice(7, -5);
const related_tags = Array.from(doc.querySelectorAll('.relatedtags a'), elm => decodeURIComponent(elm.getAttribute('href')).slice(5, -9));
return {
id: galleryid,
galleryUrl: gallery_url,
thumbnails: thumbnails,
title: title,
artists: artists,
series: series,
type: type,
language: language,
relatedTags: related_tags
};
}

64
assets/js/dev/misc.js Normal file
View File

@@ -0,0 +1,64 @@
function get_gallery_info(galleryID) {
return new Promise((resolve, reject) => {
$.getScript(`https://ltn.hitomi.la/galleries/${galleryID}.js`, () => {
resolve(galleryinfo);
});
});
}
function do_search(query) {
let terms = query.toLowerCase().trim().split(/\s+/);
let positive_terms = [], negative_terms = [];
$.each(terms, function (i, term) {
term = term.replace(/_/g, ' ');
if (term.match(/^-/)) {
negative_terms.push(term.replace(/^-/, ''));
} else {
positive_terms.push(term);
}
});
return new Promise((resolve, reject) => { //first results
if (!positive_terms.length) {
get_galleryids_from_nozomi(undefined, 'index', 'all').then(results => {
resolve(results);
});
} else {
const term = positive_terms.shift();
get_galleryids_for_query(term).then(results => {
resolve(results);
});
}
}).then(() => { //positive results
return Promise.all(positive_terms.map(term => {
return new Promise((resolve, reject) => {
get_galleryids_for_query(term).then(new_results => {
const new_results_set = new Set(new_results);
results = results.filter(galleryid => new_results_set.has(galleryid));
resolve();
})
});
}));
}).then(() => { //negative results
return Promise.all(negative_terms.map(term => {
return new Promise((resolve, reject) => {
get_galleryids_for_query(term).then(new_results => {
const new_results_set = new Set(new_results);
results = results.filter(galleryid => !new_results_set.has(galleryid));
resolve();
});
});
}));
}).then(() => {
const final_results_length = results.length;
$('#number-of-results').html(final_results_length);
if (!final_results_length) {
hide_loading();
$('.gallery-content').html($('#no-results-content').html());
} else {
put_results_on_page();
}
});
}

View File

@@ -1,7 +0,0 @@
function get_gallery_info(galleryID) {
return new Promise((resolve, reject) => {
$.getScript(`https://ltn.hitomi.la/galleries/${galleryID}.js`, () => {
resolve(galleryinfo);
});
});
}