Created galleryblock.js
This commit is contained in:
158
assets/js/dev/common.js
Normal file
158
assets/js/dev/common.js
Normal file
@@ -0,0 +1,158 @@
|
||||
"use strict";
|
||||
|
||||
var loading_timer;
|
||||
var domain = (/^dev\./.test(document.location.hostname.toString()) ? 'dev' : 'ltn')+'.hitomi.la';
|
||||
var galleryblockextension = '.html';
|
||||
var galleryblockdir = 'galleryblock';
|
||||
var nozomiextension = '.nozomi';
|
||||
|
||||
function subdomain_from_url(url, base) {
|
||||
var retval = 'b';
|
||||
if (base) {
|
||||
retval = base;
|
||||
}
|
||||
|
||||
var b = 16;
|
||||
|
||||
var r = /\/[0-9a-f]{61}([0-9a-f]{2})([0-9a-f])/;
|
||||
var m = r.exec(url);
|
||||
if (!m) {
|
||||
return 'a';
|
||||
}
|
||||
|
||||
var g = parseInt(m[2]+m[1], b);
|
||||
if (!isNaN(g)) {
|
||||
retval = String.fromCharCode(97 + gg.m(g)) + retval;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
function url_from_url(url, base) {
|
||||
return url.replace(/\/\/..?\.hitomi\.la\//, '//'+subdomain_from_url(url, base)+'.hitomi.la/');
|
||||
}
|
||||
|
||||
|
||||
function full_path_from_hash(hash) {
|
||||
return gg.b+gg.s(hash)+'/'+hash;
|
||||
}
|
||||
|
||||
function real_full_path_from_hash(hash) {
|
||||
return hash.replace(/^.*(..)(.)$/, '$2/$1/'+hash);
|
||||
}
|
||||
|
||||
|
||||
function url_from_hash(galleryid, image, dir, ext) {
|
||||
ext = ext || dir || image.name.split('.').pop();
|
||||
dir = dir || 'images';
|
||||
|
||||
return 'https://a.hitomi.la/'+dir+'/'+full_path_from_hash(image.hash)+'.'+ext;
|
||||
}
|
||||
|
||||
function url_from_url_from_hash(galleryid, image, dir, ext, base) {
|
||||
if ('tn' === base) {
|
||||
return url_from_url('https://a.hitomi.la/'+dir+'/'+real_full_path_from_hash(image.hash)+'.'+ext, base);
|
||||
}
|
||||
return url_from_url(url_from_hash(galleryid, image, dir, ext), base);
|
||||
}
|
||||
|
||||
function rewrite_tn_paths(html) {
|
||||
return html.replace(/\/\/tn\.hitomi\.la\/[^\/]+\/[0-9a-f]\/[0-9a-f]{2}\/[0-9a-f]{64}/g, function(url) {
|
||||
return url_from_url(url, 'tn');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function show_loading() {
|
||||
return vate_loading(true);
|
||||
}
|
||||
|
||||
function hide_loading() {
|
||||
stop_loading_timer();
|
||||
return vate_loading(false);
|
||||
}
|
||||
|
||||
function vate_loading(bool) {
|
||||
var el = $('#loader-content');
|
||||
if (!el) return;
|
||||
|
||||
if (bool) {
|
||||
el.show();
|
||||
} else {
|
||||
el.hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function start_loading_timer() {
|
||||
hide_loading();
|
||||
loading_timer = setTimeout(show_loading, 500);
|
||||
}
|
||||
|
||||
function stop_loading_timer() {
|
||||
clearTimeout(loading_timer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function scroll_to_top() {
|
||||
document.body.scrollTop = document.documentElement.scrollTop = 0;
|
||||
}
|
||||
|
||||
|
||||
function localDates() {
|
||||
$(".date").each(function() {
|
||||
//2007-02-06 20:02:00-06
|
||||
//2016-03-27 13:37:33.612-05
|
||||
var r = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(?:\.\d+)?([+-]\d{2})/;
|
||||
var m = r.exec($(this).html());
|
||||
if (!m) {
|
||||
return;
|
||||
}
|
||||
|
||||
//2007-02-06T20:02:00-06:00
|
||||
$(this).html(new Date(m[1]+'-'+m[2]+'-'+m[3]+'T'+m[4]+':'+m[5]+':'+m[6]+m[7]+':00').toLocaleString(undefined, { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' })); //Feb 6, 2007, 8:02 PM
|
||||
});
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/a/51332115/272601
|
||||
function retry(fn, retries, err) {
|
||||
retries = typeof retries !== 'undefined' ? retries : 3;
|
||||
err = typeof err !== 'undefined' ? err : null;
|
||||
|
||||
if (!retries) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
return fn().catch(function(err) {
|
||||
//console.warn(`retry ${3 - retries}, err ${err}`);
|
||||
return retry(fn, (retries - 1), err);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#lang").mouseenter(function() {
|
||||
$("#lang-drop").addClass("active");
|
||||
});
|
||||
$("#lang").mouseleave(function() {
|
||||
$("#lang-drop").removeClass("active");
|
||||
});
|
||||
$("#lang").click(function() {
|
||||
$("#lang-drop").toggleClass("active");
|
||||
});
|
||||
$(".drop-button").click(function() {
|
||||
$("nav").toggleClass("active");
|
||||
});
|
||||
localDates();
|
||||
});
|
||||
|
||||
if (typeof Cookies !== 'undefined' && Cookies && Cookies.get('observe_cls')) {
|
||||
let cls = 0;
|
||||
const po = new PerformanceObserver((list) => {
|
||||
for (const entry of list.getEntries()) {
|
||||
cls += entry.value;
|
||||
console.log(entry, 'total is now: '+cls);
|
||||
}
|
||||
});
|
||||
po.observe({type: 'layout-shift', buffered: true});
|
||||
}
|
||||
35
assets/js/dev/galleryblock.js
Normal file
35
assets/js/dev/galleryblock.js
Normal 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
|
||||
};
|
||||
}
|
||||
4107
assets/js/dev/gg.js
Normal file
4107
assets/js/dev/gg.js
Normal file
File diff suppressed because it is too large
Load Diff
64
assets/js/dev/misc.js
Normal file
64
assets/js/dev/misc.js
Normal 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user