Pengguna:Hidayatsrf/saveandedit.js
Tampilan
Catatan: Setelah menyimpan, Anda harus memintas tembolok (cache) peramban Anda untuk melihat perubahannya. Google Chrome, Firefox, Microsoft Edge dan Safari: Tahan tombol ⇧ Shift dan klik Muat ulang (Reload) di tombol bilah alat. Untuk detail dan instruksi tentang peramban lain, lihat halaman menghapus singgahan (Inggris).
// translated by [[User:Hidayatsrf]] original code at [[en:User:Mabdul/saveandedit.js]]
/**
* To use this script, add following line to your [[Special:MyPage/common.js]] (without the "*"):
* importScript('User:Hidayatsrf/saveandedit.js');
*/
/*global mw, $ */
(function () {
var editButtons = document.getElementsByClassName('editButtons')[0];
if (!editButtons || !document.editform) {
return;
}
var conf = mw.config.get(['wgPageName']);
$('<input type="button"/>')
.val('Simpan dan sunting lagi')
.on('click', function () {
saveandedit_prompt();
})
.appendTo(editButtons);
// Function for returning
function saveandedit_prompt() {
mw.loader.using(['mediawiki.util', 'mediawiki.api'], function () {
var section = mw.util.getParamValue('section');
var summary = document.editform.wpSummary.value;
// Some advertising
summary += ' (Menggunakan [[User:Hidayatsrf/saveandedit.js|Save & Edit]])';
var params = {
action: 'edit',
title: conf.wgPageName,
text: document.editform.wpTextbox1.value,
summary: summary
};
if (document.editform.wpMinoredit.checked) {
params.notminor = '1';
}
// Check if only a section will be edited
if (section) {
params.section = section;
}
var api = new mw.Api();
api.postWithEditToken(params).done(function (response) {
if (response.edit.result === 'Success') {
// Reload on the success
location.reload();
} else {
// Handle out the error message
var error = $.parseHTML( '<div><div class="error">Edit failed on ' +
mw.html.element('a', { href: mw.util.getUrl(conf.wgPageName), title: conf.wgPageName }, conf.wgPageName ) +
'</div> Best try it again (<b>Don\'t forget to copy the text!</b>). Error info: ' +
(response.error && mw.html.escape(response.error.code + ' : ' + response.error.info)) +
'</div>' );
mw.notify(error, { autoHide: false });
}
});
});
}
}());