User:BZPN/Email.js: Difference between revisions
From Test Wiki
Content deleted Content added
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser') return; |
if (mw.config.get('wgCanonicalSpecialPageName') !== 'EmailUser') return; |
||
// Znajdź pole "Wyślij kopię na moją stronę dyskusji" po tekście etykiety |
|||
var $copyField = $('label |
var $copyField = $('label:contains("Send a copy to my talk page")').closest('.mw-htmlform-field-HTMLCheckField'); |
||
if (!$copyField.length) return; |
if (!$copyField.length) return; |
||
// Stwórz nowe pole checkbox używając spójnego stylu OOUI |
|||
| ⚫ | |||
var $notifyCheckbox = $( |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
'<div class="oo-ui-fieldLayout oo-ui-fieldLayout-align-inline">' + |
|||
| ⚫ | |||
'< |
'<div class="oo-ui-fieldLayout-body">' + |
||
'<span class="oo-ui-fieldLayout-header">' + |
|||
| ⚫ | |||
| ⚫ | |||
'</span>' + |
|||
| ⚫ | |||
'<div class="oo-ui-widget oo-ui-widget-enabled oo-ui-checkboxInput">' + |
|||
| ⚫ | |||
'</div>' + |
|||
'</div>' + |
|||
'</div>' + |
|||
'</div>' + |
|||
| ⚫ | |||
); |
|||
$copyField.after($notifyCheckbox); |
$copyField.after($notifyCheckbox); |
||
// Obsługa formularza |
|||
$('form.mw-htmlform').on('submit', function (e) { |
$('form.mw-htmlform').on('submit', function (e) { |
||
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 talkPage = 'User talk:' + targetUser; |
var talkPage = 'User talk:' + targetUser; |
||
var text = '\n\n== You\'ve |
var text = '\n\n== You\'ve got mail! ==\n{{subst:You\'ve got mail}}'+'~~'+'~~\n'; |
||
new mw.Api().postWithToken('csrf', { |
new mw.Api().postWithToken('csrf', { |
||
| Line 31: | Line 44: | ||
summary: 'Notification: You\'ve got mail!', |
summary: 'Notification: You\'ve got mail!', |
||
format: 'json' |
format: 'json' |
||
}).done(function() { |
|||
| ⚫ | |||
console.log('Notification posted successfully'); |
|||
}).fail(function(err) { |
|||
console.error('Error posting notification:', err); |
|||
}).always(function() { |
|||
| ⚫ | |||
}); |
|||
} |
} |
||
}); |
}); |
||