User:BZPN/Email.js: Difference between revisions
From Test Wiki
Content deleted Content added
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
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; |
||
// Użyj niezawodnego selektora dla pola "Wyślij mi kopię mojej wiadomości" |
|||
var $copyField = $(' |
var $copyField = $('input[name="wpCCMe"]').closest('.mw-htmlform-field-HTMLCheckField'); |
||
if (!$copyField.length) |
if (!$copyField.length) { |
||
console.error('Could not find copy field'); |
|||
return; |
|||
} |
|||
// Stwórz nowe pole checkbox |
|||
⚫ | |||
var $notifyCheckbox = $( |
|||
⚫ | |||
⚫ | |||
⚫ | |||
'<div class="oo-ui-fieldLayout oo-ui-fieldLayout-align-inline">' + |
|||
⚫ | |||
'< |
'<div class="oo-ui-fieldLayout-body">' + |
||
'<span class="oo-ui-fieldLayout-header">' + |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
'<div class="oo-ui-widget oo-ui-widget-enabled oo-ui-checkboxInput">' + |
|||
⚫ | |||
'</div>' + |
|||
'</div>' + |
|||
'</div>' + |
|||
'</div>' + |
|||
⚫ | |||
); |
|||
// Dodaj checkbox do formularza |
|||
$copyField.after($notifyCheckbox); |
$copyField.after($notifyCheckbox); |
||
// 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 notify = $('#notifyOnTalk').is(':checked'); // Sprawdź, czy checkbox jest zaznaczony |
|||
var targetUser = $('#mw-input-wpTarget').val(); // Pobierz nazwę użytkownika |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
// Wykonaj operację API |
|||
⚫ | |||
⚫ | |||
⚫ | |||
action: 'edit', |
|||
⚫ | |||
}).always(() => $('form.mw-htmlform').off('submit').submit()); |
|||
appendtext: text, |
|||
⚫ | |||
format: 'json' |
|||
}).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 |
|||
}); |
|||
}); |
}); |
||
}); |
}); |