User:BZPN/Email.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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
(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">'
+ '<input type="checkbox" id="mw-input-wpNotifyTalk" name="wpNotifyTalk">'
+ '<label for="mw-input-wpNotifyTalk" style="margin-left: 5px;"> Notify user on talk page</label>'
+ '</span></span>');
// Dodanie nowego checkboxa pod istniejącym
ccCheckbox.closest('.mw-htmlform-field-HTMLCheckField').after(notifyCheckbox);
// Przechwycenie wysłania formularza
$('form.mw-htmlform').on('submit', function() {
if ($('#mw-input-wpNotifyTalk').is(':checked')) {
var recipient = $('input[name=wpTarget]').val();
var api = new mw.Api();
var talkPage = 'User talk:' + recipient;
var message = '\n\n== You\'ve got mail! ==\n{{You\'ve got mail}}'+'~~'+'~~';
// Pobranie obecnej zawartości strony dyskusji
api.get({
action: 'query',
prop: 'revisions',
titles: talkPage,
rvprop: 'content',
formatversion: 2
}).done(function(data) {
var page = data.query.pages[0];
var content = page.missing ? '' : page.revisions[0].content;
content += message;
// Aktualizacja strony dyskusji
api.postWithToken('csrf', {
action: 'edit',
title: talkPage,
text: content,
summary: 'Notifying user of received email',
minor: true
});
});
}
});
});
})();