User:BZPN/RfD.js

From Test Wiki
Revision as of 18:42, 1 November 2024 by BZPN (talk | contribs)
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.
(function() {
    if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgIsArticle') === false) return;

    // Dodaj przycisk "Nominate for deletion" do paska narzędzi
    var nominateLink = mw.util.addPortletLink(
        'p-tb', 
        '#', 
        'Nominate for deletion', 
        'ca-nominate-deletion', 
        'Nominate this page for deletion' 
    );

    // Jeśli dodanie przycisku się powiodło, przypisz funkcję do obsługi kliknięcia
    if (nominateLink) {
        nominateLink.onclick = function(event) {
            event.preventDefault();
            openDeletionPopup();
        };
    }

    // Tworzenie i otwarcie okna popup dla nominacji do usunięcia
    function openDeletionPopup() {
        const overlay = $('<div>').attr('id', 'deletion-popup-overlay').css({
            'position': 'fixed',
            'top': '0',
            'left': '0',
            'width': '100%',
            'height': '100%',
            'background-color': 'rgba(0, 0, 0, 0.5)',
            'z-index': '1000',
        }).appendTo('body');

        const popup = $('<div>').attr('id', 'deletion-popup').css({
            'width': '90%',
            'max-width': '400px',
            'margin': '10% auto',
            'padding': '15px',
            'background-color': '#fff',
            'border-radius': '8px',
            'box-shadow': '0 4px 8px rgba(0, 0, 0, 0.2)',
            'text-align': 'left',
            'position': 'relative'
        }).appendTo(overlay);

        $('<span>').text('×').css({
            'position': 'absolute',
            'top': '10px',
            'right': '15px',
            'cursor': 'pointer',
            'font-size': '18px',
            'font-weight': 'bold'
        }).on('click', closeDeletionPopup).appendTo(popup);

        $('<h3>').text('Nominate for deletion').css({
            'font-size': '18px',
            'margin-bottom': '10px'
        }).appendTo(popup);

        $('<p>').text('Before nominating, please read the deletion policy and guidelines on the Wikipedia:Requests for deletion page.').css({
            'font-size': '14px',
            'margin-bottom': '10px'
        }).appendTo(popup);
        $('<a>').attr('href', '/wiki/Wikipedia:Requests_for_deletion').text('Go to Wikipedia:Requests for deletion').css({
            'font-size': '14px',
            'color': '#0073e6',
            'text-decoration': 'underline',
            'display': 'block',
            'margin-bottom': '10px'
        }).appendTo(popup);

        $('<label>').attr('for', 'deletion-short-reason').text('Short reason:').css({
            'display': 'block',
            'margin-top': '10px',
            'font-size': '14px'
        }).appendTo(popup);
        const shortReasonInput = $('<input>').attr({
            'type': 'text',
            'id': 'deletion-short-reason',
            'placeholder': 'Enter short reason...'
        }).css({
            'width': '100%',
            'padding': '6px',
            'margin': '5px 0',
            'font-size': '14px',
            'box-sizing': 'border-box'
        }).appendTo(popup);

        $('<label>').attr('for', 'deletion-detailed-reason').text('Detailed reason for discussion:').css({
            'display': 'block',
            'margin-top': '10px'
        }).appendTo(popup);
        const detailedReasonInput = $('<textarea>').attr({
            'id': 'deletion-detailed-reason',
            'placeholder': 'Detailed reason...'
        }).css({
            'width': '100%',
            'padding': '6px',
            'font-size': '14px',
            'height': '80px',
            'margin-bottom': '10px'
        }).appendTo(popup);

        // Checkbox i lista rozwijana Quick Delete
        const quickDeleteCheckbox = $('<input>').attr({
            'type': 'checkbox',
            'id': 'quick-delete'
        }).css({
            'margin-right': '5px'
        });
        $('<label>').attr('for', 'quick-delete').text('Quick Delete').css({
            'font-size': '14px'
        }).prepend(quickDeleteCheckbox).appendTo(popup);

        $('<label>').attr('for', 'quick-delete-reason').text('Select reason:').css({
            'display': 'block',
            'margin-top': '10px',
            'font-size': '14px'
        }).appendTo(popup);

        const quickDeleteReasonSelect = $('<select>').attr('id', 'quick-delete-reason').css({
            'width': '100%',
            'padding': '6px',
            'font-size': '14px',
            'box-sizing': 'border-box'
        }).appendTo(popup);

        const reasons = {
            'A1': 'Little/no meaning',
            'A2': 'No content',
            'A3': 'Transwikied',
            'A4': 'Not notable',
            'A5': 'Not in English',
            'G1': 'Nonsense',
            'G2': 'Test page',
            'G3': 'Vandalism',
            'G10': 'Attack page',
            'G11': 'Advertising',
            'G12': 'Copyright infringement'
        };

        $.each(reasons, function(key, value) {
            $('<option>').attr('value', key).text(key + ' - ' + value).appendTo(quickDeleteReasonSelect);
        });

        $('<button>').text('Submit nomination').css({
            'width': '100%',
            'padding': '10px',
            'background-color': '#0073e6',
            'color': '#fff',
            'border': 'none',
            'border-radius': '5px',
            'cursor': 'pointer',
            'font-size': '16px'
        }).on('click', function() {
            const shortReason = shortReasonInput.val().trim();
            const detailedReason = detailedReasonInput.val().trim();
            const quickDelete = quickDeleteCheckbox.is(':checked');
            const quickDeleteReason = quickDeleteReasonSelect.val();
            
            if (quickDelete) {
                tagPageForQuickDeletion(quickDeleteReason);
            } else {
                initiateDeletionProcess(shortReason, detailedReason);
            }
        }).appendTo(popup);
    }

    function closeDeletionPopup() {
        $('#deletion-popup-overlay').remove();
    }

    function tagPageForQuickDeletion(reason) {
        const tag = `{{QD|${reason}}}`;
        new mw.Api().postWithToken('csrf', {
            action: 'edit',
            title: mw.config.get('wgPageName'),
            prependtext: tag + '\n',
            summary: `Quick Delete tag added: ${reason}`,
            watchlist: 'watch',
        }).done(function() {
            alert('Quick Delete tag added.');
        }).fail(function() {
            alert('Failed to add Quick Delete tag.');
        });
    }

    function initiateDeletionProcess(shortReason, detailedReason) {
        tagPageForDeletion(shortReason);
        createDiscussionPage(detailedReason);
        addToDeletionList();
        notifyPageCreator();
        closeDeletionPopup();
    }

    function tagPageForDeletion(reason) {
        const tag = `{{rfd|${reason}}}`;
        const editSummary = 'Nominating for deletion (RfD)';
        new mw.Api().postWithToken('csrf', {
            action: 'edit',
            title: mw.config.get('wgPageName'),
            prependtext: tag + '\n',
            summary: editSummary,
            watchlist: 'watch',
        }).done(function() {
            alert('Page tagged for deletion.');
        }).fail(function() {
            alert('Failed to tag the page for deletion.');
        });
    }

    function createDiscussionPage(detailedReason) {
        // Pseudokod funkcji tworzącej stronę dyskusji
        console.log('Creating discussion page with reason:', detailedReason);
    }

    function addToDeletionList() {
        // Pseudokod funkcji dodającej stronę do listy usunięć
        console.log('Adding to deletion list');
    }

    function notifyPageCreator() {
        // Pseudokod funkcji powiadamiającej twórcę strony
        console.log('Notifying page creator');
    }
})();