|
|
| Ligne 53 : |
Ligne 53 : |
| rel: 'noopener noreferrer' | | rel: 'noopener noreferrer' |
| }); | | }); |
| }
| |
| });
| |
| });
| |
| mw.loader.using('mediawiki.util', function () {
| |
| document.addEventListener('DOMContentLoaded', function () {
| |
| const input = document.getElementById('zurl');
| |
| const button = document.getElementById('zurl-button');
| |
| const result = document.getElementById('zotero-formlink-result');
| |
|
| |
| if (!input || !button || !result) return;
| |
|
| |
| button.addEventListener('click', function () {
| |
| const url = input.value.trim();
| |
| const itemKey = extractItemKey(url);
| |
| if (!itemKey.match(/^[A-Z0-9]+$/)) {
| |
| result.innerHTML = '<p style="color:red;">Clé Zotero invalide.</p>';
| |
| return;
| |
| }
| |
|
| |
| const apiUrl = `https://api.zotero.org/groups/4893620/items/${itemKey}?include=data`;
| |
| fetch(apiUrl)
| |
| .then(res => res.json())
| |
| .then(data => {
| |
| const caseName = (data.data && data.data.caseName) ? data.data.caseName : "NomInconnu";
| |
| const clean = caseName.replace(/[\[\]{}<>#%|^~`]/g, '').trim();
| |
| const title = encodeURIComponent(clean);
| |
| const formUrl = `/index.php?title=${title}&action=formedit&form=Décision_provenant_de_Zotero`;
| |
| result.innerHTML = `<p><a href="${formUrl}">Créer la page « ${clean} »</a></p>`;
| |
| })
| |
| .catch(() => {
| |
| result.innerHTML = '<p style="color:red;">Erreur lors de l’appel Zotero.</p>';
| |
| });
| |
| });
| |
|
| |
| function extractItemKey(url) {
| |
| const parts = url.split('/');
| |
| return (parts.length >= 8) ? parts[7].split('?')[0] : '';
| |
| } | | } |
| }); | | }); |
| }); | | }); |