User:BZPN/Zgłaszarka.js: Difference between revisions

From Test Wiki
Content deleted Content added
BZPN (talk | contribs)
No edit summary
BZPN (talk | contribs)
No edit summary
Line 1: Line 1:
mw.loader.using(['oojs-ui', 'mediawiki.util']).done(function () {
mw.loader.using(['oojs-ui', 'mediawiki.util']).done(function () {
function addReportButton() {
function addReportButton() {
// Przejście przez wszystkie linki edycji
// Iterate through all diff links
$('.mw-changeslist-links .mw-diff').each(function () {
$('.mw-changeslist-links .mw-diff').each(function () {
var $diffLink = $(this);
var $diffLink = $(this);
var diffHref = $diffLink.attr('href');
var diffHref = $diffLink.attr('href');
var diffNumber = diffHref.match(/oldid=(\d+)/)[1]; // Wyciągnięcie numeru edycji
var diffNumber = diffHref.match(/oldid=(\d+)/)[1]; // Extracting the diff number


// Sprawdzenie, czy przycisk już nie istnieje
// Check if the report button already exists
if ($diffLink.siblings('.pt-report').length === 0) {
if ($diffLink.siblings('.pt-report').length === 0) {
// Tworzenie przycisku
// Create the report button
var $button = $('<a>')
var $button = $('<a>')
.attr('href', '#')
.attr('href', '#')
.text('(zgłoś)')
.text('(report)')
.addClass('pt-report')
.addClass('pt-report')
.css({ 'margin-left': '10px', 'cursor': 'pointer', 'color': 'red' });
.css({ 'margin-left': '10px', 'cursor': 'pointer', 'color': 'red' });


// Dodanie przycisku po linku edycji
// Add the button after the diff link
$diffLink.after($button);
$diffLink.after($button);


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


// Wyświetlenie popupu z możliwością wpisania uzasadnienia
// Display popup for reason input
var reason = prompt('Podaj uzasadnienie zgłoszenia:');
var reason = prompt('Enter the reason for reporting:');
if (!reason || reason.trim() === '') {
if (!reason || reason.trim() === '') {
alert('Uzasadnienie jest wymagane.');
alert('A reason is required.');
return;
return;
}
}


// Potwierdzenie zgłoszenia
// Confirm the report
var confirmReport = confirm('Czy na pewno chcesz zgłosić edycję do ukrycia?');
var confirmReport = confirm('Are you sure you want to report this edit?');
if (!confirmReport) {
if (!confirmReport) {
return;
return;
}
}


// API do edycji strony z prośbami
// API call to post to the report page
var api = new mw.Api();
var api = new mw.Api();


api.postWithToken('csrf', {
api.postWithToken('csrf', {
action: 'edit',
action: 'edit',
title: 'Wikipedia:Prośby do administratorów',
title: 'User talk:BZPN',
section: 'new',
section: 'new',
sectiontitle: 'Prośba o ukrycie',
sectiontitle: 'Request to hide',
text: '[[Specjalna:Diff/' + diffNumber + '|Diff ' + diffNumber + ']] - ' + reason + '\nZgłasza: [[User:BZPN|BZPN]] ([[User talk:BZPN|talk]]) 19:56, 4 October 2024 (UTC)',
text: '[[Special:Diff/' + diffNumber + '|Diff ' + diffNumber + ']] - ' + reason + '\nReported by: [[User:BZPN|BZPN]] ([[User talk:BZPN|talk]]) 20:01, 4 October 2024 (UTC)',
summary: 'Prośba o ukrycie edycji nr ' + diffNumber
summary: 'Request to hide edit no. ' + diffNumber
}).done(function () {
}).done(function () {
alert('Zgłoszenie zostało wysłane.');
alert('The report has been submitted.');
}).fail(function (error) {
}).fail(function (error) {
console.error('Błąd podczas wysyłania zgłoszenia:', error);
console.error('Error while submitting the report:', error);
alert('Wystąpił błąd podczas wysyłania zgłoszenia.');
alert('An error occurred while submitting the report.');
});
});
});
});
Line 57: Line 57:
}
}


// Run the function after the page has loaded
// Uruchomienie funkcji po załadowaniu strony
$(document).ready(function () {
$(document).ready(function () {
addReportButton();
addReportButton();