MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
if (document.querySelector("#P200")){ | if (document.querySelector("#P200")){ | ||
let p200Container = document.querySelector("#P200") | let p200Container = document.querySelector("#P200"); | ||
let aLinks = p200Container.querySelectorAll("a") | let aLinks = p200Container.querySelectorAll("a"); | ||
let urls = [] | let urls = []; | ||
for (let el of aLinks){ | for (let el of aLinks){ | ||
if (el.getAttribute('href') && (el.getAttribute('href').toLowerCase().endsWith('.png') || el.getAttribute('href').toLowerCase().endsWith('.jpg') || el.getAttribute('href').toLowerCase().endsWith('.jpeg') ) ){ | if (el.getAttribute('href') && (el.getAttribute('href').toLowerCase().endsWith('.png') || el.getAttribute('href').toLowerCase().endsWith('.jpg') || el.getAttribute('href').toLowerCase().endsWith('.jpeg') ) ){ | ||
urls.push(el.getAttribute('href')) | urls.push(el.getAttribute('href')); | ||
} | } | ||
} | } | ||
let imageContainer = document.createElement('div') | let imageContainer = document.createElement('div'); | ||
imageContainer.classList.add('wikibase-statementgroupview') | imageContainer.classList.add('wikibase-statementgroupview'); | ||
imageContainer.innerHTML = "" | imageContainer.innerHTML = ""; | ||
for (let url of urls){ | for (let url of urls){ | ||
let img = document.createElement('img') | let img = document.createElement('img'); | ||
img.style.width = "95%" | img.style.width = "95%"; | ||
img.style.height = "auto" | img.style.height = "auto"; | ||
img.style.marginTop="0.2em" | img.style.marginTop="0.2em"; | ||
img.style.marginBottom="0.2em" | img.style.marginBottom="0.2em"; | ||
img.setAttribute('src',url) | img.setAttribute('src',url); | ||
let a = document.createElement('a') | let a = document.createElement('a'); | ||
a.setAttribute('href',url) | a.setAttribute('href',url); | ||
a.setAttribute('target','_blank') | a.setAttribute('target','_blank'); | ||
a.appendChild(img) | a.appendChild(img); | ||
imageContainer.appendChild(a) | imageContainer.appendChild(a); | ||
} | } | ||
//imageContainer.style.border = "1px solid #c8ccd1" | //imageContainer.style.border = "1px solid #c8ccd1" | ||
imageContainer.style.borderBottom = "none" | imageContainer.style.borderBottom = "none"; | ||
imageContainer.style.marginBottom = 0 | imageContainer.style.marginBottom = 0; | ||
imageContainer.style.textAlign = 'center' | imageContainer.style.textAlign = 'center'; | ||
imageContainer.style.width = '100%' | imageContainer.style.width = '100%'; | ||
imageContainer.style.backgroundColor = '#eaecf0' | imageContainer.style.backgroundColor = '#eaecf0'; | ||
document.querySelector(".wikibase-listview").insertBefore(imageContainer, p200Container); | document.querySelector(".wikibase-listview").insertBefore(imageContainer, p200Container); | ||
} | } |
Revision as of 20:44, 3 May 2024
/* Any JavaScript here will be loaded for all users on every page load. */
if (document.querySelector("#P200")){
let p200Container = document.querySelector("#P200");
let aLinks = p200Container.querySelectorAll("a");
let urls = [];
for (let el of aLinks){
if (el.getAttribute('href') && (el.getAttribute('href').toLowerCase().endsWith('.png') || el.getAttribute('href').toLowerCase().endsWith('.jpg') || el.getAttribute('href').toLowerCase().endsWith('.jpeg') ) ){
urls.push(el.getAttribute('href'));
}
}
let imageContainer = document.createElement('div');
imageContainer.classList.add('wikibase-statementgroupview');
imageContainer.innerHTML = "";
for (let url of urls){
let img = document.createElement('img');
img.style.width = "95%";
img.style.height = "auto";
img.style.marginTop="0.2em";
img.style.marginBottom="0.2em";
img.setAttribute('src',url);
let a = document.createElement('a');
a.setAttribute('href',url);
a.setAttribute('target','_blank');
a.appendChild(img);
imageContainer.appendChild(a);
}
//imageContainer.style.border = "1px solid #c8ccd1"
imageContainer.style.borderBottom = "none";
imageContainer.style.marginBottom = 0;
imageContainer.style.textAlign = 'center';
imageContainer.style.width = '100%';
imageContainer.style.backgroundColor = '#eaecf0';
document.querySelector(".wikibase-listview").insertBefore(imageContainer, p200Container);
}