MediaWiki:Common.js: Difference between revisions
OMNIVERSE
No edit summary |
No edit summary |
||
| Line 10: | Line 10: | ||
console.log('changeImageLinks function called!'); | console.log('changeImageLinks function called!'); | ||
// Find all links that go to File: pages | |||
var imageLinks = document.querySelectorAll('a[href*="/File:"]'); | var imageLinks = document.querySelectorAll('a[href*="/File:"]'); | ||
console.log('Found ' + imageLinks.length + ' File: links'); | console.log('Found ' + imageLinks.length + ' File: links'); | ||
imageLinks.forEach(function(link) { | imageLinks.forEach(function(link, index) { | ||
var img = link.querySelector('img'); | var img = link.querySelector('img'); | ||
if (img) { | if (img) { | ||
var src = img.getAttribute('src'); | var src = img.getAttribute('src'); | ||
console.log('Original src:', src); | console.log('Link ' + index + ' - Original href:', link.href); | ||
console.log('Link ' + index + ' - Image src:', src); | |||
// Remove /thumb/ and the | // Extract the full image path from src | ||
var fullSrc = src.replace(/\/thumb\/ | // Remove /thumb/ and everything after the last / | ||
var fullSrc = src.replace(/\/thumb(\/.*\/).*$/, '$1'); | |||
// Extract just the filename from the File: link | |||
var filename = link.href.split('/File:')[1]; | |||
if (filename) { | |||
filename = decodeURIComponent(filename); | |||
fullSrc = fullSrc + filename; | |||
} | |||
console.log('Changed to:', fullSrc); | console.log('Link ' + index + ' - Changed to:', fullSrc); | ||
link. | link.href = fullSrc; | ||
} | } | ||
}); | }); | ||
} | } | ||
Revision as of 03:13, 25 January 2026
console.log('Common.js is loading!');
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', changeImageLinks);
} else {
changeImageLinks();
}
function changeImageLinks() {
console.log('changeImageLinks function called!');
// Find all links that go to File: pages
var imageLinks = document.querySelectorAll('a[href*="/File:"]');
console.log('Found ' + imageLinks.length + ' File: links');
imageLinks.forEach(function(link, index) {
var img = link.querySelector('img');
if (img) {
var src = img.getAttribute('src');
console.log('Link ' + index + ' - Original href:', link.href);
console.log('Link ' + index + ' - Image src:', src);
// Extract the full image path from src
// Remove /thumb/ and everything after the last /
var fullSrc = src.replace(/\/thumb(\/.*\/).*$/, '$1');
// Extract just the filename from the File: link
var filename = link.href.split('/File:')[1];
if (filename) {
filename = decodeURIComponent(filename);
fullSrc = fullSrc + filename;
}
console.log('Link ' + index + ' - Changed to:', fullSrc);
link.href = fullSrc;
}
});
}
