User:BZPN/Email.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
mw.loader.using('mediawiki.api', 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; |
||
var $copyCheckbox = $('#ooui-php-6'); |
|||
⚫ | |||
// Użyj niezawodnego selektora dla pola "Wyślij mi kopię mojej wiadomości" |
|||
var $notifyCheckbox = $('<div class="mw-htmlform-field-HTMLCheckField"><div class="oo-ui-fieldLayout-field"><input type="checkbox" id="notifyOnTalk" name="notifyOnTalk" value="1"> <label for="notifyOnTalk">Notify user on talk page</label></div></div>'); |
|||
$ |
var $copyField = $('input[name="wpCCMe"]').closest('.mw-htmlform-field-HTMLCheckField'); |
||
⚫ | |||
console.error('Could not find copy field'); |
|||
⚫ | |||
} |
} |
||
⚫ | |||
// Stwórz nowe pole checkbox |
|||
⚫ | |||
var $notifyCheckbox = $( |
|||
e.preventDefault(); |
|||
'<div class="mw-htmlform-field-HTMLCheckField">' + |
|||
⚫ | |||
'<div class="oo-ui-fieldLayout oo-ui-fieldLayout-align-inline">' + |
|||
⚫ | |||
'<div class="oo-ui-fieldLayout-body">' + |
|||
⚫ | |||
'<span class="oo-ui-fieldLayout-header">' + |
|||
⚫ | |||
'<label class="oo-ui-labelElement-label">Notify user on talk page</label>' + |
|||
new mw.Api().postWithToken('csrf', { action: 'edit', title: talkPageTitle, appendtext: text, summary: 'Notification: You\'ve got mail!', format: 'json' }) |
|||
'</span>' + |
|||
.always(() => $('form.mw-htmlform').off('submit').submit()); |
|||
'<div class="oo-ui-fieldLayout-field">' + |
|||
⚫ | |||
'<div class="oo-ui-widget oo-ui-widget-enabled oo-ui-checkboxInput">' + |
|||
'<input type="checkbox" id="notifyOnTalk" name="notifyOnTalk" class="oo-ui-inputWidget-input">' + |
|||
'</div>' + |
|||
'</div>' + |
|||
'</div>' + |
|||
'</div>' + |
|||
'</div>' |
|||
); |
|||
// Dodaj checkbox do formularza |
|||
$copyField.after($notifyCheckbox); |
|||
// Obsługa zdarzenia submit |
|||
⚫ | |||
e.preventDefault(); // Zatrzymaj domyślne działanie formularza |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
// Wykonaj operację API |
|||
new mw.Api().postWithToken('csrf', { |
|||
action: 'edit', |
|||
title: talkPage, |
|||
appendtext: text, |
|||
summary: 'Notification: You\'ve got mail!', |
|||
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 |
|||
}); |
|||
}); |
}); |
||
}); |
}); |
Latest revision as of 23:15, 24 February 2025
mw.loader.using(['mediawiki.api', 'jquery'], function () {
$(function () {
// Sprawdź, czy jesteśmy na stronie EmailUser
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser ') return;
// Użyj niezawodnego selektora dla pola "Wyślij mi kopię mojej wiadomości"
var $copyField = $('input[name="wpCCMe"]').closest('.mw-htmlform-field-HTMLCheckField');
if (!$copyField.length) {
console.error('Could not find copy field');
return;
}
// Stwórz nowe pole checkbox
var $notifyCheckbox = $(
'<div class="mw-htmlform-field-HTMLCheckField">' +
'<div class="oo-ui-fieldLayout oo-ui-fieldLayout-align-inline">' +
'<div class="oo-ui-fieldLayout-body">' +
'<span class="oo-ui-fieldLayout-header">' +
'<label class="oo-ui-labelElement-label">Notify user on talk page</label>' +
'</span>' +
'<div class="oo-ui-fieldLayout-field">' +
'<div class="oo-ui-widget oo-ui-widget-enabled oo-ui-checkboxInput">' +
'<input type="checkbox" id="notifyOnTalk" name="notifyOnTalk" class="oo-ui-inputWidget-input">' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>'
);
// Dodaj checkbox do formularza
$copyField.after($notifyCheckbox);
// Obsługa zdarzenia submit
$('form.mw-htmlform').on('submit', function (e) {
e.preventDefault(); // Zatrzymaj domyślne działanie formularza
var notify = $('#notifyOnTalk').is(':checked'); // Sprawdź, czy checkbox jest zaznaczony
var targetUser = $('#mw-input-wpTarget').val(); // Pobierz nazwę użytkownika
if (!targetUser ) return this.submit(); // Jeśli nie ma użytkownika, wyślij formularz normalnie
var talkPage = 'User talk:' + targetUser ; // Ustal stronę dyskusji
var text = '\n\n== You\'ve got mail! ==\n{{You\'ve got mail}}'+'~~'+'~~\n'; // Treść wiadomości
// Wykonaj operację API
new mw.Api().postWithToken('csrf', {
action: 'edit',
title: talkPage,
appendtext: text,
summary: 'Notification: You\'ve got mail!',
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
});
});
});
});