User:BZPN/Zgłaszarka.js

From Test Wiki
Revision as of 20:08, 4 October 2024 by BZPN (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
mw.loader.using(['oojs-ui', 'mediawiki.util']).done(function () {
    function addReportButton() {
        // Znajdź każdą edycję
        $('.mw-changeslist-diff').each(function () {
            var diffUrl = $(this).attr('href');
            var diffNumber = diffUrl.match(/diff=(\d+)/)[1];

            // Dodaj przycisk, jeśli go jeszcze nie ma
            if ($(this).siblings('.pt-report').length === 0) {
                var $button = $('<a>')
                    .attr('href', '#')
                    .text('(zgłoś)')
                    .addClass('pt-report')
                    .css({ 'margin-left': '10px', 'cursor': 'pointer', 'color': 'red' });

                $(this).after($button);

                // Obsługa kliknięcia w przycisk
                $button.click(function (e) {
                    e.preventDefault();

                    // Popup do wpisania uzasadnienia
                    var reason = prompt('Podaj uzasadnienie zgłoszenia:');
                    if (!reason || reason.trim() === '') {
                        alert('Uzasadnienie jest wymagane.');
                        return;
                    }

                    // Potwierdzenie zgłoszenia
                    var doThis = confirm('Czy na pewno chcesz zgłosić edycję?');
                    if (doThis) {
                        var api = new mw.Api();

                        // Stwórz nowy wątek na Wikipedia:Prośby do administratorów
                        api.postWithToken('csrf', {
                            action: 'edit',
                            title: 'Wikipedia:Prośby do administratorów',
                            section: 'new',
                            sectiontitle: 'Prośba o ukrycie',
                            text: '[[Specjalna:Diff/' + diffNumber + '|Edycja ' + diffNumber + ']] - ' + reason + '\n\nZgłasza: [[User:BZPN|BZPN]] ([[User talk:BZPN|talk]]) 20:08, 4 October 2024 (UTC)',
                            summary: 'Zgłoszono edycję do ukrycia: ' + diffNumber
                        }).done(function () {
                            alert('Edycja została zgłoszona.');
                        }).fail(function (error) {
                            console.error('Błąd podczas zgłaszania:', error);
                            alert('Wystąpił błąd podczas zgłaszania edycji.');
                        });
                    }
                });
            }
        });
    }

    $(document).ready(function () {
        addReportButton();
    });
});