User:BZPN/Email.js: Difference between revisions

From Test Wiki
Content deleted Content added
No edit summary
No edit summary
 
Line 1: Line 1:
mw.loader.using(['mediawiki.api', 'jquery'], function () {
mw.loader.using(['mediawiki.api', 'jquery'], function () {
$(function () {
$(function () {
// Sprawdź, czy jesteśmy na stronie EmailUser
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser') return;
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser ') return;


// Znajdź pole "Wyślij kopię na moją stronę dyskusji" po tekście etykiety
// Użyj niezawodnego selektora dla pola "Wyślij mi kopię mojej wiadomości"
var $copyField = $('label:contains("Send a copy to my talk page")').closest('.mw-htmlform-field-HTMLCheckField');
var $copyField = $('input[name="wpCCMe"]').closest('.mw-htmlform-field-HTMLCheckField');
if (!$copyField.length) return;
if (!$copyField.length) {
console.error('Could not find copy field');
return;
}


// Stwórz nowe pole checkbox używając spójnego stylu OOUI
// Stwórz nowe pole checkbox
var $notifyCheckbox = $(
var $notifyCheckbox = $(
'<div class="mw-htmlform-field-HTMLCheckField">' +
'<div class="mw-htmlform-field-HTMLCheckField">' +
Line 25: Line 29:
);
);


// Dodaj checkbox do formularza
$copyField.after($notifyCheckbox);
$copyField.after($notifyCheckbox);


// Obsługa formularza
// Obsługa zdarzenia submit
$('form.mw-htmlform').on('submit', function (e) {
$('form.mw-htmlform').on('submit', function (e) {
e.preventDefault(); // Zatrzymaj domyślne działanie formularza
if ($('#notifyOnTalk').is(':checked')) {
e.preventDefault();
var targetUser = $('#mw-input-wpTarget').val();
if (!targetUser) return this.submit();


var notify = $('#notifyOnTalk').is(':checked'); // Sprawdź, czy checkbox jest zaznaczony
var talkPage = 'User talk:' + targetUser;
var targetUser = $('#mw-input-wpTarget').val(); // Pobierz nazwę użytkownika
var text = '\n\n== You\'ve got mail! ==\n{{subst:You\'ve got mail}}'+'~~'+'~~\n';


if (!targetUser ) return this.submit(); // Jeśli nie ma użytkownika, wyślij formularz normalnie
new mw.Api().postWithToken('csrf', {

action: 'edit',
var talkPage = 'User talk:' + targetUser ; // Ustal stronę dyskusji
title: talkPage,
var text = '\n\n== You\'ve got mail! ==\n{{You\'ve got mail}}'+'~~'+'~~\n'; // Treść wiadomości
appendtext: text,

summary: 'Notification: You\'ve got mail!',
format: 'json'
// Wykonaj operację API
}).done(function() {
new mw.Api().postWithToken('csrf', {
action: 'edit',
console.log('Notification posted successfully');
}).fail(function(err) {
title: talkPage,
appendtext: text,
console.error('Error posting notification:', err);
summary: 'Notification: You\'ve got mail!',
}).always(function() {
format: 'json'
$(e.target).off('submit').trigger('submit');
});
}).done(function() {
console.log('Notification posted successfully');
}
}).fail(function(err) {
console.error('Error posting notification:', err);
}).always(function() {
$(e.target).off('submit').trigger('submit'); // Ponownie wyślij formularz
});
});
});
});
});