|
Метки: очистка ручная отмена |
(не показаны 23 промежуточные версии 2 участников) |
Строка 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({
| |
| ajax: {
| |
| url: 'https://spacestories.club/api.php?action=webapp-manifest'
| |
| }
| |
| });
| |
| 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 = 'Ошибка загрузки предварительного просмотра.';
| |
| });
| |
| });
| |
| })();
| |