• 正在查找将来过去时的官方设定集?不如看看万界大百科吧!
  • 《将来过去时》第一部分 现在 魔科纪元的少年少女 即将正式发布!
  • 让我偷偷看一眼小鱼君的博客……
  • 服务器已成功迁移到 阿里云(杭州)

Template:Editnotice/Group/Clearyourcache

来自小鱼君和他的朋友们
< Template:Editnotice
机智的小鱼君讨论 | 贡献2019年9月23日 (一) 23:05的版本 ([InPageEdit])

/**

* 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

' + '<textarea id="newcontent" style="width:100%;min-height:300px"></textarea>' + '<button id="cancle-btn">取消</button> <button id="preview-btn">预览</button>
<input id="reason" placeholder="编辑摘要"> <button id="submit-btn">提交</button>
' + '

预览

' + '

');

   $('#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() {

$('.action-view #p-userpagetools ul').append($('

  • ').append($('<a>').addClass('in-page-edit-link-edit').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($('<a>').attr({ 'href': 'javascript:void(0)', 'class': 'in-page-edit-link-edit' }).html('[编]').data({ 'target': decodeURIComponent(params.title), 'number': params.section || -1 })); $('.in-page-edit-link-edit').click(function() { InPageEdit(params.title) }); } }); });