MediaWiki:In-page-edit.js

/** * WARNING: This is a test script, don't use it! Please use the AjaxEdit instead. * MediaWiki JS Plugin: In Page Edit * Author: 机智的小鱼君 * Url: https://github.com/Dragon-Fish/wjghj-wiki/Gadgets/in-page-edit * Description: Let you edit page without open new tab. And edit Navebox via navbar, edit section via section edit link etc. **/ function InPageEdit(inPageEditTarget) {

if ($('#InPageEdit').length > 0) { // 只能存在一个窗口 $('#InPageEdit').remove; } // 开始执行任务 $('body').addClass('action-in-page-edit'); // Variables if (inPageEditTarget == undefined) { inPageEditTarget = mw.config.get('wgPageName'); } var origintext;

new mw.Api.get({   action: "parse",    page: inPageEditTarget,    prop: "wikitext",    format: "json"  }).then(function(data) {    origintext = data.parse.wikitext['*'];    ajaxArea  }).fail(function {    origintext = '\n';    ajaxArea  }); function ajaxArea { // Create area & hide article $('#mw-content-text').hide; $('#mw-content-text').before(' ' + 'in-page-edit-title ' + ' ' + '取消 预览  提交 ' + ' 预览 ' + ' '); $('#InPageEdit #newcontent').val(origintext); $('#InPageEdit #edit-title').html('正在编辑: ' + inPageEditTarget);

// Cancle $('#InPageEdit #cancle-btn').click(function {     var cancleconfirm = confirm('取消吗？');      if (cancleconfirm) {        $('body').removeClass('action-in-page-edit');        $('#InPageEdit').remove;        $('#mw-content-text').show;      }    });

// Preview $('#InPageEdit #preview-btn').click(function {     new mw.Api.post({ action: "parse", text: $('#InPageEdit #newcontent').val, prop: "text", preview: true, format: "json" }).then(function(data) { var previewcontent = data.parse.text['*'];

$('#InPageEdit #preview-area').html(previewcontent); });   });

// Submit $('#InPageEdit #submit-btn').click(function {     var submitconfirm = confirm('提交吗？');      if (submitconfirm) {        new mw.Api.post({ action: 'edit', text: $('#InPageEdit #newcontent').val, title: inPageEditTarget, summary: '[InPageEdit] ' + $('#InPageEdit #reason').val, token: mw.user.tokens.get('editToken') }).done(function { $('#InPageEdit').html('已提交 '); window.location.reload; });     }    });  } }

/** Add button **/ $(function { $('.page-header__contribution-buttons .wds-dropdown__content ul').append($('').append($('').addClass('in-page-edit-btn-link').attr('href', 'javascript:void(0)').text('快速编辑').click(function { InPageEdit }))); }); /** Get links in ariticle **/ $(function { var self = this;  $('#mw-content-text a.external').each(function(i) { var url = $(this).attr('href'); var reg = /(([^?&=]+)(?:=([^?&=]*))*)/g; var params = {}, match; while (match = reg.exec(url)) { params[match[2]] = decodeURIComponent(match[3]); }   if (params.action === 'edit' && params.title !== undefined && params.section !== 'new') { $(this).after($('').attr({ 'href': 'javascript:void(0)', 'class': 'in-page-edit-article-link' }).html('[编] ').data({ 'target': decodeURIComponent(params.title), 'number': params.section || -1 }).click(function { InPageEdit(params.title) }));   }  }); });