MediaWiki:Gadget-BulkUpload/Runtime.js

/** * Turns Special:BulkUpload into a bulk upload form. Filenames are kept as-is and all files will have the same information. * TODO: Fix error and success handling when ignoring warnings. * Created by SuperHamster on Nookipedia (https://nookipedia.com/wiki/User:SuperHamster) * Licensed under CC BY-SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0/) **/ (function {   "use strict";    document.title = "Bulk upload form - Animal Crossing Wiki - Nookipedia";    $('#firstHeading').html('Bulk upload form');    $('#bodyContent').empty;    $('#bodyContent').append(' Use this form to upload multiple files at once. Filenames are kept as-is and all files will have the same information. To cancel an upload that is in progress, simply navigate away from this page. ');   var htmlUploadForm = `  Files and info Select files:   File description 

Licensing
Ignore warnings (check to override existing files) Upload files Upload status Waiting for user to start upload. `;   $('#bodyContent').append(htmlUploadForm); document.getElementById('bulkUploadButton').addEventListener("click", function {        const api = new mw.Api;        var completed = 0;        document.getElementById('bulkUploadButton').disabled = true;        $('#bulkUploadStatus').empty;

function uploadFile(file, uploadParams, j) { setTimeout(function {	       	api.upload(file, Object.freeze(uploadParams)).always( (response) => { JSON.stringify(response); completed++; if (response.hasOwnProperty('upload') && upload.result == 'Success') { $('#bulkUploadStatus').append('Upload succeeded for ' + file.name + ' (' + completed + ' out of ' + files.length + ') '); } else { $('#bulkUploadStatus').append('Upload failed for ' + file.name + ' (' + completed + ' out of ' + files.length + ') '); }	               if (completed == files.length) { $('#bulkUploadStatus').append(' Done! '); document.getElementById('bulkUploadButton').disabled = false; }	           });        	}, 1000 * j); }       var files = $('#bulkUploadFiles')[0].files; for (var i = 0; i < files.length; i++) { var file = files[i]; var uploadParams = {}; if($('#bulkUploadIgnoreWarnings').is(':checked')) { uploadParams = { filename: file.name, text: $('#bulkUploadInfo').val, ignorewarnings: "yes", format: "json" };           } else { uploadParams = { filename: file.name, text: $('#bulkUploadInfo').val, format: "json" };           }        	uploadFile(file, uploadParams, i); }   }); });