Замечание: Возможно, после публикации вам придётся очистить кэш своего браузера, чтобы увидеть изменения.
- Firefox / Safari: Удерживая клавишу Shift, нажмите на панели инструментов Обновить либо нажмите Ctrl+F5 или Ctrl+R (⌘+R на Mac)
- Google Chrome: Нажмите Ctrl+Shift+R (⌘+Shift+R на Mac)
- Internet Explorer / Edge: Удерживая Ctrl, нажмите Обновить либо нажмите Ctrl+F5
- Opera: Нажмите Ctrl+F5.
(function () {
if (mw.config.get('wgAction') !== 'edit' && mw.config.get('wgAction') !== 'submit') return;
var previewButton = document.createElement('button');
previewButton.textContent = 'Предварительный просмотр';
previewButton.style.margin = '10px 0';
var previewContainer = document.createElement('div');
previewContainer.id = 'live-preview-container';
previewContainer.style.marginTop = '20px';
previewContainer.style.border = '1px solid #ccc';
previewContainer.style.padding = '10px';
previewContainer.style.backgroundColor = '#f9f9f9';
previewContainer.style.display = 'none';
var editForm = document.getElementById('editform');
if (editForm) {
editForm.parentNode.insertBefore(previewButton, editForm);
editForm.parentNode.insertBefore(previewContainer, editForm.nextSibling);
}
previewButton.addEventListener('click', function () {
var editText = document.getElementById('wpTextbox1').value;
var api = new mw.Api({
ajax: {
url: 'https://spacestories.club/api.php'
}
});
api.post({
action: 'parse',
text: editText,
contentmodel: 'wikitext',
format: 'json'
}).done(function (data) {
previewContainer.style.display = 'block';
previewContainer.innerHTML = data.parse.text['*'];
}).fail(function () {
previewContainer.style.display = 'block';
previewContainer.textContent = 'Ошибка загрузки предварительного просмотра.';
});
});
})();