User:BZPN/Zgłaszarka.js
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() {
// 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();
});
});