MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 116: | Line 116: | ||
var thumbnailContainer = document.createElement('div') | var thumbnailContainer = document.createElement('div') | ||
thumbnailContainer.style.width ='100%' | thumbnailContainer.style.width ='100%' | ||
thumbnailContainer.style.textAlign ='center' | |||
var thumbImg = document.createElement('img') | var thumbImg = document.createElement('img') | ||
thumbImg.setAttribute('src',urls[0]) | thumbImg.setAttribute('src',urls[0]) |
Revision as of 21:08, 3 May 2024
if (document.querySelector("#P200")){
var p200Container = document.querySelector("#P200");
var p200Container = document.querySelector("#P200");
var aLinks = p200Container.querySelectorAll("a");
var urls = [];
for (var el = 0; el < aLinks.length; el++) {
if (aLinks[el].getAttribute('href') && (aLinks[el].getAttribute('href').toLowerCase().endsWith('.png') || aLinks[el].getAttribute('href').toLowerCase().endsWith('.jpg') || aLinks[el].getAttribute('href').toLowerCase().endsWith('.jpeg') ) ){
urls.push(aLinks[el].getAttribute('href'));
}
}
var imageContainer = document.createElement('div');
imageContainer.classList.add('wikibase-statementgroupview');
imageContainer.innerHTML = "";
for (var url in urls){
var 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',urls[url]);
var a = document.createElement('a');
a.setAttribute('href',urls[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);
}
// ---------------
if (document.querySelector("#P20")){
var downloadBlockText = function(){
var p20Container = document.querySelector("#P20")
var aLinks = p20Container.querySelectorAll("a")
var urls = []
for (var i = 0; i < aLinks.length; i++) {
if (aLinks[i].getAttribute('href') && aLinks[i].getAttribute('href').indexOf('semlab.s3.amazonaws.com/texts/') >-1){
urls.push(aLinks[i].getAttribute('href'))
}
}
var textContainer = document.createElement('div')
textContainer.classList.add('wikibase-statementgroupview')
textContainer.innerHTML = ""
var request = new XMLHttpRequest();
request.open('GET', urls[0], true);
request.onload = function () {
if (this.status >= 200 && this.status < 400) {
// Success!
document.querySelector("#P19").remove()
var text = this.response
var textBlock = document.createElement('pre')
textBlock.style.marginBottom=0
textBlock.innerText = text
textBlock.style.marginTop = 0
textContainer.appendChild(textBlock)
textContainer.style.marginBottom = 0
textContainer.style.borderBottom = "none"
document.querySelector(".wikibase-listview").insertBefore(textContainer, p20Container);
} else {
// We reached our target server, but it returned an error
}
};
request.onerror = function () {
// There was a connection error of some sort
};
request.send();
}
downloadBlockText()
}
// ---------------------
if (document.querySelector("#P3")){
var instanceOf = []
if (document.querySelector("#P1")){
var els = document.querySelector("#P1").querySelectorAll("a")
for (var i = 0; i < els.length; i++) {
if (els[i].getAttribute('href') && (els[i].getAttribute('href').indexOf('wiki/Item') >-1 ) ){
instanceOf.push(els[i].getAttribute('href').split(":")[1])
}
}
}
var P3Container = document.querySelector("#P3")
var aLinks = P3Container.querySelectorAll("a")
var urls = []
for (var i = 0; i < aLinks.length; i++) {
if (aLinks[i].getAttribute('href') && (aLinks[i].getAttribute('href').toLowerCase().endsWith('.png') || aLinks[i].getAttribute('href').toLowerCase().endsWith('.jpg') || aLinks[i].getAttribute('href').toLowerCase().endsWith('.jpeg') ) ){
urls.push(aLinks[i].getAttribute('href'))
}
}
if (urls.length>0){
var thumbnailContainer = document.createElement('div')
thumbnailContainer.style.width ='100%'
thumbnailContainer.style.textAlign ='center'
var thumbImg = document.createElement('img')
thumbImg.setAttribute('src',urls[0])
thumbImg.style.maxHeight = '250px'
thumbImg.style.objectFit = 'contain'
thumbImg.style.border = "1px solid #c8ccd1"
if (instanceOf.indexOf('Q1')>-1){
thumbImg.style.borderRadius = '15em'
}
thumbnailContainer.appendChild(thumbImg)
var hr = document.createElement('hr')
hr.style.marginTop = "0.5em"
hr.style.marginBottom = "0.5em"
// hr.style.backgroundColor = '#eaecf0'
thumbnailContainer.appendChild(hr)
document.querySelector(".wikibase-entityview-side").appendChild(thumbnailContainer)
}
}