|
|
Ligne 1 : |
Ligne 1 : |
| $(function() {
| |
| // Ajouter un lien "Téléversement multiple" à la barre latérale
| |
| var sidebarLink = $('<li>').append(
| |
| $('<a>').attr('href', '#').text('Téléversement multiple')
| |
| );
| |
|
| |
|
| $('#p-Contribuer ul').append(sidebarLink);
| |
|
| |
| // Lorsque le lien est cliqué, ouvrir le sélecteur de fichiers
| |
| sidebarLink.on('click', function(event) {
| |
| event.preventDefault();
| |
|
| |
| var fileInput = $('<input>').attr({
| |
| 'type': 'file',
| |
| 'multiple': 'multiple'
| |
| }).css('display', 'none');
| |
|
| |
| fileInput.on('change', function(event) {
| |
| var files = event.target.files;
| |
| if (files.length > 0) {
| |
| showOptionModal(files);
| |
| }
| |
| });
| |
|
| |
| fileInput.click();
| |
| });
| |
|
| |
| function showOptionModal(files) {
| |
| var modal = $('<div>').css({
| |
| 'position': 'fixed',
| |
| 'top': '50%',
| |
| 'left': '50%',
| |
| 'transform': 'translate(-50%, -50%)',
| |
| 'background-color': '#FFF',
| |
| 'padding': '20px',
| |
| 'box-shadow': '0px 0px 20px rgba(0, 0, 0, 0.3)',
| |
| 'z-index': '1001',
| |
| 'width': '300px',
| |
| 'border-radius': '10px',
| |
| 'font-family': 'Arial, sans-serif',
| |
| 'color': '#333'
| |
| });
| |
|
| |
| var title = $('<h2>').text('Choisir une option').css({
| |
| 'margin-top': '0',
| |
| 'font-size': '24px',
| |
| 'color': '#333',
| |
| 'text-align': 'center'
| |
| });
| |
|
| |
| var perFileBtn = $('<button>').text('Description par fichier').css({
| |
| 'padding': '10px',
| |
| 'margin': '10px',
| |
| 'background-color': '#333',
| |
| 'color': '#FFF',
| |
| 'border': 'none',
| |
| 'border-radius': '5px',
| |
| 'cursor': 'pointer',
| |
| 'width': '100%'
| |
| });
| |
|
| |
| var globalDescriptionBtn = $('<button>').text('Description globale').css({
| |
| 'padding': '10px',
| |
| 'margin': '10px',
| |
| 'background-color': '#333',
| |
| 'color': '#FFF',
| |
| 'border': 'none',
| |
| 'border-radius': '5px',
| |
| 'cursor': 'pointer',
| |
| 'width': '100%'
| |
| });
| |
|
| |
| perFileBtn.on('click', function() {
| |
| modal.remove();
| |
| handleFiles(files);
| |
| });
| |
|
| |
| globalDescriptionBtn.on('click', function() {
| |
| modal.remove();
| |
| createGlobalDescriptionModal(files);
| |
| });
| |
|
| |
| modal.append(title, perFileBtn, globalDescriptionBtn);
| |
| $('body').append(modal);
| |
| }
| |
|
| |
| function handleFiles(files) {
| |
| $.each(files, function(index, file) {
| |
| createUploadModal(file);
| |
| });
| |
| }
| |
|
| |
| function createUploadModal(file) {
| |
| var modal = $('<div>').css({
| |
| 'position': 'fixed',
| |
| 'top': '50%',
| |
| 'left': '50%',
| |
| 'transform': 'translate(-50%, -50%)',
| |
| 'background-color': '#FFF',
| |
| 'padding': '20px',
| |
| 'box-shadow': '0px 0px 20px rgba(0, 0, 0, 0.3)',
| |
| 'z-index': '1001',
| |
| 'width': '500px',
| |
| 'border-radius': '10px',
| |
| 'font-family': 'Arial, sans-serif',
| |
| 'color': '#333'
| |
| });
| |
|
| |
| var titleBar = $('<div>').css({
| |
| 'display': 'flex',
| |
| 'justify-content': 'space-between',
| |
| 'align-items': 'center'
| |
| });
| |
|
| |
| var title = $('<h2>').text('Téléverser un fichier').css({
| |
| 'margin-top': '0',
| |
| 'font-size': '24px',
| |
| 'color': '#333'
| |
| });
| |
|
| |
| var closeButton = $('<button>').text('X').css({
| |
| 'background': 'none',
| |
| 'border': 'none',
| |
| 'color': '#333',
| |
| 'font-size': '18px',
| |
| 'cursor': 'pointer'
| |
| });
| |
|
| |
| closeButton.on('click', function() {
| |
| modal.remove();
| |
| });
| |
|
| |
| titleBar.append(title, closeButton);
| |
|
| |
| var fileNameLabel = $('<label>').text('Nom du fichier').css({
| |
| 'display': 'block',
| |
| 'margin-bottom': '5px',
| |
| 'font-weight': 'bold'
| |
| });
| |
|
| |
| var fileNameInput = $('<input>').attr('type', 'text').val(file.name).css({
| |
| 'width': '100%',
| |
| 'padding': '10px',
| |
| 'margin-bottom': '10px',
| |
| 'box-sizing': 'border-box',
| |
| 'border': '1px solid #CCC',
| |
| 'border-radius': '5px'
| |
| });
| |
|
| |
| var descriptionLabel = $('<label>').text('Description du fichier').css({
| |
| 'display': 'block',
| |
| 'margin-bottom': '5px',
| |
| 'font-weight': 'bold'
| |
| });
| |
|
| |
| var descriptionInput = $('<textarea>').attr('placeholder', 'Entrer la description du fichier').css({
| |
| 'width': '100%',
| |
| 'height': '150px',
| |
| 'padding': '10px',
| |
| 'margin-bottom': '10px',
| |
| 'box-sizing': 'border-box',
| |
| 'border': '1px solid #CCC',
| |
| 'border-radius': '5px'
| |
| });
| |
|
| |
| var buttonContainer = $('<div>').css({
| |
| 'text-align': 'right'
| |
| });
| |
|
| |
| var uploadBtn = $('<button>').text('Téléverser').css({
| |
| 'padding': '10px 20px',
| |
| 'background-color': '#333',
| |
| 'color': '#FFF',
| |
| 'border': 'none',
| |
| 'border-radius': '5px',
| |
| 'cursor': 'pointer',
| |
| 'font-size': '16px',
| |
| 'margin-right': '10px'
| |
| });
| |
|
| |
| var cancelBtn = $('<button>').text('Annuler').css({
| |
| 'padding': '10px 20px',
| |
| 'background-color': '#CCC',
| |
| 'color': '#000',
| |
| 'border': 'none',
| |
| 'border-radius': '5px',
| |
| 'cursor': 'pointer',
| |
| 'font-size': '16px'
| |
| });
| |
|
| |
| uploadBtn.on('click', function() {
| |
| uploadFile(file, fileNameInput.val(), descriptionInput.val(), modal);
| |
| });
| |
|
| |
| cancelBtn.on('click', function() {
| |
| modal.remove();
| |
| });
| |
|
| |
| buttonContainer.append(uploadBtn, cancelBtn);
| |
| modal.append(titleBar, fileNameLabel, fileNameInput, descriptionLabel, descriptionInput, buttonContainer);
| |
| $('body').append(modal);
| |
| }
| |
|
| |
| function createGlobalDescriptionModal(files) {
| |
| var modal = $('<div>').css({
| |
| 'position': 'fixed',
| |
| 'top': '50%',
| |
| 'left': '50%',
| |
| 'transform': 'translate(-50%, -50%)',
| |
| 'background-color': '#FFF',
| |
| 'padding': '20px',
| |
| 'box-shadow': '0px 0px 20px rgba(0, 0, 0, 0.3)',
| |
| 'z-index': '1001',
| |
| 'width': '500px',
| |
| 'border-radius': '10px',
| |
| 'font-family': 'Arial, sans-serif',
| |
| 'color': '#333'
| |
| });
| |
|
| |
| var titleBar = $('<div>').css({
| |
| 'display': 'flex',
| |
| 'justify-content': 'space-between',
| |
| 'align-items': 'center'
| |
| });
| |
|
| |
| var title = $('<h2>').text('Téléverser des fichiers').css({
| |
| 'margin-top': '0',
| |
| 'font-size': '24px',
| |
| 'color': '#333'
| |
| });
| |
|
| |
| var closeButton = $('<button>').text('X').css({
| |
| 'background': 'none',
| |
| 'border': 'none',
| |
| 'color': '#333',
| |
| 'font-size': '18px',
| |
| 'cursor': 'pointer'
| |
| });
| |
|
| |
| closeButton.on('click', function() {
| |
| modal.remove();
| |
| });
| |
|
| |
| titleBar.append(title, closeButton);
| |
|
| |
| var descriptionLabel = $('<label>').text('Description globale des fichiers').css({
| |
| 'display': 'block',
| |
| 'margin-bottom': '5px',
| |
| 'font-weight': 'bold'
| |
| });
| |
|
| |
| var descriptionInput = $('<textarea>').attr('placeholder', 'Entrer la description des fichiers').css({
| |
| 'width': '100%',
| |
| 'height': '150px',
| |
| 'padding': '10px',
| |
| 'margin-bottom': '10px',
| |
| 'box-sizing': 'border-box',
| |
| 'border': '1px solid #CCC',
| |
| 'border-radius': '5px'
| |
| });
| |
|
| |
| var buttonContainer = $('<div>').css({
| |
| 'text-align': 'right'
| |
| });
| |
|
| |
| var uploadBtn = $('<button>').text('Tout téléverser').css({
| |
| 'padding': '10px 20px',
| |
| 'background-color': '#333',
| |
| 'color': '#FFF',
| |
| 'border': 'none',
| |
| 'border-radius': '5px',
| |
| 'cursor': 'pointer',
| |
| 'font-size': '16px',
| |
| 'margin-right': '10px'
| |
| });
| |
|
| |
| var cancelBtn = $('<button>').text('Annuler').css({
| |
| 'padding': '10px 20px',
| |
| 'background-color': '#CCC',
| |
| 'color': '#000',
| |
| 'border': 'none',
| |
| 'border-radius': '5px',
| |
| 'cursor': 'pointer',
| |
| 'font-size': '16px'
| |
| });
| |
|
| |
| uploadBtn.on('click', function() {
| |
| uploadAllFilesSequentially(files, descriptionInput.val(), modal);
| |
| });
| |
|
| |
| cancelBtn.on('click', function() {
| |
| modal.remove();
| |
| });
| |
|
| |
| buttonContainer.append(uploadBtn, cancelBtn);
| |
| modal.append(titleBar, descriptionLabel, descriptionInput, buttonContainer);
| |
| $('body').append(modal);
| |
| }
| |
|
| |
| function uploadAllFilesSequentially(files, description, modal) {
| |
| var index = 0;
| |
|
| |
| function uploadNextFile() {
| |
| if (index < files.length) {
| |
| var file = files[index];
| |
| var formData = new FormData();
| |
| formData.append('file', file);
| |
| formData.append('filename', file.name);
| |
| formData.append('comment', description);
| |
| formData.append('action', 'upload');
| |
| formData.append('ignorewarnings', '1');
| |
| formData.append('format', 'json');
| |
| formData.append('token', mw.user.tokens.get('csrfToken'));
| |
|
| |
| $.ajax({
| |
| url: mw.util.wikiScript('api'),
| |
| type: 'POST',
| |
| data: formData,
| |
| processData: false,
| |
| contentType: false,
| |
| success: function(response) {
| |
| if (response.upload && response.upload.result === 'Success') {
| |
| console.log('Fichiers téléversés avec succès: ' + file.name);
| |
| } else {
| |
| console.error('Error uploading file: ' + file.name, response);
| |
| }
| |
| index++;
| |
| uploadNextFile();
| |
| },
| |
| error: function(xhr, status, error) {
| |
| console.error('Erreur lors du téléversement des fichiers: ' + file.name, error);
| |
| index++;
| |
| uploadNextFile();
| |
| }
| |
| });
| |
| } else {
| |
| alert('Tous les fichiers ont été téléversés avec succès');
| |
| modal.remove();
| |
| }
| |
| }
| |
|
| |
| uploadNextFile();
| |
| }
| |
|
| |
| function uploadFile(file, fileName, description, modal) {
| |
| var formData = new FormData();
| |
| formData.append('file', file);
| |
| formData.append('filename', fileName);
| |
| formData.append('comment', description);
| |
| formData.append('action', 'upload');
| |
| formData.append('ignorewarnings', '1');
| |
| formData.append('format', 'json');
| |
| formData.append('token', mw.user.tokens.get('csrfToken'));
| |
|
| |
| $.ajax({
| |
| url: mw.util.wikiScript('api'),
| |
| type: 'POST',
| |
| data: formData,
| |
| processData: false,
| |
| contentType: false,
| |
| success: function(response) {
| |
| if (response.upload && response.upload.result === 'Success') {
| |
| alert('Fichier téléversé avec succès ' + fileName);
| |
| } else {
| |
| alert('Erreur lors du téléversement du fichier: ' + fileName);
| |
| console.error(response);
| |
| }
| |
| modal.remove();
| |
| },
| |
| error: function(xhr, status, error) {
| |
| alert('Erreur lors du téléversement du fichier: ' + fileName);
| |
| console.error(error);
| |
| modal.remove();
| |
| }
| |
| });
| |
| }
| |
| });
| |
|
| |
| $(document).ready(function() {
| |
| // Vérifier si l'URL de la page actuelle correspond aux pages spécifiées
| |
| var currentUrl = window.location.href;
| |
| var validUrls = [
| |
| 'https://www.pokepedia.fr/Catégorie:Corporate_Art_de_Pokémon',
| |
| 'https://www.pokepedia.fr/Cat%C3%A9gorie:Corporate_Art_de_Pok%C3%A9mon'
| |
| ];
| |
|
| |
| if (validUrls.includes(currentUrl)) {
| |
| // Ajout de la barre de recherche en haut de la page
| |
| var searchBar = '<div id="custom-search-bar" style="margin-bottom: 20px;">' +
| |
| '<input type="text" id="search-term" placeholder="Entrez un terme...">' +
| |
| '<button id="search-button">Cherche !</button>' +
| |
| '</div>';
| |
| $('#content').prepend(searchBar);
| |
|
| |
| // Fonction de recherche et d'affichage
| |
| $('#search-button').click(function() {
| |
| var searchTerm = $('#search-term').val().toLowerCase();
| |
| if (!searchTerm) {
| |
| alert('Veuillez entrer un terme de recherche.');
| |
| return;
| |
| }
| |
|
| |
| // Fonction pour récupérer les fichiers MediaWiki via l'API
| |
| function fetchFiles(term) {
| |
| return $.ajax({
| |
| url: mw.util.wikiScript('api'),
| |
| data: {
| |
| action: 'query',
| |
| list: 'categorymembers',
| |
| cmtitle: 'Catégorie:Corporate_Art_de_Pokémon',
| |
| cmtype: 'file',
| |
| cmlimit: 'max',
| |
| format: 'json'
| |
| },
| |
| dataType: 'json'
| |
| });
| |
| }
| |
|
| |
| // Fonction pour filtrer et afficher les fichiers
| |
| function displayFiles(files) {
| |
| var galleryHtml = '<div class="mw-category-generated mw-category" style="margin-top: 20px;">';
| |
| galleryHtml += '<div class="gallery mw-gallery-traditional" style="display: flex; flex-wrap: wrap;">';
| |
| files.forEach(function(file) {
| |
| var fileName = file.title.toLowerCase();
| |
| if (fileName.includes('fichier:') && fileName.includes('-ca.png') && fileName.includes(searchTerm)) {
| |
| var fileUrl = mw.util.getUrl('Special:FilePath/' + file.title.replace('Fichier:', ''));
| |
| galleryHtml += '<div class="gallerybox" style="margin-right: 10px;">' +
| |
| '<div class="thumb">' +
| |
| '<div class="thumbinner" style="width: 180px;">' +
| |
| '<a href="' + mw.util.getUrl(file.title) + '" class="image">' +
| |
| '<img src="' + fileUrl + '" alt="' + file.title + '" width="180" height="180">' +
| |
| '</a>' +
| |
| '<div class="gallerytext">' +
| |
| '<p class="galleryfilename galleryfilename-truncate">' + file.title.replace('Fichier:', '') + '</p>' +
| |
| '</div>' +
| |
| '</div>' +
| |
| '</div>' +
| |
| '</div>';
| |
| }
| |
| });
| |
| galleryHtml += '</div></div>';
| |
| $('#mw-content-text').html(galleryHtml);
| |
| }
| |
|
| |
| // Effacer les résultats précédents
| |
| $('.mw-category-generated').remove();
| |
|
| |
| // Rechercher les fichiers et les afficher
| |
| fetchFiles(searchTerm).done(function(data) {
| |
| var files = data.query.categorymembers;
| |
| displayFiles(files);
| |
| }).fail(function() {
| |
| alert('Une erreur est survenue lors de la recherche des fichiers.');
| |
| });
| |
| });
| |
| }
| |
| });
| |