var loading_timer;
var domain = (/^dev./.test(document.location.hostname.toString()) ? 'dev' : 'ltn')+'.hitomi.la';
//domain = 'ltn.hitomi.la';
var galleryblockextension = '.html';
var galleryblockdir = 'galleryblock';
var nozomiextension = '.nozomi';
var gg = {};
var is_safari = false;//['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator.platform) || (navigator.userAgent.includes("Mac") && "ontouchend" in document);///(\s|^)AppleWebKit/[\d.]+\s+(.+)\s+Version/(1[0-9]|[2-9][0-9]|\d{3,})(.|$|\s)/i.test(navigator.userAgent);
function subdomain_from_url(url, base) {
var retval = 'b';
if (base) {
retval = base;
}
code
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';
const imgs = document.querySelectorAll('img.lazyload');
imgs.forEach(function(lazyEl) {
lazyEl.setAttribute("src", lazyEl.getAttribute("data-src"));
//lazyEl.setAttribute("srcset", lazyEl.getAttribute("data-srcset")); //can't do this because the webp shim can't handle it
});
function inc_cookie(cookie_name) {
let c = parseInt(Cookies.get(cookie_name), 10) || 0;
c++;
code
let t = new Date(new Date().getTime() + 30 * 60 * 1000);
const date_name = cookie_name+'_date';
if (Cookies.get(date_name)) {
t = new Date(Cookies.get(date_name));
}
Cookies.set(cookie_name, c, { secure: true, expires: t });
Cookies.set(date_name, t, { secure: true, expires: t });
}
if (typeof Cookies !== 'undefined' && Cookies) {
if (!//(?:search|all)[^/]*.html/.test(window.location.href)) {
inc_cookie('a0e');
if (!//reader//.test(window.location.href)) {
inc_cookie('pvp');
}
}
let set_pve = (val) => { Cookies.set('pve', val, { secure: true, expires: 1 }); };
fetch('https://pagead2.googlesyndication.com/pagead/show_ads.js', { mode: 'no-cors' }).then(() => { set_pve('1'); }).catch((err) => { set_pve('0'); });
code
if (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});
}
}
function mark_unread(datas) {
if (typeof Cookies === 'undefined' || !Cookies) return;
code
var last_visited_epoch, last_visited_date, match, galleryblock_date;
if (last_visited_epoch = Cookies.get('last_visited_recently') || Cookies.get('last_visited_epoch')) {
if (last_visited_date = new Date(parseInt(last_visited_epoch))) {
var mark = -1;
for (var i = 0; i < datas.length; i++) {
if (match = datas[i].match(/\sdata-posted="([^"]+)/)) {
if (galleryblock_date = new Date(match[1])) {
if (galleryblock_date > last_visited_date) {
mark = i;
}
}
}
}
if (mark >= 0 && mark < datas.length - 1 && !/\/(?:date|popular)\//.test(window.location.href)) {
datas[mark] += '<hr class="unread">';
}
}
}
if (!Cookies.get('last_visited_recently')) {
Cookies.set('last_visited_recently', Cookies.get('last_visited_epoch') || 1, { secure: true, expires: 1/24/3 });
Cookies.set('last_visited_epoch', new Date().getTime(), { secure: true, expires: 365*10 });
}
}
function set_date_published() {
const els = document.getElementsByClassName('date');
for (let el of els) {
if (el.hasAttribute('data-datepublished') && el.getAttribute('data-datepublished')) {
el.textContent = el.getAttribute('data-datepublished');
}
}
}
var get_gg = function() {
$.ajax({dataType: 'script', cache: false, url: '//'+domain+'/gg.js'});
setTimeout(get_gg, 1000 * 60 * 30);
};
get_gg();
if ('loading' in HTMLImageElement.prototype) {
flip_lazy_images();
} else {
let script = document.createElement("script");
script.async = true;
script.src = '//'+domain+'/lazysizes.min.js';
document.body.appendChild(script);
}
if (!/\/reader\//.test(window.location.href) && location.hostname !== 'dev.hitomi.la') {
let items = [function() {
let script = document.createElement("script");
script.async = true;
script.setAttribute("src", "https://a.exdynsrv.com/ad-provider.js");
let ins = document.createElement("ins");
ins.setAttribute("class", "eas6a97888e");
ins.setAttribute("data-zoneid", "4607020");
ins.setAttribute("data-keywords", set_keywords().join(','));
document.body.appendChild(script);
document.body.appendChild(ins);
(AdProvider = window.AdProvider || []).push({"serve": {}});
}, function() {
let script = document.createElement("script");
script.async = true;
script.setAttribute("src", "https://citadelpathstatue.com/i/npage/2005785/code.js");
document.body.appendChild(script);
}, function() {
let script = document.createElement("script");
script.async = true;
script.setAttribute('data-admpid', '128015');
script.setAttribute("src", "https://js.wpadmngr.com/static/adManager.js");
document.body.appendChild(script);
}];
items[Math.floor(Math.random()*items.length)]();
}
});
how to get which domain to use from hash
It seems you are working with a web application that is determining a subdomain based on some hashing function. Let's break down the code to understand how we can determine which domain to use from a hash:
Key Points from the Code
Domains:
javascript
var domain = (/^dev\./.test(document.location.hostname.toString()) ? 'dev' : 'ltn')+'.hitomi.la';
If the hostname starts with dev., use the domain dev.hitomi.la.
Otherwise, use ltn.hitomi.la.
Determining Subdomain from Hash:
javascript
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;
}
This function generates a subdomain based on a URL pattern.
The subdomain calculation involves:
Matching a specific part of the URL /[0-9a-f]{61}([0-9a-f]{2})([0-9a-f]).
Converting parts of the match to a number and adjusting it to get a subdomain.
Generating URL from Hash:
javascript
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;
}
This function creates a URL from given parameters.
The important part here is full_path_from_hash(image.hash) which generates part of the URL path.
Full Path from Hash:
javascript
function full_path_from_hash(hash) {
return gg.b+gg.s(hash)+'/'+hash;
}
This function generates the full path from the hash.
How to Determine the Domain from a Hash
By piecing together the above information, you can determine the domain based on a hash in the following way:
Initialize gg Object:
Ensure the gg object has methods b, s, and m defined syntactically and correctly.
Example implementation (assuming some operations for gg):
javascript
var gg = {
b: "base_prefix",
s: function(hash) {
// Example transformation function
return hash.slice(0, 2); // placeholder example
},
m: function(val) {
// Example function to return mapped value
return val % 26;
}
};
Generate Subdomain:
Use the subdomain_from_url function to get the subdomain.
Generate Final URL:
Use the url_from_hash and url_from_url functions to generate the complete URL.
Example
Here's an example of putting it all together:
javascript
var gg = {
b: "base_prefix",
s: function(hash) {
// Sample transformation; adapt as needed based on the real `gg.s` function
return hash.slice(0, 2);
},
m: function(val) {
// Sample modular arithmetic; adapt as needed based on the real `gg.m` function
return val % 26; // Ensure the result is within the range for a-z
}
};
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 full_path_from_hash(hash) {
return gg.b + gg.s(hash) + '/' + hash;
}
// Example hash
var galleryid = "sample_gallery_id";
var image = { hash: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" };
var dir = "images";
var ext = "jpg";
var base = "tn";
// Simulating the URL pattern as if derived from the hash
var simulated_url = "https://a.hitomi.la/" + dir + "/" + full_path_from_hash(image.hash) + "." + ext;
// Determine subdomain
var subdomain = subdomain_from_url(simulated_url, base);
// Output the full URL with the determined subdomain
var final_url = simulated_url.replace('//a.hitomi.la/', '//' + subdomain + '.hitomi.la/');
console.log(final_url); // Logs the final URL with the computed subdomain
This should give you the necessary steps to determine and construct the domain and URL based on a given hash. Adjust the individual functions as needed to match the specifics of your application.