Dantes (обсуждение | вклад) (Полностью удалено содержимое страницы) Метка: очистка |
Dantes (обсуждение | вклад) Нет описания правки Метка: ручная отмена |
||
| Строка 1: | Строка 1: | ||
(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(); | |||
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 = 'Ошибка загрузки предварительного просмотра.'; | |||
}); | |||
}); | |||
})(); | |||
Версия от 06:10, 17 января 2025
(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();
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 = 'Ошибка загрузки предварительного просмотра.';
});
});
})();