MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 36: | Line 36: | ||
document.querySelector(".wikibase-listview").insertBefore(imageContainer, p200Container); | document.querySelector(".wikibase-listview").insertBefore(imageContainer, p200Container); | ||
} | } | ||
if (document.querySelector("#P20")){ | |||
let downloadBlockText = async function(){ | |||
let p20Container = document.querySelector("#P20") | |||
let aLinks = p20Container.querySelectorAll("a") | |||
let 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')) | |||
} | |||
} | |||
let textContainer = document.createElement('div') | |||
textContainer.classList.add('wikibase-statementgroupview') | |||
textContainer.innerHTML = "" | |||
for (let u in urls){ | |||
let textReq = await fetch(urls[u]) | |||
// if it worked remove the preview block text in P19 | |||
if (textReq.status == 200){ | |||
document.querySelector("#P19").remove() | |||
} | |||
let text = await textReq.text() | |||
let 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); | |||
} | |||
downloadBlockText() | |||
} |
Revision as of 20:54, 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")){
let downloadBlockText = async function(){
let p20Container = document.querySelector("#P20")
let aLinks = p20Container.querySelectorAll("a")
let 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'))
}
}
let textContainer = document.createElement('div')
textContainer.classList.add('wikibase-statementgroupview')
textContainer.innerHTML = ""
for (let u in urls){
let textReq = await fetch(urls[u])
// if it worked remove the preview block text in P19
if (textReq.status == 200){
document.querySelector("#P19").remove()
}
let text = await textReq.text()
let 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);
}
downloadBlockText()
}