User:Célian/common.js

From Test Wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
importScript:('user:Célian/test.js');
$(function () {
    if (mw.config.get('wgCanonicalSpecialPageName') !== 'Recentchanges') return;

    const seuilCaractères = 200;
    const userIsAdmin = mw.config.get('wgUserGroups').includes('sysop');

    $('.mw-changeslist-line-inner').each(function () {
        const $ligne = $(this);
        const estCreation = $ligne.find('.mw-changeslist-separator + .newpage').length > 0;
        const lienDiff = $ligne.find('a.mw-changeslist-diff').attr('href');

        if (estCreation && lienDiff) {
            fetch(lienDiff + '&action=raw')
                .then(res => res.text())
                .then(contenuPage => {
                    if (contenuPage.length < seuilCaractères) {
                        $ligne.css('background-color', '#fff3c4'); // jaune pâle
                        $ligne.prepend('⚠️ Article très court ');

                        if (userIsAdmin) {
                            const pageName = mw.util.getParamValue('title', lienDiff);
                            if (pageName) {
                                const bouton = $('<a>')
                                    .text('🗑️ Supprimer')
                                    .attr('href', mw.util.getUrl('Special:Delete/' + pageName))
                                    .css({
                                        'margin-left': '10px',
                                        'color': 'red',
                                        'font-weight': 'bold',
                                        'text-decoration': 'none'
                                    });
                                $ligne.append(bouton);
                            }
                        }
                    }
                });
        }
    });
});