User:BZPN/Email.js: Difference between revisions
From Test Wiki
Content deleted Content added
Created page with "(function() { if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser') { return; } $(document).ready(function() { // Znalezienie istniejącego checkboxa "Wyślij mi kopię" var ccCheckbox = $('#mw-input-wpCCMe'); if (!ccCheckbox.length) { return; } // Tworzenie nowego checkboxa var notifyCheckbox = $('<span class="oo-ui-fieldLayout-body"><span class="oo-ui-fieldLayout-field">'..." |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
(function() { |
mw.loader.using(['mediawiki.api', 'jquery'], function () { |
||
| ⚫ | |||
| ⚫ | |||
// Sprawdź, czy jesteśmy na stronie EmailUser |
|||
| ⚫ | |||
| ⚫ | |||
// Użyj niezawodnego selektora dla pola "Wyślij mi kopię mojej wiadomości" |
|||
| ⚫ | |||
| ⚫ | |||
console.error('Could not find copy field'); |
|||
| ⚫ | |||
} |
} |
||
// Stwórz nowe pole checkbox |
|||
| ⚫ | |||
var $notifyCheckbox = $( |
|||
// Znalezienie istniejącego checkboxa "Wyślij mi kopię" |
|||
'<div class="mw-htmlform-field-HTMLCheckField">' + |
|||
var ccCheckbox = $('#mw-input-wpCCMe'); |
|||
| ⚫ | |||
| ⚫ | |||
'<div class="oo-ui-fieldLayout-body">' + |
|||
'<span class="oo-ui-fieldLayout-header">' + |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
'<div class="oo-ui-fieldLayout-field">' + |
|||
'<div class="oo-ui-widget oo-ui-widget-enabled oo-ui-checkboxInput">' + |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
'</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 |
|||
// Tworzenie nowego checkboxa |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
// Dodanie nowego checkboxa pod istniejącym |
|||
| ⚫ | |||
// Wykonaj operację API |
|||
new mw.Api().postWithToken('csrf', { |
|||
| ⚫ | |||
if ($('#mw-input-wpNotifyTalk').is(':checked')) { |
|||
| ⚫ | |||
var recipient = $('input[name=wpTarget]').val(); |
|||
appendtext: text, |
|||
var api = new mw.Api(); |
|||
summary: 'Notification: You\'ve got mail!', |
|||
format: 'json' |
|||
| ⚫ | |||
}).done(function() { |
|||
console.log('Notification posted successfully'); |
|||
// Pobranie obecnej zawartości strony dyskusji |
|||
}).fail(function(err) { |
|||
console.error('Error posting notification:', err); |
|||
action: 'query', |
|||
| ⚫ | |||
prop: 'revisions', |
|||
$(e.target).off('submit').trigger('submit'); // Ponownie wyślij formularz |
|||
titles: talkPage, |
|||
| ⚫ | |||
rvprop: 'content', |
|||
formatversion: 2 |
|||
| ⚫ | |||
var page = data.query.pages[0]; |
|||
var content = page.missing ? '' : page.revisions[0].content; |
|||
content += message; |
|||
// Aktualizacja strony dyskusji |
|||
api.postWithToken('csrf', { |
|||
| ⚫ | |||
| ⚫ | |||
text: content, |
|||
summary: 'Notifying user of received email', |
|||
minor: true |
|||
}); |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
}); |
}); |
||
} |
}); |
||
}); |
|||