User:BZPN/Zgłaszarka.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
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() { |
||
// |
// 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]; // |
var diffNumber = diffHref.match(/oldid=(\d+)/)[1]; // Extracting the diff number |
||
// |
// Check if the report button already exists |
||
if ($diffLink.siblings('.pt-report').length === 0) { |
if ($diffLink.siblings('.pt-report').length === 0) { |
||
// |
// Create the report button |
||
var $button = $('<a>') |
var $button = $('<a>') |
||
.attr('href', '#') |
.attr('href', '#') |
||
.text('( |
.text('(report)') |
||
.addClass('pt-report') |
.addClass('pt-report') |
||
.css({ 'margin-left': '10px', 'cursor': 'pointer', 'color': 'red' }); |
.css({ 'margin-left': '10px', 'cursor': 'pointer', 'color': 'red' }); |
||
// |
// Add the button after the diff link |
||
$diffLink.after($button); |
$diffLink.after($button); |
||
// |
// Handle button click |
||
$button.click(function (e) { |
$button.click(function (e) { |
||
e.preventDefault(); |
e.preventDefault(); |
||
// |
// Display popup for reason input |
||
var reason = prompt(' |
var reason = prompt('Enter the reason for reporting:'); |
||
if (!reason || reason.trim() === '') { |
if (!reason || reason.trim() === '') { |
||
alert(' |
alert('A reason is required.'); |
||
return; |
return; |
||
} |
} |
||
// |
// Confirm the report |
||
var confirmReport = confirm(' |
var confirmReport = confirm('Are you sure you want to report this edit?'); |
||
if (!confirmReport) { |
if (!confirmReport) { |
||
return; |
return; |
||
} |
} |
||
// API |
// 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: ' |
title: 'User talk:BZPN', |
||
section: 'new', |
section: 'new', |
||
sectiontitle: ' |
sectiontitle: 'Request to hide', |
||
text: '[[ |
text: '[[Special:Diff/' + diffNumber + '|Diff ' + diffNumber + ']] - ' + reason + '\nReported by: [[User:BZPN|BZPN]] ([[User talk:BZPN|talk]]) 20:01, 4 October 2024 (UTC)', |
||
summary: ' |
summary: 'Request to hide edit no. ' + diffNumber |
||
}).done(function () { |
}).done(function () { |
||
alert(' |
alert('The report has been submitted.'); |
||
}).fail(function (error) { |
}).fail(function (error) { |
||
console.error(' |
console.error('Error while submitting the report:', error); |
||
alert(' |
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(); |
Revision as of 20:01, 4 October 2024
mw.loader.using(['oojs-ui', 'mediawiki.util']).done(function () {
function addReportButton() {
// Iterate through all diff links
$('.mw-changeslist-links .mw-diff').each(function () {
var $diffLink = $(this);
var diffHref = $diffLink.attr('href');
var diffNumber = diffHref.match(/oldid=(\d+)/)[1]; // Extracting the diff number
// Check if the report button already exists
if ($diffLink.siblings('.pt-report').length === 0) {
// Create the report button
var $button = $('<a>')
.attr('href', '#')
.text('(report)')
.addClass('pt-report')
.css({ 'margin-left': '10px', 'cursor': 'pointer', 'color': 'red' });
// Add the button after the diff link
$diffLink.after($button);
// Handle button click
$button.click(function (e) {
e.preventDefault();
// Display popup for reason input
var reason = prompt('Enter the reason for reporting:');
if (!reason || reason.trim() === '') {
alert('A reason is required.');
return;
}
// Confirm the report
var confirmReport = confirm('Are you sure you want to report this edit?');
if (!confirmReport) {
return;
}
// API call to post to the report page
var api = new mw.Api();
api.postWithToken('csrf', {
action: 'edit',
title: 'User talk:BZPN',
section: 'new',
sectiontitle: 'Request to hide',
text: '[[Special:Diff/' + diffNumber + '|Diff ' + diffNumber + ']] - ' + reason + '\nReported by: [[User:BZPN|BZPN]] ([[User talk:BZPN|talk]]) 20:01, 4 October 2024 (UTC)',
summary: 'Request to hide edit no. ' + diffNumber
}).done(function () {
alert('The report has been submitted.');
}).fail(function (error) {
console.error('Error while submitting the report:', error);
alert('An error occurred while submitting the report.');
});
});
}
});
}
// Run the function after the page has loaded
$(document).ready(function () {
addReportButton();
});
});