Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 25 : | Ligne 25 : | ||
document.getElementById("mw-pages").innerHTML = ""; | document.getElementById("mw-pages").innerHTML = ""; | ||
} | } | ||
$(function () { | |||
// Ne rien faire sauf si on est sur une page de contenu | |||
if (mw.config.get('wgNamespaceNumber') !== 0) return; | |||
const pageId = mw.config.get('wgArticleId'); | |||
const html = ` | |||
<div id="comment-form" style="margin-top:2em;"> | |||
<h3>💬 Commenter cette page</h3> | |||
<input type="text" id="comment-user" placeholder="Votre nom" style="width:100%; margin-bottom:8px;" /> | |||
<textarea id="comment-text" placeholder="Votre commentaire" style="width:100%; height:80px;"></textarea> | |||
<br /> | |||
<button id="submit-comment">Envoyer</button> | |||
</div> | |||
<div id="comment-list" style="margin-top:1em;"></div> | |||
`; | |||
// Ajoute le HTML en bas de la page | |||
$('#mw-content-text').append(html); | |||
function loadComments() { | |||
// Exemple : appel à une API personnalisée | |||
fetch(`/index.php?title=API:Custom&action=raw&function=loadComments&pageid=${pageId}`) | |||
.then(r => r.text()) | |||
.then(html => { | |||
document.getElementById('comment-list').innerHTML = html; | |||
}); | |||
} | |||
$('#submit-comment').on('click', function () { | |||
const user = $('#comment-user').val(); | |||
const text = $('#comment-text').val(); | |||
if (!text) return alert("Merci d'entrer un commentaire."); | |||
fetch('/api.php?action=postcomment&format=json', { | |||
method: 'POST', | |||
headers: { | |||
'Content-Type': 'application/x-www-form-urlencoded', | |||
'Api-User-Agent': 'CustomComment', | |||
'X-CSRF-Token': mw.user.tokens.get('csrfToken') | |||
}, | |||
body: `pageid=${pageId}&username=${encodeURIComponent(user)}&comment=${encodeURIComponent(text)}` | |||
}) | |||
.then(res => res.json()) | |||
.then(() => { | |||
$('#comment-text').val(''); | |||
loadComments(); | |||
}); | |||
}); | |||
loadComments(); | |||
}); |
Version du 13 mai 2025 à 11:52
/* Tout JavaScript présent ici sera exécuté par tous les utilisateurs à chaque chargement de page. */
var userID = mw.config.get("wgUserId");
if(userID == null){
// Suppression du bouton "Nouveau"
var xpathExpression = "/html/body/div[2]/nav/div/div[3]/ul/li[2]/div";
// Use document.evaluate to find the element
var result = document.evaluate(xpathExpression, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
// Check if an element was found
if (result.singleNodeValue) {
// Remove the element from the DOM
result.singleNodeValue.remove();
}
// Suppression du bouton "Roue dentée"
var xpathExpression2 = "/html/body/div[2]/nav/div/div[3]/ul/li[3]";
var result = document.evaluate(xpathExpression2, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (result.singleNodeValue) {
// Remove the element from the DOM
result.singleNodeValue.remove();
}
}
if(window.location.href.includes("Contact")){
document.getElementById("ooui-php-5").rows = 6;
}
if(window.location.href.includes("Cat%C3%A9gorie:19") || window.location.href.includes("Cat%C3%A9gorie:20")){
document.getElementById("mw-pages").innerHTML = "";
}
$(function () {
// Ne rien faire sauf si on est sur une page de contenu
if (mw.config.get('wgNamespaceNumber') !== 0) return;
const pageId = mw.config.get('wgArticleId');
const html = `
<div id="comment-form" style="margin-top:2em;">
<h3>💬 Commenter cette page</h3>
<input type="text" id="comment-user" placeholder="Votre nom" style="width:100%; margin-bottom:8px;" />
<textarea id="comment-text" placeholder="Votre commentaire" style="width:100%; height:80px;"></textarea>
<br />
<button id="submit-comment">Envoyer</button>
</div>
<div id="comment-list" style="margin-top:1em;"></div>
`;
// Ajoute le HTML en bas de la page
$('#mw-content-text').append(html);
function loadComments() {
// Exemple : appel à une API personnalisée
fetch(`/index.php?title=API:Custom&action=raw&function=loadComments&pageid=${pageId}`)
.then(r => r.text())
.then(html => {
document.getElementById('comment-list').innerHTML = html;
});
}
$('#submit-comment').on('click', function () {
const user = $('#comment-user').val();
const text = $('#comment-text').val();
if (!text) return alert("Merci d'entrer un commentaire.");
fetch('/api.php?action=postcomment&format=json', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Api-User-Agent': 'CustomComment',
'X-CSRF-Token': mw.user.tokens.get('csrfToken')
},
body: `pageid=${pageId}&username=${encodeURIComponent(user)}&comment=${encodeURIComponent(text)}`
})
.then(res => res.json())
.then(() => {
$('#comment-text').val('');
loadComments();
});
});
loadComments();
});