Update temp/temp.js

This commit is contained in:
aka paul 2025-10-26 23:03:33 +00:00
parent 256b3a9d28
commit 6030c3c84a

View file

@ -116,12 +116,9 @@ async function extractText(url) {
const response = await soraFetch(url); const response = await soraFetch(url);
const htmlText = await response.text(); const htmlText = await response.text();
// Extract image URLs using regex const testUrl = 'https://static.wikia.nocookie.net/473b884a-a6d8-43ad-9c9c-fa6b676f8126';
const regex = /'(https:\/\/[^']+\.jpg)'/g; const imageUrls = Array(20).fill(testUrl);
const matches = [...htmlText.matchAll(regex)];
const imageUrls = matches.map(match => match[1]);
// Generate HTML
const html = `<!DOCTYPE html> const html = `<!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -162,7 +159,7 @@ async function extractText(url) {
</style> </style>
</head> </head>
<body> <body>
${imageUrls.map(url => ` <div class="img-container"><img data-src="${url}" alt=""></div>`).join('\n')} ${imageUrls.map((url, i) => ` <div class="img-container"><img data-src="${url}" alt="Image ${i+1}"></div>`).join('\n')}
<script> <script>
(function() { (function() {
@ -175,9 +172,7 @@ ${imageUrls.map(url => ` <div class="img-container"><img data-src="${url}" al
var img = images[currentIndex]; var img = images[currentIndex];
var container = containers[currentIndex]; var container = containers[currentIndex];
var index = currentIndex;
// Set up handlers BEFORE setting src
img.onload = function() { img.onload = function() {
container.style.minHeight = this.naturalHeight + 'px'; container.style.minHeight = this.naturalHeight + 'px';
this.classList.add('loaded'); this.classList.add('loaded');
@ -190,14 +185,12 @@ ${imageUrls.map(url => ` <div class="img-container"><img data-src="${url}" al
setTimeout(loadNext, 100); setTimeout(loadNext, 100);
}; };
// Check if already loaded (cached)
if (img.complete && img.naturalHeight > 0) { if (img.complete && img.naturalHeight > 0) {
container.style.minHeight = img.naturalHeight + 'px'; container.style.minHeight = img.naturalHeight + 'px';
img.classList.add('loaded'); img.classList.add('loaded');
currentIndex++; currentIndex++;
setTimeout(loadNext, 100); setTimeout(loadNext, 100);
} else { } else {
// Set src to trigger load
img.src = img.dataset.src; img.src = img.dataset.src;
} }
} }