MediaWiki:ChapterSlides.js
From Illustrations in German Translations of Mark Twain's Works
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Acht feste Illustratoren definieren
const chapter_illustrators = [
"Kemble",
"Schroedter",
"Hirth",
"Busoni",
"Kellerer",
"Harder",
"Trier",
"Bebié"
];
// Bildlisten und aktuelle Indizes
let chapter_slides = {};
let chapter_currentIndex = {};
chapter_illustrators.forEach(name => {
chapter_slides[name] = [];
chapter_currentIndex[name] = 0;
});
// Eingabe verarbeiten
function chapter_loadSlideshowsByChapter() {
const chapterInput = document.getElementById("chapterInput").value.trim();
const chapterNumber = parseInt(chapterInput, 10);
if (isNaN(chapterNumber) || chapterNumber < 1 || chapterNumber > 43) {
alert("Please enter a number between 1 and 43.");
return;
}
const chapterTag = "ch" + String(chapterNumber).padStart(3, "0");
// Tabelle durchsuchen
const rows = document.querySelectorAll("#catalog tbody tr");
chapter_illustrators.forEach(name => {
chapter_slides[name] = [];
chapter_currentIndex[name] = 0;
const imageElement = document.getElementById("slide-" + name);
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const illustratorCell = row.cells[2];
const idCell = row.cells[8];
const illustratorText = illustratorCell ? illustratorCell.textContent.trim().toLowerCase() : "";
const idLink = idCell ? idCell.getElementsByTagName("a")[0] : null;
const idText = idLink ? idLink.textContent.trim().toLowerCase() : "";
if (
illustratorText.indexOf(name.toLowerCase()) !== -1 &&
idText.indexOf(chapterTag) !== -1
) {
chapter_slides[name].push(idText);
}
}
if (chapter_slides[name].length === 0) {
imageElement.src = "https://illus.twainframe.org/images/2/2b/ChapterPlaceholder.png";
imageElement.title = "No matching images found.";
chapter_updateCounter(name); // Counter aktualisieren
} else {
chapter_showSlide(name, 0);
}
});
}
// Ein Bild anzeigen
function chapter_showSlide(illustrator, index) {
const imageElement = document.getElementById("slide-" + illustrator);
const slideArray = chapter_slides[illustrator];
if (!imageElement || slideArray.length === 0) return;
chapter_currentIndex[illustrator] = (index + slideArray.length) % slideArray.length;
const imageId = slideArray[chapter_currentIndex[illustrator]];
imageElement.src = "/index.php/Special:Redirect/file/" + imageId + ".jpg";
imageElement.alt = imageId;
imageElement.title = imageId;
// Beim Klick die File-Seite öffnen
imageElement.style.cursor = "pointer";
imageElement.onclick = function () {
window.open("/File:" + imageId, "_blank");
};
// Counter aktualisieren
chapter_updateCounter(illustrator);
// MediaInfo laden, ohne Vergleichsskript zu stören
if (typeof comparison_showMediaInfo === "function") {
comparison_showMediaInfo(illustrator, imageId + ".jpg");
}
}
// Counter aktualisieren
function chapter_updateCounter(illustrator) {
const counterElement = document.getElementById("counter-" + illustrator);
const slideArray = chapter_slides[illustrator];
const index = chapter_currentIndex[illustrator];
if (counterElement) {
if (slideArray.length === 0) {
counterElement.textContent = "0/0";
} else {
counterElement.textContent = (index + 1) + "/" + slideArray.length;
}
}
}
// Buttons
function chapter_nextSlide(illustrator) {
chapter_showSlide(illustrator, chapter_currentIndex[illustrator] + 1);
}
function chapter_prevSlide(illustrator) {
chapter_showSlide(illustrator, chapter_currentIndex[illustrator] - 1);
}