User:BZPN/Email.js: Difference between revisions
Jump to navigation
Jump to search
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 |
||
Line 1: | Line 1: | ||
(function() { |
mw.loader.using('mediawiki.api', function () { |
||
$(function () { |
|||
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser') |
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser') return; |
||
return; |
|||
var $copyCheckbox = $('#ooui-php-6'); |
|||
if ($copyCheckbox.length) { |
|||
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>'); |
|||
⚫ | |||
} |
} |
||
⚫ | |||
$( |
if ($('#notifyOnTalk').is(':checked')) { |
||
e.preventDefault(); |
|||
// Znalezienie istniejącego checkboxa "Wyślij mi kopię" |
|||
var |
var targetUser = $('#mw-input-wpTarget').val(); |
||
if (! |
if (!targetUser) return this.submit(); |
||
var talkPageTitle = 'User talk:' + targetUser; |
|||
⚫ | |||
⚫ | |||
new mw.Api().postWithToken('csrf', { action: 'edit', title: talkPageTitle, appendtext: text, summary: 'Notification: You\'ve got mail!', format: 'json' }) |
|||
.always(() => $('form.mw-htmlform').off('submit').submit()); |
|||
// 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 |
|||
⚫ | |||
// Przechwycenie wysłania formularza |
|||
⚫ | |||
if ($('#mw-input-wpNotifyTalk').is(':checked')) { |
|||
var recipient = $('input[name=wpTarget]').val(); |
|||
var api = new mw.Api(); |
|||
var talkPage = 'User talk:' + recipient; |
|||
⚫ | |||
// 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 |
|||
}); |
|||
}); |
|||
} |
|||
}); |
|||
}); |
}); |
||
} |
}); |
||
}); |
Revision as of 22:18, 24 February 2025
mw.loader.using('mediawiki.api', function () {
$(function () {
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser') return;
var $copyCheckbox = $('#ooui-php-6');
if ($copyCheckbox.length) {
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>');
$copyCheckbox.closest('.mw-htmlform-field-HTMLCheckField').after($notifyCheckbox);
}
$('form.mw-htmlform').submit(function (e) {
if ($('#notifyOnTalk').is(':checked')) {
e.preventDefault();
var targetUser = $('#mw-input-wpTarget').val();
if (!targetUser) return this.submit();
var talkPageTitle = 'User talk:' + targetUser;
var text = '\n\n== You\'ve got got mail! ==\n{{You\'ve got mail}}'+'~~'+'~~\n';
new mw.Api().postWithToken('csrf', { action: 'edit', title: talkPageTitle, appendtext: text, summary: 'Notification: You\'ve got mail!', format: 'json' })
.always(() => $('form.mw-htmlform').off('submit').submit());
}
});
});
});