MediaWiki:CardToImage.js: mudanças entre as edições

sem sumário de edição
Sem resumo de edição
Sem resumo de edição
 
/* jshint esversion: 810 */
/**
* Convert a base64 string in a Blob according to the data and contentType.
*/
function cardToImage() {
function b64toBlob(b64Data, contentType = '', sliceSize = 512) {
"use strict";
const byteCharacters = atob(b64Data);
function b64toBlob(b64Data, contentType, sliceSize) {
letconst byteArrays = [];
contentType = contentType || "";
sliceSize = sliceSize || 512;
 
for (let offset = let0; offset < byteCharacters.length; offset += atob(b64DatasliceSize); {
const slice = byteCharacters.slice(offset, offset + sliceSize);
let byteArrays = [];
 
const for (let offsetbyteNumbers = 0;new offset < byteCharactersArray(slice.length); offset += sliceSize) {
for (let i = 0; i let< slice = byteCharacters.slice(offset, offsetlength; i++) sliceSize);{
byteNumbers[i] = slice.charCodeAt(i);
}
 
const let byteNumbersbyteArray = new ArrayUint8Array(slice.lengthbyteNumbers);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
 
byteArrays.push(byteArray);
let byteArray = new Uint8Array(byteNumbers);
}
 
letconst blob = new Blob(byteArrays, { type: contentType });
byteArrays.push(byteArray);
return }blob;
}
 
// Generate screenshot and download
let blob = new Blob(byteArrays, {type: contentType});
let const opt = {
return blob;
}
 
// Generate screenshot and download
let opt = {
scrollX: -window.scrollX,
scrollY: -window.scrollY,
};
let const element = document.getElementById("'cardCatalog"');
html2canvas(element, opt).then(function (canvas) {
// Generate the base64 representation of the canvas
letconst base64image = canvas.toDataURL("'image/png"');
 
// Split the base64 string in data and contentType
letconst block = base64image.split("';"');
// Get the content type
letconst mimeType = block[0].split("':"')[1]; // In this case "image/png"
// get the real base64 content of the file
letconst realData = block[1].split("',"')[1]; // For example: iVBORw0KGgouqw23....
 
// Convert b64 to blob and store it into a variable (with real base64 as value)
letconst canvasBlob = b64toBlob(realData, mimeType);
 
// Generate file download
window.saveAs(canvasBlob, "'Ficha.png"');
});
 
}