User:BZPN/Email.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
mw.loader.using('mediawiki.api', function () { |
mw.loader.using(['mediawiki.api', 'jquery'], function () { |
||
$(function () { |
$(function () { |
||
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser') return; |
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser') return; |
||
var $copyCheckbox = $('#ooui-php-6'); |
|||
⚫ | |||
if ($ |
if (!$copyField.length) return; |
||
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 $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>'); |
|||
$copyField.after($notifyCheckbox); |
|||
⚫ | |||
if ($('#notifyOnTalk').is(':checked')) { |
if ($('#notifyOnTalk').is(':checked')) { |
||
e.preventDefault(); |
e.preventDefault(); |
||
var targetUser = $('#mw-input-wpTarget').val(); |
var targetUser = $('#mw-input-wpTarget').val(); |
||
if (!targetUser) return this.submit(); |
if (!targetUser) return this.submit(); |
||
var |
var talkPage = 'User talk:' + targetUser; |
||
var text = '\n\n== You\'ve got got mail! ==\n{{You\'ve got mail}}'+'~~'+'~~\n'; |
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' }) |
|||
new mw.Api().postWithToken('csrf', { |
|||
action: 'edit', |
|||
title: talkPage, |
|||
appendtext: text, |
|||
summary: 'Notification: You\'ve got mail!', |
|||
format: 'json' |
|||
}).always(() => $('form.mw-htmlform').off('submit').submit()); |
|||
} |
} |
||
}); |
}); |
Revision as of 22:24, 24 February 2025
mw.loader.using(['mediawiki.api', 'jquery'], function () {
$(function () {
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser') return;
var $copyField = $('label[for="ooui-php-6"]').closest('.mw-htmlform-field-HTMLCheckField');
if (!$copyField.length) return;
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>');
$copyField.after($notifyCheckbox);
$('form.mw-htmlform').on('submit', function (e) {
if ($('#notifyOnTalk').is(':checked')) {
e.preventDefault();
var targetUser = $('#mw-input-wpTarget').val();
if (!targetUser) return this.submit();
var talkPage = '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: talkPage,
appendtext: text,
summary: 'Notification: You\'ve got mail!',
format: 'json'
}).always(() => $('form.mw-htmlform').off('submit').submit());
}
});
});
});