Site Notice

hello, world

Difference between revisions of "MediaWiki:Js-InPageEdit-canary.js"

From Project-EPB Commons
([InPageEdit] 没有编辑摘要)
([InPageEdit] 没有编辑摘要)
 
(242 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
/**
 
/**
  *『Wjghj Project Static』
+
  * @license GPL-3.0 GNU GENERAL PUBLIC LICENSE 3.0
* This _JavaScript_ code is from https://common.wjghj.cn
 
* GNU GENERAL PUBLIC LICENSE 3.0
 
 
  *
 
  *
  * MediaWiki JS Plugin: In Page Edit Canary Edition
+
  * @name InPageEdit-v2
* Version: InPageEdit-canary
+
  * @description A JavaScript-based MediaWiki Plugin:  
  * Author: 机智的小鱼君
+
  * @author 机智的小鱼君
  * Url:
+
  * @url https://github.com/Dragon-Fish/InPageEdit-v2
  ** https://github.com/Dragon-Fish/InPageEdit-v2
+
  */
  ** https://common.wjghj.cn/wiki/InPageEdit-v2
+
!(function (root, factory) {
* Logs:
+
  root.InPageEdit = factory(root.jQuery);
** https://common.wjghj.cn/wiki/InPageEdit-v2/version-info
+
}(this, function ($) {
**/
 
 
 
(function () {
 
 
   'use strict';
 
   'use strict';
   if (typeof InPageEdit !== 'undefined') throw '[InPageEdit] 已经有一个IPE插件在执行了';
+
  /**
 +
  * @description 检查插件是否已经运行,创建全局函数
 +
  */
 +
  window.InPageEdit = window.InPageEdit || {};
 +
   if (typeof (InPageEdit.version) !== 'undefined') { throw '[InPageEdit] 已经有一个IPE插件在执行了'; }
 +
  InPageEdit.isCanary = false;
 +
  InPageEdit.api = {
 +
    analysis: 'https://doc.wjghj.cn/inpageedit-v2/analysis/api/index.php',
 +
    aboutUrl: 'https://dragon-fish.github.io/inpageedit-v2/about/',
 +
    analysisUrl: 'https://dragon-fish.github.io/inpageedit-v2/analysis/',
 +
    updatelogsUrl: 'https://dragon-fish.github.io/inpageedit-v2/update-logs/'
 +
  }
 +
  InPageEdit.version = '2.13.4-5';
 +
  // 冻结重要全局变量
 +
  Object.freeze(InPageEdit.api);
 +
  Object.freeze(InPageEdit.version);
  
   // 创建全局函数
+
   /**
   window.InPageEdit = {};
+
  * @description 常用变量以及函数
 +
  */
 +
   var config = mw.config.get(),
 +
    _loadScript = function (src) {
 +
      return $.ajax({
 +
        url: src,
 +
        dataType: 'script',
 +
        crossDomain: !0,
 +
        cache: !0
 +
      });
 +
    };
  
   /** 导入模态框插件 **/
+
   /**
   mw.loader.load('https://cdn.bootcss.com/ssi-modal/1.0.27/js/ssi-modal.min.js');
+
  * @name 导入依赖
  $('title').after('<link id="ssi-modal-style" rel="stylesheet" href="https://cdn.bootcss.com/ssi-modal/1.0.27/styles/ssi-modal.min.css"/>');
+
  * @description 加载需要的依赖项,然后进行初始化
 +
  */
 +
   /* 样式表 */
 +
  $('head').prepend(
 +
    // 模态框
 +
    $('<link>', { rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/src/ssi_modal/ssi-modal.min.css' }),
 +
    // FontAwesome
 +
    $('<link>', { rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/npm/[email protected]/css/font-awesome.min.css' }),
 +
    // 覆写
 +
    $('<link>', { rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/src/skin/ipe-default.min.css' })
 +
  );
 +
  /* I18n-js */
 +
  _loadScript('https://cdn.jsdelivr.net/gh/dragon-fish/i18n-js@master/script.min.js'); // 因为留有钩子,无需异步,与模态框同时加载提升速度
 +
  /* 模态框 */
 +
  _loadScript('https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/src/ssi_modal/ssi-modal.min.js').done(() => {
 +
    mw.hook('dfgh.i18n').add(i18nJs => {
 +
      i18nJs.loadMessages('InPageEdit-v2').then(init);
 +
    })
 +
  }).fail((...res) => {
 +
    console.error('[InPageEdit] 初始化时遇到致命错误:', ...res);
 +
  });
  
   /** 获取版本信息 **/
+
   /**
   mw.loader.load('https://common.wjghj.cn/js/InPageEdit-v2.js/version-info-canary');
+
  * @function InPageEdit
 +
  */
 +
   function init(i18n) {
 +
    /**
 +
    * @function i18n模块
 +
    * @param {string} 'message-name', '$1', '$2', ...
 +
    * @example _msg('updatelog-update-success', InPageEdit.version) => InPageEdit <version> has been installed.
 +
    */
 +
    function _msg(...args) {
 +
      var msgName = args.shift();
 +
      return i18n.msg(msgName, ...args).parse();
 +
    }
  
  /** 样式表 **/
+
    /**
  // 皮肤
+
    * @description 常用 html 结构
  $('link#ssi-modal-style').after('<link rel="stylesheet" href="https://common.wjghj.cn/css/InPageEdit-v2"/>');
+
    */
  // Material icons
+
    var $br = '<br>',
  mw.loader.load('https://cdn.bootcss.com/material-design-icons/3.0.1/iconfont/material-icons.min.css', 'text/css');
+
      $hr = '<hr>',
 +
      $progress = '<div class="ipe-progress" style="width: 100%"><div class="ipe-progress-bar"></div></div>';
  
  /*** BOT FLAG ***/
+
    /**
  /** InPageEdit主框架 **/
+
    * @module 快速编辑模块
  /** 多语言环境 **/
+
    *  
  $.ajax({
+
    * @param {Object} options
    url: 'https://common.wjghj.cn/api.php',
+
    * @param {String} options.page edit page (default: wgPageName)
    data: {
+
    * @param {Number} options.revision page rev ID
      page: 'MediaWiki:InPageEdit-v2/i18n.json',
+
    * @param {Number} options.section edit section
      action: 'parse',
+
    * @param {Boolean} options.reload if reload page after save successful (default: true)
      prop: 'wikitext',
+
    */
      format: 'json'
+
     InPageEdit.edit = InPageEdit.quickEdit = function (options) {
     },
+
       mw.hook('InPageEdit.quickEdit').fire();
    dataType: 'jsonp',
+
       /** 获取设定信息,设置缺省值 **/
    success: function (i18n) {
+
      var options = options || {};
       // i18n
+
      if (typeof options === 'string') {
      var i18nMsg = JSON.parse(i18n.parse.wikitext['*']);
+
         options = {
      mw.config.set('InPageEdit_i18n', i18nMsg);
+
           page: options
       function msg(i) {
 
        var i18n = mw.config.get('InPageEdit_i18n', i18n),
 
          lang = mw.config.get('wgUserLanguage'),
 
          final;
 
         switch (lang) {
 
           case 'zh':
 
          case 'zh-hans':
 
          case 'zh-cn':
 
            lang = 'zh-hans';
 
            break;
 
          case 'zh-hant':
 
          case 'zh-tw':
 
          case 'zh-hk':
 
            lang = 'zh-hant';
 
            break;
 
 
         }
 
         }
         if (i18n['en'].hasOwnProperty(i)) {
+
      }
           final = i18n['en'][i]
+
      var defaultOptions = {
        } else {
+
        page: config.wgPageName,
          final = '&lt;' + i + '&gt;';
+
         pageId: -1,
 +
        revision: null,
 +
        summaryRevision: '',
 +
        section: null,
 +
        editText: '',
 +
        editMinor: false,
 +
        editSummary: _msg('preference-summary-default'),
 +
        editNotice: '',
 +
        outSideClose: true,
 +
        jsonGet: {
 +
          action: 'parse',
 +
          page: options.page || config.wgPageName,
 +
          prop: 'wikitext|langlinks|categories|templates|images|sections',
 +
          format: 'json'
 +
        },
 +
        jsonPost: {},
 +
        pageDetail: {},
 +
        jumpTo: '',
 +
        reload: true
 +
      }
 +
 
 +
      /** 获取用户设置 **/
 +
      var preference = InPageEdit.preference.get();
 +
 
 +
      /** 缓存时间戳 **/
 +
      var date = new Date(),
 +
        timestamp = date.getTime(),
 +
        now = date.toUTCString();
 +
 
 +
      /** 将选项合并并标准化 **/
 +
      options = $.extend({}, defaultOptions, options, preference);
 +
      options.page = decodeURIComponent(options.page); // 解码网址 Unicode
 +
 
 +
      _analysis('quick_edit');
 +
 
 +
      if (options.revision !== null && options.revision !== '' && options.revision !== config.wgCurRevisionId) {
 +
        ssi_modal.notify('warning', {
 +
          className: 'in-page-edit',
 +
          content: _msg('notify-editing-history'),
 +
           title: _msg('notify-info')
 +
        });
 +
        delete options.jsonGet.page;
 +
        options.jsonGet.oldid = options.revision;
 +
        options.summaryRevision = '(' + _msg('editor-summary-rivision') + '[[Special:Diff/' + options.revision + ']])';
 +
      } else {
 +
        if (options.section !== null && options.section !== '') {
 +
          options.jsonGet.section = options.section;
 
         }
 
         }
        if (i18n.hasOwnProperty(lang)) {
+
       }
          if (i18n[lang].hasOwnProperty(i)) {
 
            final = i18n[lang][i];
 
          }
 
        }
 
        return final;
 
       };
 
  
       /** 快速编辑模块 **/
+
       // Debug
       InPageEdit.edit = function (option) {
+
       console.time('[InPageEdit] 获取页面源代码');
        // 变量
+
      console.info('[InPageEdit] QuickEdit start with options:');
        if (option === undefined)
+
      console.table(options);
          option = {};
 
        var preference = JSON.parse(localStorage.getItem('InPageEditPreference'));
 
        var editPage = decodeURIComponent(option.page),
 
          editSection = option.section,
 
          titleSection = '',
 
          editRevision = option.revision,
 
          titleRevision = '',
 
          summaryRevision = '',
 
          editText,
 
          editSummary = preference.editSummary,
 
          editMinor = preference.editMinor,
 
          editNotice = '',
 
          outSideClose = preference.outSideClose,
 
          jsonGet = {
 
            action: 'parse',
 
            page: editPage,
 
            prop: 'wikitext',
 
            format: 'json'
 
          },
 
          jsonGetInfo = {
 
            action: 'query',
 
            titles: editPage,
 
            prop: 'revisions|info',
 
            inprop: 'timestamp|protection',
 
            format: 'json'
 
          },
 
          jsonPost = {},
 
          protection = '',
 
          basetimestamp,
 
          date = new Date(),
 
          timestamp = date.getTime(),
 
          now = date.toUTCString(); // 缓存时间戳
 
  
         InPageEdit.analysis({ type: 'functionCount', function: '快速编辑' });
+
      // 显示主窗口
        InPageEdit.analysis({ type: 'siteCount' });
+
      ssi_modal.show({
        InPageEdit.analysis({ type: 'dateCount' });
+
        title: _msg('editor-title-editing') + ': <u class="editPage">' + options.page.replace(/\_/g, ' ') + '</u>',
 +
         content:
 +
          $('<div>').append(
 +
            $progress,
 +
            $('<section>', { class: 'hideBeforeLoaded' }).append(
 +
              // 编辑工具条
 +
              $('<div>', { class: 'editTools' }).append(
 +
                $('<div>', { class: 'btnGroup' }).append(
 +
                  $('<div>', { class: 'toolSelect' }).append(
 +
                    $('<div>', { class: 'label', text: _msg('editor-edittool-header') }),
 +
                    $('<ul>', { class: 'ul-list' }).append(
 +
                      $('<li>', { class: 'editToolBtn', 'data-open': '\n== ', 'data-middle': _msg('editor-edittool-header-text'), 'data-close': ' ==\n', text: 'H2' }),
 +
                      $('<li>', { class: 'editToolBtn', 'data-open': '\n=== ', 'data-middle': _msg('editor-edittool-header-text'), 'data-close': ' ===\n', text: 'H3' }),
 +
                      $('<li>', { class: 'editToolBtn', 'data-open': '\n==== ', 'data-middle': _msg('editor-edittool-header-text'), 'data-close': ' ====\n', text: 'H4' }),
 +
                      $('<li>', { class: 'editToolBtn', 'data-open': '\n===== ', 'data-middle': _msg('editor-edittool-header-text'), 'data-close': ' =====\n', text: 'H5' })
 +
                    )
 +
                  )
 +
                ),
 +
                $('<div>', { class: 'btnGroup' }).append(
 +
                  $('<span>', { class: 'label', text: '格式' }),
 +
                  $('<button>', { class: 'editToolBtn fa fa-bold btn', 'data-open': "'''", 'data-middle': _msg('editor-edittool-bold'), 'data-close': "'''" }),
 +
                  $('<button>', { class: 'editToolBtn fa fa-italic btn', 'data-open': "''", 'data-middle': _msg('editor-edittool-italic'), 'data-close': "''" }),
 +
                  $('<button>', { class: 'editToolBtn fa fa-list-ul btn', 'data-open': '\n* ', 'data-middle': _msg('editor-edittool-list-bulleted'), 'data-close': '\n' }),
 +
                  $('<button>', { class: 'editToolBtn fa fa-list-ol btn', 'data-open': '\n# ', 'data-middle': _msg('editor-edittool-list-numbered'), 'data-close': '\n' }),
 +
                  $('<button>', { class: 'editToolBtn fa fa-won btn', 'data-open': '<' + 'nowiki>', 'data-middle': _msg('editor-edittool-nowiki'), 'data-close': '</nowiki>' }),
 +
                  $('<button>', { class: 'editToolBtn fa fa-level-down fa-rotate-90 btn', 'data-open': '<br>\n', 'data-middle': '', 'data-close': '' })
 +
                ),
 +
                $('<div>', { class: 'btnGroup' }).append(
 +
                  $('<span>', { class: 'label', text: '插入' }),
 +
                  $('<button>', { class: 'editToolBtn fa fa-link btn', 'data-open': '[' + '[', 'data-middle': _msg('editor-edittool-internal-link'), 'data-close': ']]' }),
 +
                  $('<button>', { class: 'editToolBtn fa fa-file-image-o btn', 'data-open': '[' + '[File:', 'data-middle': 'Example.png', 'data-close': '|thumb]]' }),
 +
                  $('<button>', { class: 'editToolBtn btn', 'data-open': '\n<' + 'gallery>\n', 'data-middle': 'Example1.jpg|Description\nExample2.png|Description', 'data-close': '\n</gallery>\n', html: '<span class="fa-stack"><i class="fa fa-picture-o fa-stack-1x"></i><i class="fa fa-picture-o fa-stack-1x" style="left: 2px;top: 2px;text-shadow: 1px 1px 0 #fff;"></i></span>' })
 +
                ),
 +
                $('<div>', { class: 'btnGroup extra', style: 'display: none' }).append(
 +
                  $('<span>', { class: 'label', text: '自定义' })
 +
                ),
 +
                $('<div>', { class: 'btnGroup special-tools', style: 'float: right' }).append(
 +
                  $('<button>', { class: 'btn fa fa-search' }).click(function () {
 +
                    InPageEdit.findAndReplace($('.ipe-editor.timestamp-' + timestamp + ' .editArea'));
 +
                  })
 +
                )
 +
              ),
 +
              // 编辑框
 +
              $('<textarea>', { class: 'editArea', style: 'margin-top: 0;' }),
 +
              // 页面分析
 +
              $('<div>', { class: 'editOptionsLabel hideBeforeLoaded' }).append(
 +
                $('<aside>', { class: 'detailArea' }).append(
 +
                  $('<label>', { class: 'detailToggle', text: _msg('editor-detail-button-toggle') }),
 +
                  $('<div>', { class: 'detailBtnGroup' }).append(
 +
                    $('<a>', { href: 'javascript:;', class: 'detailBtn', id: 'showTemplates', text: _msg('editor-detail-button-templates') }),
 +
                    ' | ',
 +
                    $('<a>', { href: 'javascript:;', class: 'detailBtn', id: 'showImages', text: _msg('editor-detail-button-images') })
 +
                  )
 +
                ),
 +
                // 摘要&小编辑
 +
                $('<label>', { for: 'editSummary', text: _msg('editSummary') }),
 +
                $br,
 +
                $('<input>', { class: 'editSummary', id: 'editSummary', placeholder: 'Edit via InPageEdit~', value: options.editSummary.replace(/\$oldid/ig, options.summaryRevision) }),
 +
                $br,
 +
                $('<label>').append(
 +
                  $('<input>', { type: 'checkbox', class: 'editMinor', id: 'editMinor', checked: options.editMinor }),
 +
                  $('<span>', { text: _msg('markAsMinor') })
 +
                ),
 +
                $br,
 +
                $('<label>').append(
 +
                  $('<input>', { type: 'checkbox', class: 'reloadPage', id: 'reloadPage', checked: options.reload }),
 +
                  $('<span>', { text: _msg('editor-reload-page') })
 +
                )
 +
              )
 +
            )
 +
          ),
 +
        outSideClose: options.outSideClose,
 +
        className: 'in-page-edit ipe-editor timestamp-' + timestamp,
 +
        sizeClass: 'large',
  
         if (editPage === undefined) editPage = mw.config.get('wgPageName');
+
         /* 按钮 */
        if (editRevision !== undefined && editRevision !== '' && editRevision !== mw.config.get('wgCurRevisionId')) {
+
        buttons: [{
          ssi_modal.notify('warning', {
+
          label: _msg('editor-button-save'),
            className: 'in-page-edit',
+
          className: 'btn btn-primary leftBtn hideBeforeLoaded save-btn',
            content: msg('notify-editing-history'),
+
          method: function (e, modal) {
            title: msg('notify-info')
+
            var modal = modal;
          });
+
            ssi_modal.confirm({
          delete jsonGet.page;
+
              className: 'in-page-edit',
          jsonGet.oldid = editRevision;
+
              center: true,
          titleRevision = '<span style="font-size:small;">(' + msg('editor-title-editRevision') + '' + editRevision + ')</span>';
+
              content: _msg('editor-confirm-save'),
          summaryRevision = '(' + msg('editor-summary-rivision') + '[[Special:Diff/' + editRevision + ']])';
+
              okBtn: {
         } else {
+
                className: 'btn btn-primary',
           if (editSection !== undefined && editSection !== '' && editSection !== null) {
+
                label: _msg('confirm')
             jsonGet.section = editSection;
+
              },
            titleSection = msg('editor-title-editSection').replace('$1', editSection);
+
              cancelBtn: {
 +
                className: 'btn btn-secondary',
 +
                label: _msg('cancel')
 +
              },
 +
            },
 +
              function (result) {
 +
                if (result) {
 +
                  var text = $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val(),
 +
                    minor = $('.ipe-editor.timestamp-' + timestamp + ' .editMinor').prop('checked'),
 +
                    section = options.section,
 +
                    summary = $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val();
 +
                  postArticle({
 +
                    text: text,
 +
                    page: options.page,
 +
                    minor: minor,
 +
                    section: section,
 +
                    summary: summary
 +
                  }, modal);
 +
                }
 +
              });
 +
          }
 +
        }, {
 +
          label: _msg('editor-button-preview'),
 +
          className: 'btn btn-secondary leftBtn hideBeforeLoaded',
 +
          method: function () {
 +
            _analysis('preview_edit');
 +
            var text = $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val();
 +
            InPageEdit.quickPreview({
 +
              title: options.page,
 +
              text: text,
 +
              pst: true
 +
            });
 +
          }
 +
         }, {
 +
           label: _msg('editor-button-diff'),
 +
          className: 'btn btn-secondary leftBtn hideBeforeLoaded diff-btn',
 +
          method: function () {
 +
             // ...
 +
          }
 +
        }, {
 +
          label: _msg('cancel'),
 +
          className: 'btn btn-danger',
 +
          method: function (e, modal) {
 +
            modal.close();
 
           }
 
           }
 
         }
 
         }
         if (typeof (MyInPageEditPreference) !== 'undefined') {
+
         ],
          if (typeof (MyInPageEditPreference.editSummary) === 'string')
 
            editSummary = MyInPageEditPreference.editSummary;
 
          if (typeof (MyInPageEditPreference.editMinor) === 'boolean')
 
            editMinor = MyInPageEditPreference.editMinor;
 
          if (typeof (MyInPageEditPreference.outSideClose) === 'boolean')
 
            outSideClose = MyInPageEditPreference.outSideClose;
 
        }
 
 
 
        // Debug
 
        console.time('[InPageEdit] 获取页面源代码');
 
        console.info('%c[InPageEdit] Edit function running with params: ', 'color:#fe20d1');
 
        console.table({
 
          'editPage': editPage,
 
          'editSection': editSection,
 
          'titleSection': titleSection,
 
          'editRevision': editRevision,
 
          'titleRevision': titleRevision,
 
          'editSummary': editSummary,
 
          'editMinor': editMinor,
 
          'now': now
 
        });
 
  
         // 显示主窗口
+
         /* 预加载 */
         var $ipe_progress = $('<div>', {class:'ipe-progress',style:'width: 100%'}).append($('<div>',{class:'ipe-progress-bar'}))[0].outerHTML;
+
         beforeShow: function () {
        ssi_modal.show({
+
          // 设置样式
           title: msg('editor-title-editing') + ': <u class="editPage">' + editPage + '</u>' + titleSection + titleRevision,
+
          $('.ipe-editor.timestamp-' + timestamp + ' .hideBeforeLoaded').hide();
           content: $ipe_progress + '<section class="editForm"><textarea class="editArea"></textarea><div class="editOptionsLabel editForm"><label for="editSummary">' + msg('editSummary') + ':</label><br/><input id="editSummary" class="editSummary" placeholder="Edit via InPageEdit~"/><br/><input id="editMinor" class="editMinor" type="checkbox" style=""/><label for="editMinor">' + msg('markAsMinor') + '</label></div></section>',
+
          $('.ipe-editor.timestamp-' + timestamp + ' .ipe-progress').css('margin', Number($(window).height() / 3 - 50) + 'px 0');
           outSideClose: outSideClose,
+
           $('.ipe-editor.timestamp-' + timestamp + ' .editArea').css('height', $(window).height() / 3 * 2 - 100);
          className: 'in-page-edit ipe-editor timestamp-' + timestamp,
+
           $('.ipe-editor.timestamp-' + timestamp + ' .editOptionsLabel').prependTo('.ipe-editor.timestamp-' + timestamp + ' .ssi-buttons');
          sizeClass: 'large',
+
          $('.ipe-editor.timestamp-' + timestamp + ' .leftBtn').appendTo('.ipe-editor.timestamp-' + timestamp + ' .ssi-leftButtons');
 
+
           $('.ipe-editor.timestamp-' + timestamp + ' .ssi-modalTitle').append(
          /* 按钮 */
+
            $('<a>', {
          buttons: [{
+
              class: 'showEditNotice',
            label: msg('editor-button-save'),
+
              href: 'javascript:void(0);',
            className: 'btn btn-primary leftBtn editForm',
+
              html: '<i class="fa fa-info-circle"></i> ' + _msg('editor-has-editNotice'),
             method: function () {
+
              style: 'display: none;'
               ssi_modal.confirm({
+
             }).click(function () {
 +
               ssi_modal.show({
 
                 className: 'in-page-edit',
 
                 className: 'in-page-edit',
 
                 center: true,
 
                 center: true,
                 content: msg('editor-confirm-save'),
+
                 title: _msg('editor-title-editNotice'),
                 okBtn: {
+
                 content: '<section class="editNotice">' + $('.ipe-editor.timestamp-' + timestamp).data('editNotice') + '</section>'
                  className: 'btn btn-primary',
 
                  label: msg('confirm')
 
                },
 
                cancelBtn: {
 
                  className: 'btn btn-secondary',
 
                  label: msg('cancel')
 
                },
 
              },
 
                function (result) {
 
                  if (result) {
 
                    var text = $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val(),
 
                      minor = $('.ipe-editor.timestamp-' + timestamp + ' .editMinor').prop('checked'),
 
                      section = option.section,
 
                      summary = $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val();
 
                    postArticle({
 
                      text: text,
 
                      page: editPage,
 
                      minor: minor,
 
                      section: section,
 
                      summary: summary
 
                    });
 
                  }
 
                })
 
            }
 
          }, {
 
            label: msg('editor-button-preview'),
 
            className: 'btn btn-secondary leftBtn editForm',
 
            method: function () {
 
              InPageEdit.analysis({ type: 'functionCount', function: 'previewEdit' });
 
              var text = $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val();
 
              InPageEdit.quickPreview({
 
                action: 'parse',
 
                title: editPage,
 
                text: text,
 
                prop: 'text',
 
                preview: true,
 
                format: 'json'
 
 
               });
 
               });
 +
            })
 +
          );
 +
 +
          /** Edit-Tool 扩展 **/
 +
          function insertText(strings, obj) {
 +
            var strings = strings,
 +
              textarea = obj || $('.in-page-edit.ipe-editor .editArea')[0],
 +
              start = textarea.selectionStart,
 +
              stop = textarea.selectionEnd,
 +
              selectedText = textarea.value.slice(start, stop);
 +
            textarea.value =
 +
              textarea.value.slice(0, start) +
 +
              (strings.open || '') +
 +
              (selectedText || strings.middle || '') +
 +
              (strings.close || '') +
 +
              textarea.value.slice(stop);
 +
            var selectStart = start + (strings.open.length || 0);
 +
            textarea.setSelectionRange(selectStart, selectStart + (selectedText.length || strings.middle.length || 0));
 +
            textarea.focus();
 +
          }
 +
          // 用户自定义按钮
 +
          if (InPageEdit.buttons) {
 +
            var btns = InPageEdit.buttons;
 +
            $('.ipe-editor.timestamp-' + timestamp + ' .btnGroup.extra').show();
 +
            function addBtn(open, middle, close, icon) {
 +
              var open = open || '',
 +
                middle = middle || '',
 +
                close = close || '',
 +
                icon = 'fa-' + icon || 'fa-wrench';
 +
              $('.ipe-editor.timestamp-' + timestamp + ' .btnGroup.extra').append(
 +
                $('<button>', { class: 'editToolBtn btn', 'data-open': open, 'data-middle': middle, 'data-close': close, html: `<i class="fa ${icon}"></i>` })
 +
              );
 
             }
 
             }
          }, {
+
             for (var i = 0; i < btns.length; i++) {
             label: msg('editor-button-diff'),
+
               var btn = btns[i];
            className: 'btn btn-secondary leftBtn editForm',
+
               addBtn(btn.open, btn.middle, btn.close, btn.text);
            method: function () {
 
              InPageEdit.analysis({ type: 'functionCount', function: '快速差异Edit' });
 
              var text = $('.editArea').val();
 
               var diffJson = {};
 
               diffJson.fromtext = editText;
 
              diffJson.totext = text;
 
              diffJson.hideBtn = true;
 
              diffJson.pageName = editPage;
 
              diffJson.isPreview = true;
 
              InPageEdit.quickDiff(diffJson);
 
            }
 
          }, {
 
            label: msg('editor-button-findAndReplace'),
 
            className: 'btn btn-secondary leftBtn editForm',
 
            method: function () {
 
              InPageEdit.analysis({ type: 'functionCount', function: '查找替换' });
 
              InPageEdit.findAndReplace($('.ipe-editor.timestamp-' + timestamp + ' .editArea'));
 
            }
 
          }, {
 
            label: msg('cancel'),
 
            className: 'btn btn-danger',
 
            method: function (e, modal) {
 
              modal.close();
 
 
             }
 
             }
 
           }
 
           }
           ],
+
           $('.ipe-editor.timestamp-' + timestamp + ' .editToolBtn').click(function (e) {
 
+
            e.preventDefault();
           /* 开始执行后续程序 */
+
            var $this = $(this),
          onShow: function (modal) {
+
              $open = $this.attr('data-open') || '',
            // 绑定事件,在尝试离开页面时提示
+
              $middle = $this.attr('data-middle') || '',
 +
              $close = $this.attr('data-close') || '';
 +
            insertText({
 +
              open: $open,
 +
              middle: $middle,
 +
              close: $close
 +
            }, $('.ipe-editor.timestamp-' + timestamp + ' .editArea')[0]);
 +
           });
 +
        },
 +
        /**
 +
        * @event onShow
 +
        * @description 模态框显示后
 +
        */
 +
        onShow: function (a, modal) {
 +
          mw.hook('InPageEdit.quickEdit.modal').fire();
 +
          // 绑定事件,在尝试离开页面时提示
 +
          $('.ipe-editor.timestamp-' + timestamp + ' .editArea').change(function () {
 +
            $(this).attr('data-modifiled', 'true');
 
             $(window).bind('beforeunload', function () {
 
             $(window).bind('beforeunload', function () {
               return msg('window-leave-confirm');
+
               return _msg('window-leave-confirm');
 
             });
 
             });
            // 设置样式
+
          });
            $('.ipe-editor.timestamp-' + timestamp + ' .editForm').hide();
+
          // 获取权限
            $('.ipe-editor.timestamp-' + timestamp + ' .ipe-progress').css('margin', Number($(window).height() / 3 - 50) + 'px 0');
+
          if (_hasRight('edit') === false) {
            $('.ipe-editor.timestamp-' + timestamp + ' .editArea').css('height', $(window).height() / 3 * 2 - 100);
+
            ssi_modal.notify('dialog', {
            $('.ipe-editor.timestamp-' + timestamp + ' .editOptionsLabel').prependTo('.ipe-editor.timestamp-' + timestamp + ' .ssi-buttons');
+
              className: 'in-page-edit',
            $('.leftBtn').appendTo('.ssi-leftButtons');
+
              position: 'center bottom',
            // 获取页面保护等级+最后编辑时间戳
+
              title: _msg('notify-no-right'),
            console.time('[InPageEdit] 获取页面基础信息');
+
              content: _msg('editor-no-right'),
            new mw.Api().get(jsonGetInfo).then(function (data) {
+
              okBtn: {
              if (data && data.query && data.query.pages) {
+
                label: _msg('ok'),
                var info = data.query.pages;
+
                className: 'btn btn-primary',
                for (var key in info) {
+
                method: function (e, modal) {
                  if (key !== '-1') {
+
                  modal.close();
                    console.timeEnd('[InPageEdit] 获取页面基础信息');
 
                    console.info('[InPageEdit] 获取页面基础信息成功');
 
                    if (info[key].touched) {
 
                      $('.ipe-editor.timestamp-' + timestamp).attr('data-basetimestamp', info[key].touched);
 
                    } else {
 
                      $('.ipe-editor.timestamp-' + timestamp).attr('data-basetimestamp', now);
 
                    }
 
                    if (info[key].protection) {
 
                      if (typeof (info[key].protection[0].level) !== 'undefined') {
 
                        if (info[key].protection[0].type === 'edit') {
 
                          protection = info[key].protection[0].level;
 
                        }
 
                      }
 
                      if ((protection === 'autoconfirmed' && !InPageEdit.hasRight('autoconfirmed')) || (protection === 'sysop' && !InPageEdit.hasRight('editprotected')) || (mw.config.get('wgNamespaceNumber') === 8 && !InPageEdit.hasRight('editinterface'))) {
 
                        ssi_modal.notify('dialog', {
 
                          className: 'in-page-edit',
 
                          position: 'center bottom',
 
                          title: msg('notify-no-right'),
 
                          content: msg('editor-no-right'),
 
                          okBtn: {
 
                            label: msg('ok'),
 
                            className: 'btn btn-primary',
 
                            method: function (e, modal) {
 
                              modal.close();
 
                            }
 
                          }
 
                        });
 
                        $('.ipe-editor.timestamp-' + timestamp + ' .editArea').attr('readonly', 'readonly');
 
                        $('.ipe-editor.timestamp-' + timestamp + ' button.editForm').attr('disabled', 'disabled');
 
                      }
 
                    }
 
                  } else {
 
                    console.timeEnd('[InPageEdit] 获取页面基础信息');
 
                    console.warn('[InPageEdit] 获取页面基础信息失败');
 
                  }
 
 
                 }
 
                 }
 
               }
 
               }
             }).fail(function () {
+
            });
 +
            $('.ipe-editor.timestamp-' + timestamp + ' .save-btn').addClass('btn-danger');
 +
          }
 +
 
 +
          // 解析页面内容
 +
          new mw.Api().get(options.jsonGet).done(function (data) {
 +
            var data = data;
 +
            console.timeEnd('[InPageEdit] 获取页面源代码');
 +
            contentDone(data);
 +
          }).fail(function (a, b, errorThrown) {
 +
            console.timeEnd('[InPageEdit] 获取页面源代码');
 +
            console.warn('[InPageEdit]警告:无法获取页面内容');
 +
            var data = errorThrown;
 +
            contentDone(data);
 +
          });
 +
 
 +
          // 页面内容获取完毕,后续工作
 +
          function contentDone(data) {
 +
            var data = data;
 +
            options.pageDetail = data;
 +
 
 +
            if (data.hasOwnProperty('error')) {
 +
              console.warn('[InPageEdit]警告:无法获取页面内容');
 +
              options.editText = '<!-- ' + data.error.info + ' -->';
 +
              options.pageId = -1;
 +
              $('.ipe-editor.timestamp-' + timestamp + ' .detailArea').hide();
 +
            } else {
 +
              options.editText = data.parse.wikitext['*'];
 +
              options.pageId = data.parse.pageid;
 +
            }
 +
            // 设定一堆子样式
 +
            $('.ipe-editor.timestamp-' + timestamp + ' .ipe-progress').hide();
 +
            $('.ipe-editor.timestamp-' + timestamp + ' .hideBeforeLoaded').fadeIn(500);
 +
            $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val(options.editText + '\n');
 +
 
 +
            if (options.section !== null) {
 +
              var val = $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val();
 +
              val = val.replace(/\$section/ig, '/* ' + data.parse.sections[0].line + ' */');
 +
              $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val(val);
 +
              $('.ipe-editor.timestamp-' + timestamp + ' .editPage').after('<span class="editSection">→' + data.parse.sections[0].line + '</span>');
 +
              options.jumpTo = '#' + data.parse.sections[0].anchor;
 +
            } else {
 +
              var val = $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val();
 +
              val = val.replace(/\$section/ig, '');
 +
              $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val(val);
 +
              options.jumpTo = '';
 +
            }
 +
            if (options.revision !== null && options.revision !== '' && options.revision !== config.wgCurRevisionId) {
 +
              $('.ipe-editor.timestamp-' + timestamp + ' .editPage').after('<span class="editRevision">(' + _msg('editor-title-editRevision') + ':' + options.revision + ')</span>');
 +
              $('.ipe-editor.timestamp-' + timestamp + ' .diff-btn').click(() => {
 +
                _analysis('quick_diff_edit');
 +
                var text = $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val();
 +
                var diffJson = {
 +
                  fromrev: options.revision,
 +
                  totext: text,
 +
                  hideBtn: true,
 +
                  pageName: options.page,
 +
                  isPreview: true
 +
                }
 +
                if (options.section) {
 +
                  diffJson.fromsection = options.section;
 +
                }
 +
                InPageEdit.quickDiff(diffJson);
 +
              });
 +
            } else {
 +
              $('.ipe-editor.timestamp-' + timestamp + ' .diff-btn').attr('disabled', true);
 +
            }
 +
 
 +
            // 获取页面基础信息
 +
            console.time('[InPageEdit] 获取页面基础信息');
 +
            var queryJson = {
 +
              action: 'query',
 +
              prop: 'revisions|info',
 +
              inprop: 'protection',
 +
              format: 'json'
 +
            }
 +
            if (options.pageId !== -1) {
 +
              queryJson.pageids = options.pageId;
 +
            } else {
 +
              queryJson.titles = options.page;
 +
            }
 +
            new mw.Api().get(queryJson).done(function (data) {
 +
              var data = data;
 +
              console.info('[InPageEdit] 获取页面基础信息成功');
 +
              console.timeEnd('[InPageEdit] 获取页面基础信息');
 +
              // 记录页面最后编辑时间,防止编辑冲突
 +
              $('.ipe-editor.timestamp-' + timestamp).data('basetimestamp', data['query']['pages'][options.pageId].hasOwnProperty('revisions') ? data['query']['pages'][options.pageId]['revisions'][0]['timestamp'] : now);
 +
              queryDone(data);
 +
             }).fail(function (a, b, errorThrown) {
 +
              var data = errorThrown;
 
               console.timeEnd('[InPageEdit] 获取页面基础信息');
 
               console.timeEnd('[InPageEdit] 获取页面基础信息');
 
               console.warn('[InPageEdit] 获取页面基础信息失败');
 
               console.warn('[InPageEdit] 获取页面基础信息失败');
 +
              $('.ipe-editor.timestamp-' + timestamp).data('basetimestamp', now);
 +
              queryDone(data);
 
             });
 
             });
             // 获取页面代码
+
 
             new mw.Api().get(jsonGet).then(function (data) {
+
             /** 页面保护等级和编辑提示等 **/
               console.timeEnd('[InPageEdit] 获取页面源代码');
+
             function queryDone(data) {
               if (data.error === undefined) {
+
               var data = data;
                 editText = data.parse.wikitext['*']
+
              options.namespace = data.query.pages[options.pageId].ns; // 名字空间ID
               } else {
+
              options.protection = data.query.pages[options.pageId]['protection'] || []; // 保护等级
                 console.timeEnd('[InPageEdit] 获取页面源代码');
+
               if (data.query.pages[options.pageId].hasOwnProperty('revisions')) {
                editText = '<!-- 警告:无法获取页面内容 -->';
+
                 options.revision = data.query.pages[options.pageId]['revisions'][0]['revid']; // 版本号
                console.error('[InPageEdit]警告:无法获取页面内容');
+
               }
 +
 
 +
              // 使页面名标准化
 +
              options.page = data.query.pages[options.pageId].title;
 +
              $('.ipe-editor.timestamp-' + timestamp + ' .editPage').text(options.page);
 +
 
 +
              if (options.revision) {
 +
                 $('.ipe-editor.timestamp-' + timestamp + ' .diff-btn').attr('disabled', false).click(function () {
 +
                  _analysis('quick_diff_edit');
 +
                  var text = $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val();
 +
                  var diffJson = {
 +
                    fromrev: options.revision,
 +
                    totext: text,
 +
                    hideBtn: true,
 +
                    pageName: options.page,
 +
                    isPreview: true
 +
                  }
 +
                  if (options.section) {
 +
                    diffJson.fromsection = options.section;
 +
                  }
 +
                  InPageEdit.quickDiff(diffJson);
 +
                })
 
               }
 
               }
              $('.ipe-editor.timestamp-' + timestamp + ' .ipe-progress').hide();
+
 
               $('.ipe-editor.timestamp-' + timestamp + ' .editForm').fadeIn(500);
+
               // 页面是否被保护
               $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val(editText + '\n');
+
               if (options.protection.length > 0) {
            }).fail(function (data) {
+
                for (var i = 0; i < options.protection.length; i++) {
              console.timeEnd('[InPageEdit] 获取页面源代码');
+
                  if (options.protection[i].type === 'edit') {
              editText = '<!-- 警告:无法获取页面内容 -->';
+
                    if (
              console.error('[InPageEdit]警告:无法获取页面内容');
+
                      (options.protection[i].level === 'autoconfirmed' && !_hasRight('autoconfirmed')) ||
              $('.ipe-editor.timestamp-' + timestamp + ' .ipe-progress').hide();
+
                      (options.protection[i].level === 'sysop' && !_hasRight('editprotected')) ||
              $('.ipe-editor.timestamp-' + timestamp + ' .editForm').fadeIn(500);
+
                      (config.wgNamespaceNumber === 8 && !_hasRight('editinterface'))
              $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val(editText + '\n');
+
                     ) {
            });
+
                       ssi_modal.notify('dialog', {
            // 设定状态
 
            if (editMinor) {
 
              $('.ipe-editor.timestamp-' + timestamp + ' .editMinor').attr('checked', 'checked');
 
            }
 
            $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val(editSummary.replace(/\$section/ig, $($.parseHTML(titleSection)).text()).replace(/\$oldid/ig, summaryRevision));
 
            // 获取编辑提示
 
            $.get(mw.config.get('wgScript'), {
 
              action: 'raw',
 
              title: 'MediaWiki:Editnotice-' + mw.config.get('wgNamespaceNumber')
 
            }, function (data) {
 
              new mw.Api().post({
 
                action: 'parse',
 
                title: editPage.replace(/\.(js|css|json)/g, '@Dot@$1'),
 
                preview: true,
 
                text: data
 
              }).then(function (data) {
 
                editNotice = '<section class="editNotice">' + data.parse.text['*'].replace(/\@Dot\@/g, '.') + '</section>';
 
                $('.ipe-editor.timestamp-' + timestamp + ' .ssi-modalTitle').append(
 
                  $('<a>')
 
                     .attr({
 
                      id: 'showEditNotice',
 
                      href: 'javascript:;'
 
                    })
 
                    .click(function () {
 
                       ssi_modal.show({
 
 
                         className: 'in-page-edit',
 
                         className: 'in-page-edit',
                         center: true,
+
                         position: 'center bottom',
                         title: msg('editor-title-editNotice'),
+
                        title: _msg('notify-no-right'),
                         content: editNotice
+
                         content: _msg('editor-no-right'),
 +
                         okBtn: {
 +
                          label: _msg('ok'),
 +
                          className: 'btn btn-primary',
 +
                          method: function (e, modal) {
 +
                            modal.close();
 +
                          }
 +
                        }
 
                       });
 
                       });
                     })
+
                      $('.ipe-editor.timestamp-' + timestamp + ' .save-btn').addClass('btn-danger');
                     .html('<i class="material-icons">info</i> ' + msg('editor-has-editNotice'))
+
                     }
                 );
+
                  }
 +
                }
 +
              }
 +
 
 +
              // 获取编辑提示
 +
              var namespaceNoticePage = 'Editnotice-' + options.namespace,
 +
                pageNoticePage = namespaceNoticePage + '-' +
 +
                  options.page
 +
                    .replace(/_/, ' ') // 将页面名里的 _ 转换为空格
 +
                     .replace(config.wgFormattedNamespaces[options.namespace] + ':', ''); // 去掉名字空间
 +
 
 +
              new mw.Api().get({
 +
                action: 'query',
 +
                meta: 'allmessages',
 +
                ammessages: namespaceNoticePage + '|' + pageNoticePage
 +
              }).done(function (data) {
 +
                var wikitextNs = data.query.allmessages[0]['*'] || '',
 +
                  wikitextPage = data.query.allmessages[1]['*'] || '';
 +
                if (wikitextNs === '' && wikitextPage === '') return; // 没有编辑提示
 +
                // 将编辑提示解析为 html
 +
                new mw.Api().post({
 +
                  action: 'parse',
 +
                  title: options.page,
 +
                  contentmodel: 'wikitext',
 +
                  preview: true,
 +
                  text: wikitextPage + '\n' + wikitextNs
 +
                }).done(function (data) {
 +
                  var data = data;
 +
                  options.editNotice = data.parse.text['*'];
 +
                  var notice = $('.ipe-editor.timestamp-' + timestamp).data('editNotice') || '';
 +
                  notice += '\n' + options.editNotice;
 +
                  $('.ipe-editor.timestamp-' + timestamp).data('editNotice', notice);
 +
                  $('.ipe-editor.timestamp-' + timestamp + ' .showEditNotice').show();
 +
                 });
 
               });
 
               });
            });
 
          },
 
  
          /* 确认是否取消 */
+
             }
          beforeClose: function (modal) {
 
             ssi_modal.confirm({
 
              className: 'in-page-edit',
 
              center: true,
 
              content: msg('editor-leave-confirm'),
 
              okBtn: {
 
                className: 'btn btn-danger',
 
                label: msg('confirm')
 
              },
 
              cancelBtn: {
 
                className: 'btn btn-secondary',
 
                label: msg('cancel')
 
              }
 
            },
 
              function (result) {
 
                if (result === true) {
 
                  $(window).unbind('beforeunload');
 
                  modal.options.keepContent = false;
 
                  modal.options.beforeClose = '';
 
                  modal.close();
 
                  ssi_modal.notify('info', {
 
                    className: 'in-page-edit',
 
                    position: 'right top',
 
                    title: msg('cancel'),
 
                    content: msg('notify-no-change')
 
                  })
 
                }
 
              });
 
            return false;
 
 
           }
 
           }
         });
+
         },
  
         // 发布编辑模块
+
         /* 确认是否取消 */
         function postArticle(pValue) {
+
         beforeClose: function (modal) {
           InPageEdit.analysis({ type: 'functionCount', function: '保存编辑' });
+
           if ($('.ipe-editor.timestamp-' + timestamp + ' .editArea').attr('data-modifiled') !== 'true') {
          InPageEdit.progress(msg('editor-title-saving'));
+
             close();
          jsonPost = {
+
             return;
             action: 'edit',
+
          } else if ($('.ipe-editor.timestamp-' + timestamp + ' .editArea').attr('data-confirmclose') === 'true') {
             basetimestamp: $('.ipe-editor.timestamp-' + timestamp).attr('data-basetimestamp'),
+
             closeNoReload();
             starttimestamp: now,
+
             return;
             text: pValue.text,
 
            title: pValue.page,
 
            minor: pValue.minor,
 
            summary: pValue.summary,
 
            errorformat: 'plaintext'
 
 
           }
 
           }
           if (pValue.section !== undefined && pValue.section !== '' && pValue.section !== null) {
+
           ssi_modal.confirm({
             jsonPost.section = pValue.section;
+
            className: 'in-page-edit',
             delete jsonPost.basetimestamp;
+
             center: true,
          }
+
             content: _msg('editor-leave-confirm'),
          // Debug
+
            okBtn: {
          console.info('%c[InPageEdit] Submitting with params: ', 'color:#fe20d1');
+
              className: 'btn btn-danger',
           console.table(jsonPost);
+
              label: _msg('confirm')
          new mw.Api().postWithToken('csrf', jsonPost).then(function (data) {
+
            },
            InPageEdit.progress(true);
+
            cancelBtn: {
 +
              className: 'btn btn-secondary',
 +
              label: _msg('cancel')
 +
            }
 +
           },
 +
            function (result) {
 +
              if (result === true) {
 +
                close();
 +
              }
 +
            });
 +
          function close() {
 
             $(window).unbind('beforeunload');
 
             $(window).unbind('beforeunload');
             ssi_modal.notify('success', {
+
            modal.options.keepContent = false;
 +
            modal.options.beforeClose = '';
 +
            modal.close();
 +
             ssi_modal.notify('info', {
 
               className: 'in-page-edit',
 
               className: 'in-page-edit',
 
               position: 'right top',
 
               position: 'right top',
               title: msg('notify-success'),
+
               title: _msg('cancel'),
               content: msg('notify-save-success')
+
              content: _msg('notify-no-change')
 +
            });
 +
          }
 +
          function closeNoReload() {
 +
            $(window).unbind('beforeunload');
 +
            modal.options.keepContent = false;
 +
            modal.options.beforeClose = '';
 +
            modal.close();
 +
          }
 +
          return false;
 +
        }
 +
      });
 +
 
 +
      // 页面详情模块
 +
      $('.ipe-editor.timestamp-' + timestamp + ' .detailBtnGroup .detailBtn').click(function () {
 +
        _analysis('quick_edit_pagedetail');
 +
        var $this = $(this),
 +
          id = $this.attr('id'),
 +
          content = $('<ul>');
 +
        switch (id) {
 +
          case 'showTemplates':
 +
            var templates = options.pageDetail.parse.templates,
 +
              templateName;
 +
            for (var i = 0; i < templates.length; i++) {
 +
               templateName = templates[i]['*'];
 +
              $('<li>').append(
 +
                $('<a>', { href: mw.util.getUrl(templateName), target: '_blank', text: templateName }),
 +
                ' (',
 +
                $('<a>', { href: 'javascript:;', text: _msg('quick-edit'), class: 'quickEditTemplate', 'data-template-name': templateName }),
 +
                ')'
 +
              ).appendTo(content);
 +
            }
 +
            ssi_modal.show({
 +
              className: 'in-page-edit quick-edit-detail',
 +
              sizeClass: 'dialog',
 +
              title: _msg('editor-detail-title-templates'),
 +
              content: content
 
             });
 
             });
             setTimeout(function () {
+
             break;
               if (pValue.page === mw.config.get('wgPageName')) {
+
          case 'showImages':
                window.location = mw.config.get('wgArticlePath').replace('$1', pValue.page);
+
            var images = options.pageDetail.parse.images,
               } else {
+
              imageName;
                window.location.reload();
+
            for (var i = 0; i < images.length; i++) {
              }
+
              imageName = images[i];
            }, 500);
+
              $('<li>').append(
          }).fail(function (errorCode, feedback, errorThrown) {
+
                $('<a>', { href: mw.util.getUrl('File:' + imageName), target: '_balnk', text: imageName }),
            InPageEdit.progress(false);
+
                ' (',
             ssi_modal.notify('error', {
+
                $('<a>', { href: 'javascript:;', class: 'quickViewImage', text: _msg('editor-detail-images-quickview'), 'data-image-name': imageName }),
 +
                ' | ',
 +
                $('<a>', { href: config.wgScript + '?title=Special:Upload&wpDestFile=' + imageName + '&wpForReUpload=1', target: '_balnk', text: _msg('editor-detail-images-upload') }),
 +
                ')'
 +
              ).appendTo(content);
 +
            }
 +
            ssi_modal.show({
 +
               className: 'in-page-edit quick-edit-detail',
 +
              sizeClass: 'dialog',
 +
              title: _msg('editor-detail-title-images'),
 +
              content: content
 +
            });
 +
            break;
 +
        }
 +
        $('.in-page-edit.quick-edit-detail .quickEditTemplate').click(function () {
 +
          _analysis('quick_edit_pagedetail_edit_template');
 +
          var $this = $(this);
 +
          var page = $this.attr('data-template-name');
 +
          InPageEdit.quickEdit({
 +
            page: page
 +
          });
 +
        });
 +
        $('.in-page-edit.quick-edit-detail .quickViewImage').click(function () {
 +
          _analysis('quick_edit_pagedetail_view_image');
 +
          var $this = $(this);
 +
          var imageName = $this.attr('data-image-name');
 +
          ssi_modal.show({
 +
            className: 'in-page-edit quick-view-image',
 +
            center: true,
 +
            title: imageName.replace(/_/g, ' '),
 +
            content: $('<center>', { id: 'imageLayer' }).append(
 +
              $progress
 +
            ),
 +
            buttons: [{
 +
              label: _msg('editor-detail-images-upload'),
 +
              className: 'btn btn-primary',
 +
              method: function (a, modal) { window.open(config.wgScript + '?title=Special:Upload&wpDestFile=' + imageName + '&wpForReUpload=1') }
 +
            }, {
 +
              label: _msg('close'),
 +
              className: 'btn btn-secondary',
 +
              method: function (a, modal) { modal.close() }
 +
            }],
 +
            onShow: function () {
 +
              new mw.Api().get({
 +
                action: 'query',
 +
                format: 'json',
 +
                prop: 'imageinfo',
 +
                titles: 'File:' + imageName.replace(/file:/g, ''),
 +
                iiprop: 'url'
 +
              }).done(function (data) {
 +
                $('.quick-view-image .ipe-progress').hide();
 +
                $('.quick-view-image #imageLayer').append(
 +
                  $('<img>', { src: data.query.pages['-1'].imageinfo[0].url, class: 'loading', style: 'max-width: 80%; max-height: 60vh' })
 +
                );
 +
                $('.quick-view-image #imageLayer img').load(function () {
 +
                  $(this).removeClass('loading');
 +
                });
 +
              })
 +
            }
 +
          });
 +
        });
 +
      });
 +
 
 +
      // 发布编辑模块
 +
      function postArticle(pValue, modal) {
 +
        var pValue = pValue,
 +
          modal = modal;
 +
        _analysis('quick_edit_save');
 +
        InPageEdit.progress(_msg('editor-title-saving'));
 +
        options.jsonPost = {
 +
          action: 'edit',
 +
          basetimestamp: $('.ipe-editor.timestamp-' + timestamp).data('basetimestamp'),
 +
          starttimestamp: now,
 +
          text: pValue.text,
 +
          title: pValue.page,
 +
          minor: pValue.minor,
 +
          summary: pValue.summary,
 +
          errorformat: 'plaintext'
 +
        }
 +
        if (pValue.section !== undefined && pValue.section !== '' && pValue.section !== null) {
 +
          options.jsonPost.section = pValue.section;
 +
          delete options.jsonPost.basetimestamp;
 +
        }
 +
 
 +
        new mw.Api().postWithToken('csrf', options.jsonPost).done(saveSuccess).fail(saveError);
 +
 
 +
        // 保存正常
 +
        function saveSuccess(data, feedback, errorThrown) {
 +
          if (data.edit.result === 'Success') {
 +
            InPageEdit.progress(true);
 +
            // 是否重载页面
 +
            if ($('.ipe-editor.timestamp-' + timestamp + ' .reloadPage').prop('checked')) {
 +
              var content;
 +
              $(window).unbind('beforeunload');
 +
              content = _msg('notify-save-success');
 +
               setTimeout(function () {
 +
                if (pValue.page === config.wgPageName) {
 +
                  window.location = mw.util.getUrl(pValue.page) + options.jumpTo;
 +
                  window.location.reload();
 +
                } else {
 +
                  window.location.reload();
 +
                }
 +
              }, 500);
 +
            } else {
 +
              console.info('[InPageEdit] 将不会重载页面!');
 +
              content = _msg('notify-save-success-noreload');
 +
              setTimeout(function () {
 +
                InPageEdit.progress(false);
 +
                $('.ipe-editor.timestamp-' + timestamp + ' .editArea').attr('data-confirmclose', 'true');
 +
                modal.close();
 +
              }, 1500);
 +
            }
 +
 
 +
             ssi_modal.notify('success', {
 
               className: 'in-page-edit',
 
               className: 'in-page-edit',
 
               position: 'right top',
 
               position: 'right top',
              closeAfter: {
+
               title: _msg('notify-success'),
                time: 15
+
               content: content
              },
 
               title: msg('notify-error'),
 
               content: msg('editor-save-error') + ':<br/><span style="font-size:amall">' + errorThrown.errors[0]['*'] + '(<code>' + errorThrown.errors[0]['code'] + '</code>)</span>'
 
 
             });
 
             });
             console.error('[InPageEdit] Submit failed: \nCode: ' + errorThrown.errors[0]['code'] + '\nDescription: ' + errorThrown.errors[0]['*']);
+
          } else {
 +
             saveError(data, feedback, errorThrown)
 +
          }
 +
        }
 +
 
 +
        // 保存失败
 +
        function saveError(errorCode, feedback, errorThrown) {
 +
          InPageEdit.progress(false);
 +
          var data = errorThrown || errorCode; // 规范错误代码
 +
          var errorCode,
 +
            errorInfo,
 +
            errorMore = '';
 +
          if (data.errors !== undefined) {
 +
            errorCode = data.errors[0].code;
 +
            errorInfo = data.errors[0]['*'];
 +
            errorMore = '';
 +
          } else if (data.edit.result !== 'Success') {
 +
            errorCode = data.edit.code || 'Unknown';
 +
            errorInfo = data.edit.info || 'Reason unknown.';
 +
            errorMore = data.edit.warning || '';
 +
          } else {
 +
            errorCode = 'unknown';
 +
            errorInfo = 'Reason unknown.';
 +
            errorMore = 'Please contact plug-in author or try again.'
 +
          }
 +
          ssi_modal.show({
 +
            className: 'in-page-edit',
 +
            sizeClass: 'dialog',
 +
            center: true,
 +
            title: _msg('editor-save-error'),
 +
            content: errorInfo + '<hr style="clear: both" />' + errorMore
 
           });
 
           });
 +
          ssi_modal.notify('error', {
 +
            className: 'in-page-edit',
 +
            position: 'right top',
 +
            closeAfter: {
 +
              time: 15
 +
            },
 +
            title: _msg('notify-error'),
 +
            content: _msg('editor-save-error') + ':<code>' + errorCode + '</code>'
 +
          });
 +
 +
          console.error('[InPageEdit] Submit failed: \nCode: ' + errorCode);
 +
          return;
 
         }
 
         }
 +
      }
 +
    }
 +
 +
    /**
 +
    * @module 查找替换模块
 +
    * @param {element} contengut Textarea
 +
    */
 +
    InPageEdit.findAndReplace = function (contengut) {
 +
      if (contengut === this.undefined) contengut = $('.in-page-edit.ipe-editor .editArea');
 +
      var origin = contengut.val();
 +
 +
      ssi_modal.show({
 +
        className: 'in-page-edit',
 +
        sizeClass: 'dialog',
 +
        center: true,
 +
        outSideClose: false,
 +
        // position: 'right bottom',
 +
        title: _msg('fAndR-title'),
 +
        content:
 +
          $('<div>', { class: 'module far-module' }).append(
 +
            $('<div>', { class: 'module_content', id: 'findfielddiv' }).append(
 +
              $('<section>').append(
 +
                $('<h4>', { text: _msg('fAndR-find-text') }),
 +
                $('<textarea>', { id: 'find_this', style: 'margin: 0', rows: 4 }),
 +
                $('<h4>', { text: _msg('fAndR-replace-text') }),
 +
                $('<textarea>', { id: 'replace_with', style: 'margin: 0', rows: 4 })
 +
              ),
 +
              $('<section>', { style: 'padding: 7px 0' }).append(
 +
                $('<label>').append(
 +
                  $('<input>', { type: 'checkbox', id: 'globl', checked: '' }),
 +
                  $('<span>', { text: _msg('fAndR-globl') })
 +
                ),
 +
                $br,
 +
                $('<label>').append(
 +
                  $('<input>', { type: 'checkbox', id: 'case_sen' }),
 +
                  $('<span>', { text: _msg('fAndR-case-sen') })
 +
                ),
 +
                $br,
 +
                $('<label>').append(
 +
                  $('<input>', { type: 'checkbox', id: 'regex_search' }),
 +
                  $('<span>', { text: _msg('fAndR-enable-regex') })
 +
                ),
 +
              )
 +
            )
 +
          ),
 +
        buttons: [
 +
          {
 +
            label: _msg('fAndR-button-undo'),
 +
            className: 'btn btn-danger',
 +
            method: function (e, modal) {
 +
              contengut.val(origin);
 +
              ssi_modal.notify('info', {
 +
                className: 'in-page-edit',
 +
                title: _msg('notify-info'),
 +
                content: _msg('notify-fAndR-undo')
 +
              });
 +
              // modal.close();
 +
            }
 +
          },
 +
          {
 +
            className: 'btn btn-primary',
 +
            label: _msg('fAndR-button-replace'),
 +
            method: function (a, modal) {
 +
              /**
 +
              * 查找替换主函数
 +
              * 借鉴:https://dev.fandom.com/wiki/MediaWiki:FindAndReplace/code.js
 +
              **/
 +
              if ($('#find_this').val() === '') return;
 +
              var searchfor = '',
 +
                searchexp,
 +
                $textarea = contengut,
 +
                replacewith = $('#replace_with').val().replace(/\r/gi, ''),
 +
                text = $textarea.val().replace(/\r/gi, ''),
 +
                flagg = 'g',
 +
                flagi = 'i',
 +
                enableregex = 0;
  
       };
+
              if ($('#globl').prop('checked') === false) {
 +
                flagg = '';
 +
              }
 +
              if ($('#case_sen').prop('checked') === true) {
 +
                flagi = '';
 +
              }
 +
              if ($('#regex_search').prop('checked') === true) {
 +
                enableregex = 1;
 +
              }
 +
              var flags = flagg + flagi + 'm';
 +
              if (enableregex === 1) {
 +
                searchfor = $('#find_this').val();
 +
              } else {
 +
                searchfor = $('#find_this').val().replace(/\r/gi, '').replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
 +
              }
 +
              searchexp = new RegExp(searchfor, flags);
 +
              var rcount = 0;
 +
              var matched = text.match(searchexp);
 +
              if (matched !== null) {
 +
                rcount = matched.length;
 +
              }
 +
              text = text.replace(searchexp, replacewith);
 +
              $textarea.val(text);
 +
              ssi_modal.notify('success', {
 +
                className: 'in-page-edit',
 +
                title: _msg('notify-success'),
 +
                content: _msg('notify-fAndR-done', rcount)
 +
              });
 +
              // modal.close();
 +
            }
 +
          }
 +
        ]
 +
       });
 +
    }
  
      /** 快速重定向模块 **/
+
    /** 快速重定向模块 **/
      InPageEdit.redirect = function (type) {
+
    InPageEdit.redirect = InPageEdit.quickRedirect = function (type = 'to') {
         var json = {
+
      mw.hook('InPageEdit.quickRedirect').fire();
 +
      var text = '#REDIRECT [[:$1]]',
 +
        question,
 +
        target,
 +
         json = {
 
           action: 'edit',
 
           action: 'edit',
           minor: JSON.parse(localStorage.getItem('InPageEditPreference')).editMinor,
+
           minor: InPageEdit.preference.get('editMinor'),
 
           token: mw.user.tokens.get('editToken'),
 
           token: mw.user.tokens.get('editToken'),
 
           errorformat: 'plaintext'
 
           errorformat: 'plaintext'
 
         },
 
         },
          summary = msg('redirect-summary') + ' → [[:$1]]',
+
        summary;
          text = '#REDIRECT [[:$1]]',
+
 
          question,
+
      if (type === 'to') {
          target;
+
        json.title = config.wgPageName;
        switch (type) {
+
        question = _msg('redirect-question-to', '<b>' + config.wgPageName.replace(/_/g, ' ') + '</b>');
          case 'to':
+
      } else if (type === 'from') {
            json.title = mw.config.get('wgPageName');
+
        question = _msg('redirect-question-from', '<b>' + config.wgPageName.replace(/_/g, ' ') + '</b>');
            question = msg('redirect-question-to').replace('$1', '<b>' + mw.config.get('wgPageName') + '</b>');
+
        summary = _msg('redirect-summary') + ' → [[:' + config.wgPageName + ']]';
            break;
+
        json.text = text.replace('$1', config.wgPageName);
          case 'from':
+
      } else {
            question = msg('redirect-question-from').replace('$1', '<b>' + mw.config.get('wgPageName') + '</b>');
+
        console.error('[InPageEdit] quickRedirect only accept "from" or "to"');
            json.text = text.replace('$1', mw.config.get('wgPageName'));
+
        return;
            json.summary = summary.replace('$1', mw.config.get('wgPageName'));
+
      }
            break;
+
 
        }
+
      ssi_modal.show({
        ssi_modal.show({
+
        outSideClose: false,
          outSideClose: false,
+
        className: 'in-page-edit quick-redirect',
          className: 'in-page-edit quick-redirect',
+
        center: true,
          center: true,
+
        sizeClass: 'dialog',
          sizeClass: 'dialog',
+
        title: _msg('redirect-title'),
          title: msg('redirect-title'),
+
        content: $('<div>').append(
          content: '<section>' + question + '<br/><input id="redirect-page" style="width:80%;margin: 0 10%;" onclick="$(this).css(\'box-shadow\',\'\')"/></section><div class="ipe-progress" style="width:100%;display:none"><div class="ipe-progress-bar"></div></div>',
+
          $('<section>').append(
          buttons: [{
+
            $('<span>', { html: question }),
            label: msg('confirm'),
+
            $br,
            className: 'btn btn-primary btn-single okBtn',
+
            $('<input>', { id: 'redirect-page', style: 'width:96%' }).click(function () { $(this).css('box-shadow', '') }),
            method: function (a, modal) {
+
            $br,
               InPageEdit.analysis({ type: 'functionCount', function: '快速重定向' });
+
            $('<label>', { for: 'redirect-reason', text: _msg('editSummary') }),
               InPageEdit.analysis({ type: 'dateCount' });
+
            $('<input>', { id: 'redirect-reason', style: 'width:96%' })
               InPageEdit.analysis({ type: 'siteCount' });
+
          ),
               var input = $('#redirect-page').val();
+
          $($progress).css('display', 'none')
              if (input === '' || input === mw.config.get('wgPageName')) {
+
        ),
                $('#redirect-page').css('box-shadow', '0 0 4px red');
+
        buttons: [{
 +
          label: _msg('confirm'),
 +
          className: 'btn btn-primary btn-single okBtn',
 +
          method: function (a, modal) {
 +
            target = $('.in-page-edit.quick-redirect #redirect-page').val();
 +
            if (target === '' || target.toLowerCase().replace(/_/g, ' ') === config.wgPageName.toLowerCase().replace(/_/g, ' ')) {
 +
               $('.in-page-edit.quick-redirect #redirect-page').css('box-shadow', '0 0 4px #f00');
 +
              return;
 +
            }
 +
 
 +
            _analysis('quick_redirect');
 +
 
 +
            if (type === 'to') {
 +
               summary = _msg('redirect-summary') + ' → [[:' + target + ']]';
 +
               json.text = text.replace('$1', target);
 +
            } else if (type === 'from') {
 +
              json.title = target;
 +
            }
 +
            if ($('.in-page-edit.quick-redirect #redirect-reason').val() !== '') {
 +
               summary = summary + ' (' + $('.in-page-edit.quick-redirect #redirect-reason').val() + ')';
 +
            }
 +
            json.summary = summary;
 +
 
 +
            $('.in-page-edit.quick-redirect .ipe-progress').show();
 +
            $('.in-page-edit.quick-redirect section').hide();
 +
            $('.in-page-edit.quick-redirect .okBtn').attr('disabled', 'disabled');
 +
 
 +
            new mw.Api().post(json).done(function () {
 +
              $('.in-page-edit.quick-redirect .ipe-progress').addClass('done');
 +
              ssi_modal.notify('success', {
 +
                className: 'in-page-edit',
 +
                content: _msg('notify-redirect-success'),
 +
                title: _msg('notify-success')
 +
              });
 +
              if (type === 'to') {
 +
                window.location.reload();
 
               } else {
 
               } else {
                 $('.in-page-edit.quick-redirect .ipe-progress').show();
+
                 $('.in-page-edit.quick-redirect .ipe-progress').addClass('done');
                $('.in-page-edit.quick-redirect section').hide();
+
                setTimeout(function () { modal.close() }, 2000);
                $('.in-page-edit.quick-redirect .okBtn').attr('disabled', 'disabled');
 
                switch (type) {
 
                  case 'to':
 
                    json.summary = summary.replace('$1', input);
 
                    json.text = text.replace('$1', input);
 
                    break;
 
                  case 'from':
 
                    json.title = input;
 
                    break;
 
                }
 
 
 
                new mw.Api().post(json).done(function () {
 
                  $('.in-page-edit.quick-redirect .ipe-progress').addClass('done');
 
                  ssi_modal.notify('success', {
 
                    className: 'in-page-edit',
 
                    content: msg('notify-redirect-success'),
 
                    title: msg('notify-success')
 
                  });
 
                  if (type === 'to') {
 
                    window.location.reload();
 
                  } else {
 
                    $('.in-page-edit.quick-redirect .ipe-progress').addClass('done');
 
                    setTimeout(function () { modal.close() }, 2000);
 
                  }
 
                }).fail(function () {
 
                  $('.in-page-edit.quick-redirect .ipe-progress').hide();
 
                  $('.in-page-edit.quick-redirect section').show();
 
                  $('.in-page-edit.quick-redirect .okBtn').attr('disabled', false);
 
                  $('.in-page-edit.quick-redirect .ipe-progress').addClass('done');
 
                  ssi_modal.notify('error', {
 
                    className: 'in-page-edit',
 
                    content: msg('notify-redirect-error'),
 
                    title: msg('notify-error')
 
                  });
 
                });
 
 
               }
 
               }
             }
+
             }).fail(function () {
 +
              $('.in-page-edit.quick-redirect .ipe-progress').hide();
 +
              $('.in-page-edit.quick-redirect section').show();
 +
              $('.in-page-edit.quick-redirect .okBtn').attr('disabled', false);
 +
              $('.in-page-edit.quick-redirect .ipe-progress').addClass('done');
 +
              ssi_modal.notify('error', {
 +
                className: 'in-page-edit',
 +
                content: _msg('notify-redirect-error'),
 +
                title: _msg('notify-error')
 +
              });
 +
            });
 
           }
 
           }
          ]
+
        }
        });
+
        ]
      };
+
      });
 +
    }
  
      /** 查找替换模块 **/
+
    /** 删除页面模块 **/
      InPageEdit.findAndReplace = function (contengut) {
+
    InPageEdit.deletepage = InPageEdit.quickDelete = function (page) {
        if (contengut === this.undefined) contengut = $('.in-page-edit.ipe-editor .editArea');
+
      mw.hook('InPageEdit.quickDelete').fire();
         var origin = contengut.val();
+
      var reason,
 +
         page = page || config.wgPageName;
  
        ssi_modal.show({
+
      ssi_modal.show({
          className: 'in-page-edit',
+
        outSideClose: false,
          sizeClass: 'dialog',
+
        className: 'in-page-edit quick-delete',
          // backdrop: false,
+
        center: true,
          outSideClose: false,
+
        sizeClass: 'dialog',
          position: 'right bottom',
+
        title: _msg('delete-title'),
          title: msg('fAndR-title'),
+
        content: $('<div>').append(
          content: '<div class="module far-module"><div class="module_content" id="findfielddiv"><div>' + msg('fAndR-find-text') + '<div style="padding-top:3px;"><textarea id="find_this" style="margin: 0; width:100%;" rows="4" wrap="off"></textarea></div></div><div style="padding-top:8px;">' + msg('fAndR-replace-text') + '</div><div style="padding-top:3px;"><textarea id="replace_with" style="margin: 0; width:100%;" rows="4" wrap="off" placeholder=""></textarea></div><div style="padding:7px 0px 7px 0px;"><table><tr><td><input type="checkbox" id="globl" checked disabled><label for="globl">' + msg('fAndR-globl') + '</label></td></tr><tr><td><input type="checkbox" id="case_sen"><label for="case_sen">' + msg('fAndR-case-sen') + '</label></td></tr><tr><td><input type="checkbox" id="regex_search"><label for="regex_search">' + msg('fAndR-enable-regex') + '</label></td></tr><tr><td><span id="far-found"></span></td></tr></table></div></div></div>',
+
          $('<section>', { id: 'InPageEditDeletepage' }).append(
           buttons: [
+
            $('<span>', { html: _msg('delete-reason', '<b>' + page.replace(/\_/g, ' ') + '</b>') }),
            {
+
            $br,
              label: msg('fAndR-button-undo'),
+
            $('<label>', { for: 'delete-reason', text: _msg('editSummary') }),
              className: 'btn btn-danger',
+
            $('<input>', { id: 'delete-reason', style: 'width:96%', onclick: "$(this).css('box-shadow', '')" })
              method: function (e, modal) {
+
          )
                contengut.val(origin);
+
        ),
                ssi_modal.notify('info', {
+
        beforeShow: function () {
                  title: msg('fAndR-undo-title'),
+
          if (!_hasRight('delete')) {
                  content: msg('notify-fAndR-undo')
+
            ssi_modal.dialog({
                });
+
              title: _msg('notify-no-right'),
                 // modal.close();
+
              content: _msg('delete-no-right'),
 +
              className: 'in-page-edit quick-deletepage',
 +
              center: true,
 +
              okBtn: {
 +
                className: 'btn btn-primary btn-single'
 +
              }
 +
            });
 +
            return false;
 +
           }
 +
        },
 +
        buttons: [
 +
          {
 +
            label: _msg('cancel'),
 +
            className: 'btn btn-primary',
 +
            method: function (e, modal) {
 +
              modal.close();
 +
            }
 +
          }, {
 +
            label: _msg('confirm'),
 +
            className: 'btn btn-danger',
 +
            method: function (e, modal) {
 +
              reason = $('#InPageEditDeletepage #delete-reason').val();
 +
              if (reason === '') {
 +
                 $('#InPageEditDeletepage #delete-reason').css('box-shadow', '0 0 4px #f00');
 +
                return;
 
               }
 
               }
            },
+
               _analysis('quick_delete');
            {
 
               className: 'btn btn-primary',
 
              label: msg('fAndR-button-replace'),
 
              method: function (nothing, modal) {
 
                /**
 
                * 查找替换主函数
 
                * 借鉴:https://dev.fandom.com/wiki/MediaWiki:FindAndReplace/code.js
 
                **/
 
                if ($('#find_this').val() === '') return;
 
                var searchfor = '',
 
                  searchexp,
 
                  $textarea = contengut,
 
                  replacewith = $('#replace_with').val().replace(/\r/gi, ''),
 
                  text = $textarea.val().replace(/\r/gi, ''),
 
                  flagg = 'g',
 
                  flagi = 'i',
 
                  enableregex = 0;
 
  
                 if ($('#globl').prop('checked') === false) {
+
              ssi_modal.confirm({
                   flagg = '';
+
                center: true,
 +
                className: 'in-page-edit',
 +
                 title: _msg('delete-confirm-title'),
 +
                content: _msg('delete-confirm-content'),
 +
                okBtn: {
 +
                  label: _msg('confirm'),
 +
                  className: 'btn btn-danger'
 +
                },
 +
                cancelBtn: {
 +
                  label: _msg('cancel'),
 +
                   className: 'btn'
 
                 }
 
                 }
                 if ($('#case_sen').prop('checked') === true) {
+
              }, function (result) {
                  flagi = '';
+
                 if (result) {
                }
+
                  reason = _msg('delete-title') + ' (' + reason + ')';
                if ($('#regex_search').prop('checked') === true) {
+
                  new mw.Api().postWithToken('csrf', {
                   enableregex = 1;
+
                    action: 'delete',
                }
+
                    title: page,
                var flags = flagg + flagi + 'm';
+
                    reason: reason,
                if (enableregex === 1) {
+
                    format: 'json'
                  searchfor = $('#find_this').val();
+
                  }).then(function (data) {
 +
                    ssi_modal.notify('success', {
 +
                      className: 'in-page-edit',
 +
                      title: _msg('notify-success'),
 +
                      content: _msg('notify-delete-success', page)
 +
                    });
 +
                   }).fail(function (errorCode, feedback, errorThrown) {
 +
                    ssi_modal.notify('error', {
 +
                      className: 'in-page-edit',
 +
                      title: _msg('notify-error'),
 +
                      content: _msg('notify-delete-error') + ': <br/><span style="font-size:amall">' + errorThrown.error['*'] + '(<code>' + errorThrown.error['code'] + '</code>)</span>'
 +
                    });
 +
                  });
 +
                  modal.close();
 
                 } else {
 
                 } else {
                   searchfor = $('#find_this').val().replace(/\r/gi, '').replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
+
                   return false;
 
                 }
 
                 }
                searchexp = new RegExp(searchfor, flags);
+
              });
                var rcount = 0;
+
            }
                var matched = text.match(searchexp);
+
          }
                if (matched !== null) {
+
        ]
                  rcount = matched.length;
+
      });
                }
+
    }
                text = text.replace(searchexp, replacewith);
+
 
                $textarea.val(text);
+
    /** 重命名模块 **/
                ssi_modal.notify('info', {
+
    InPageEdit.renamepage = InPageEdit.quickRename = function (from, to) {
                  title: msg('notify-fAndR-done-title'),
+
      mw.hook('InPageEdit.quickRename').fire();
                  content: msg('notify-fAndR-done').replace('$1', rcount)
+
      var from = from || config.wgPageName,
                });
+
        to = to || '',
                // modal.close();
+
        reason,
               }
+
        movetalk,
 +
        movesubpages,
 +
        noredirect,
 +
        ignorewarnings;
 +
 
 +
      ssi_modal.show({
 +
        outSideClose: false,
 +
        className: 'in-page-edit quick-rename',
 +
        center: true,
 +
        sizeClass: 'dialog',
 +
        title: _msg('rename-title'),
 +
        content:
 +
          $('<section>').append(
 +
            $('<label>', { for: 'move-to', html: _msg('rename-moveTo', '<b>' + from.replace(/\_/g, ' ') + '</b>') }),
 +
            $br,
 +
            $('<input>', { id: 'move-to', style: 'width:96%', onclick: "$(this).css('box-shadow','')" }),
 +
            $br,
 +
            $('<label>', { for: 'move-reason', text: _msg('editSummary') }),
 +
            $br,
 +
            $('<input>', { id: 'move-reason', style: 'width:96%' }),
 +
            $br,
 +
            $('<label>').append(
 +
              $('<input>', { type: 'checkbox', id: 'movetalk', checked: 'checked' }),
 +
              $('<span>', { text: _msg('rename-movetalk') })
 +
            ),
 +
            $br,
 +
            $('<label>').append(
 +
              $('<input>', { type: 'checkbox', id: 'movesubpages', checked: 'checked' }),
 +
              $('<span>', { text: _msg('rename-movesubpages') })
 +
            ),
 +
            $br,
 +
 
 +
            $('<label>').append(
 +
              $('<input>', { type: 'checkbox', id: 'noredirect' }),
 +
              $('<span>', { text: _msg('rename-noredirect') })
 +
            ),
 +
          ),
 +
        buttons: [{
 +
          label: _msg('cancel'),
 +
          className: 'btn btn-secondary',
 +
          method: function (a, modal) {
 +
            modal.close();
 +
          }
 +
        }, {
 +
          label: _msg('confirm'),
 +
          className: 'btn btn-primary',
 +
          method: function () {
 +
            to = $('.in-page-edit.quick-rename #move-to').val();
 +
            if (to === '' || to === config.wgPageName || to === config.wgPageName.replace(/\_/g, ' ')) {
 +
              $('.in-page-edit.quick-rename #move-to').css('box-shadow', '0 0 4px #f00');
 +
               return;
 
             }
 
             }
          ]
 
        });
 
      };
 
  
      /** 删除页面模块 **/
+
            _analysis('quick_move');
      InPageEdit.deletepage = function (page) {
+
 
        InPageEdit.analysis({ type: 'functionCount', function: '快速删除' });
+
            InPageEdit.progress(_msg('editor-title-saving'));
        var reasonType,
+
            movetalk = $('.in-page-edit.quick-rename #movetalk').prop('checked');
          reason = msg('delete-reason-default');
+
            movesubpages = $('.in-page-edit.quick-rename #movesubpages').prop('checked');
        if (page === this.undefined) page = mw.config.get('wgPageName');
+
            noredirect = $('.in-page-edit.quick-rename #noredirect').prop('checked');
 +
            reason = $('.in-page-edit.quick-rename #move-reason').val();
  
        ssi_modal.show({
+
            if (reason === '') {
          outSideClose: false,
+
              reason = _msg('rename-summary') + ' → [[:' + to + ']]';
          className: 'in-page-edit quick-delete',
+
            } else {
          center: true,
+
              reason = _msg('rename-summary') + ' → [[:' + to + ']] (' + reason + ')';
          sizeClass: 'dialog',
+
            }
          title: msg('delete-title'),
+
            new mw.Api().postWithToken('csrf', {
          content: '<b style="color:#b00">本功能处于测试阶段,谨慎使用</b><section id="InPageEditDeletepage">您要将 <b>' + page + '</b> 删除的理由?<br/><i>自动填充</i><!-- <select id="reasonType" style="width: 23%;padding: 2px;margin: 2px;"><option value="破坏" selected="selected">这是一个破坏</option><option value="被标记">被标记为删除</option><option value="其他">其他</option></select><input id="reason" style="width: 73%;padding: 2px;margin: 2px;" value="' + reason + '"><br/> --></section>',
+
              action: 'move',
          beforeShow: function () {
+
              from: from,
            if (!InPageEdit.hasRight('delete')) {
+
              to: to,
               ssi_modal.dialog({
+
              reason: reason,
                 title: msg('notify-no-right'),
+
              movetalk: movetalk,
                 content: msg('delete-no-right'),
+
              movesubpages: movesubpages,
                 className: 'in-page-edit quick-deletepage',
+
              noredirect: noredirect
                 center: true,
+
            }).done(function () {
                 okBtn: {
+
              InPageEdit.progress(true);
                  className: 'btn btn-primary btn-single'
+
               ssi_modal.notify('success', {
                }
+
                 className: 'in-page-edit',
 +
                content: _msg('notify-rename-success'),
 +
                 title: _msg('notify-success')
 +
              });
 +
              location.href = config.wgArticlePath.replace('$1', to);
 +
            }).fail(function (errorCode, feedback, errorThrown) {
 +
              InPageEdit.progress(false);
 +
              ssi_modal.notify('error', {
 +
                 className: 'in-page-edit',
 +
                 content: _msg('notify-rename-error') + ': ' + errorThrown.error.info + '<code>' + errorThrown.error.code + '</code>',
 +
                 title: _msg('notify-error')
 
               });
 
               });
               return false;
+
               if (errorThrown.error.code === 'articleexists') {
            }
+
                 ssi_modal.dialog({
          },
+
                  className: 'in-page-edit',
          buttons: [
+
                  title: _msg('rename-articleexists-title'),
            {
 
              label: msg('cancel'),
 
              className: 'btn btn-primary',
 
              method: function (e, modal) {
 
                 modal.close();
 
              }
 
            }, {
 
              label: msg('confirm'),
 
              className: 'btn btn-danger',
 
              method: function (e, modal) {
 
                ssi_modal.confirm({
 
 
                   center: true,
 
                   center: true,
                  className: 'in-page-edit',
+
                   content: _msg('rename-articleexists'),
                  title: msg('delete-confirm-title'),
 
                   content: msg('delete-confirm-content'),
 
 
                   okBtn: {
 
                   okBtn: {
                     label: msg('confirm'),
+
                     label: _msg('ok'),
                     className: 'btn btn-danger'
+
                     className: 'btn btn-primary only-btn'
                  },
 
                  cancelBtn: {
 
                    label: msg('cancel'),
 
                    className: 'btn'
 
                  }
 
                }, function (result) {
 
                  if (result) {
 
                    var fiNalReason = '[' + $('#InPageEditDeletepage #reasonType').val() + '] ' + $('#InPageEditDeletepage #reason').val();
 
                    new mw.Api().postWithToken('csrf', {
 
                      action: 'delete',
 
                      title: page
 
                    }).then(function (data) {
 
                      ssi_modal.notify('success', {
 
                        className: 'in-page-edit',
 
                        title: msg('notify-success'),
 
                        content: msg('notify-delete-success').replace('$1', page)
 
                      });
 
                    }).fail(function (errorCode, feedback, errorThrown) {
 
                      ssi_modal.notify('error', {
 
                        className: 'in-page-edit',
 
                        title: msg('notify-error'),
 
                        content: msg('notify-delete-error') + ': <br/><span style="font-size:amall">' + errorThrown.errors[0]['*'] + '(<code>' + errorThrown.errors[0]['code'] + '</code>)</span>'
 
                      });
 
                    });
 
                    modal.close();
 
                  } else {
 
                    return false;
 
 
                   }
 
                   }
 
                 });
 
                 });
 
               }
 
               }
             }
+
             });
           ]
+
          }
         });
+
        }],
       };
+
        beforeShow: function () {
 +
          if (!_hasRight('move')) {
 +
            ssi_modal.dialog({
 +
              title: _msg('notify-no-right'),
 +
              content: _msg('rename-no-right'),
 +
              className: 'in-page-edit quick-deletepage',
 +
              center: true,
 +
              okBtn: {
 +
                className: 'btn btn-primary btn-single'
 +
              }
 +
            });
 +
            return false;
 +
          }
 +
        }
 +
      });
 +
    }
 +
 
 +
    /**
 +
    * @module 个人设置模块
 +
    */
 +
    InPageEdit.preference = {
 +
      /**
 +
      * @name 预设值
 +
      * @return {object}
 +
      */
 +
      "default": {
 +
        doNotCollectMyInfo: false,
 +
        doNotShowLocalWarn: false,
 +
        editMinor: false,
 +
        editSummary: _msg('preference-summary-default'),
 +
        lockToolBox: false,
 +
        redLinkQuickEdit: true,
 +
        outSideClose: true,
 +
        watchList: Boolean(mw.user.options.get('watchdefault'))
 +
      },
 +
      /**
 +
      * @name 获取设置
 +
      * @description 合并保存在用户页的设置以及localStorage的设置,有容错机制
 +
      * @param {string} setting 返回相应的设置,为空时返回全部设置
 +
      * @return {object|string}
 +
      */
 +
      get: function (setting) {
 +
        var setting = setting || undefined;
 +
        var local = localStorage.getItem('InPageEditPreference') || '{}';
 +
        try {
 +
          var local = JSON.parse(local);
 +
        } catch (e) {
 +
          var local = {};
 +
        }
 +
        if (typeof InPageEdit.myPreference === 'object') {
 +
           local = $.extend({}, local, InPageEdit.myPreference);
 +
        }
 +
        var json = $.extend({}, InPageEdit.preference.default, local);
 +
        if (typeof (setting) === 'string' && setting !== '') {
 +
          return json.hasOwnProperty(setting) ? json[setting] : null;
 +
        } else {
 +
          return json;
 +
         }
 +
      },
 +
      /**
 +
      * @name 保存设置
 +
      * @param {Object|string} settingKey
 +
      * @param {any} settingValue
 +
      * @example 可以这样 InPageEdit.preference.set({ key: 'value' }) 也可以 InPageEdit.preference.set('key', 'value')
 +
      */
 +
      set: function (settingKey = {}, settingValue = undefined) {
 +
        var options = {};
 +
        if (typeof settingKey === 'string' && settingValue !== undefined) {
 +
          options[settingKey] = settingValue;
 +
        } else if (typeof settingKey === 'object') {
 +
          options = settingKey;
 +
        } else {
 +
          return;
 +
        }
 +
        options = $.extend({}, InPageEdit.preference.get(), options);
 +
        options = JSON.stringify(options);
 +
        localStorage.setItem('InPageEditPreference', options);
 +
       },
 +
      /**
 +
      * @name 用户图形界面
 +
      * @description 打开可视化设置窗口
 +
      */
 +
      modal: function () {
 +
        // 防止多开设置页面
 +
        if ($('#ipe-preference-form').length > 0) return;
  
      /** 重命名模块 **/
+
        mw.hook('InPageEdit.preference').fire();
      InPageEdit.renamepage = function () {
+
        InPageEdit.preference.set();
         var from = mw.config.get('wgPageName'),
+
         var local = InPageEdit.preference.get();
          to,
+
        _analysis('plugin_setting');
          reason,
 
          movetalk,
 
          movesubpages,
 
          noredirect,
 
          ignorewarnings;
 
  
 
         ssi_modal.show({
 
         ssi_modal.show({
 
           outSideClose: false,
 
           outSideClose: false,
           className: 'in-page-edit quick-rename',
+
           title: _msg('preference-title') + ' - ' + InPageEdit.version,
           center: true,
+
           content:
          sizeClass: 'dialog',
+
            $('<section>', { id: 'ipe-preference-form', class: 'ipe-preference-form' }).append(
          title: msg('rename-title'),
+
              $('<h4>', { text: _msg('preference-editor-label') }),
          content: '<section id="InPageEditRename"><label for="move-to">' + msg('rename-moveTo').replace('$1', '<b>' + from + '</b>') + '</label><br/><input style="width:90%" id="move-to"><br/><input type="checkbox" id="movetalk" checked="checked"/><label for="movetalk">' + msg('rename-movetalk') + '</label><br/><input id="movesubpages" type="checkbox" checked="checked"/><label for="movesubpages">' + msg('rename-movesubpages') + '</label><br/><input id="noredirect" type="checkbox"/><label for="noredirect">' + msg('rename-noredirect') + '</label><br/><label for="move-reason">' + msg('editSummary') + '<br/><input style="width:90%" id="move-reason"/></label></section>',
+
              $('<label>').append(
          buttons: [{
+
                $('<input>', { id: 'outSideClose', type: 'checkbox' }).prop('checked', local.outSideClose),
            label: msg('cancel'),
+
                $('<span>', { text: _msg('preference-outSideClose') })
            className: 'btn btn-secondary',
+
              ),
            method: function (a, modal) {
+
              $br,
               modal.close();
+
              $('<label>').append(
            }
+
                $('<input>', { id: 'editMinor', type: 'checkbox' }).prop('checked', local.editMinor),
          }, {
+
                $('<span>', { text: _msg('preference-setMinor') })
            label: msg('confirm'),
+
              ),
            className: 'btn btn-primary',
+
              $br,
            method: function () {
+
              $('<h4>', { text: _msg('preference-summary-label') }),
              InPageEdit.analysis({ type: 'functionCount', function: '快速重命名' });
+
              $('<label>', { for: 'editSummary', style: 'padding-left: 0; font-size: small', html: _msg('preference-editSummary') }),
               InPageEdit.analysis({ type: 'dateCount' });
+
              $br,
               InPageEdit.analysis({ type: 'siteCount' });
+
               $('<input>', { id: 'editSummary', style: 'width: 96%', value: local.editSummary, placeholder: 'Edit via InPageEdit, yeah~' }),
              InPageEdit.progress('正在和土豆交涉……');
+
               $('<h4>', { text: _msg('preference-analysis-label') }),
              movetalk = $('#movetalk').prop('checked');
+
               $('<span>', { style: 'font-size: small; line-height: 0.9em', html: _msg('preference-analysis-view', '<a href="' + InPageEdit.api.analysisUrl + '" target="_blank">' + InPageEdit.api.analysisUrl + '</a>') }),
               movesubpages = $('#movesubpages').prop('checked');
+
               $('<h4>', { text: _msg('preference-about-label') }),
               noredirect = $('#noredirect').prop('checked');
+
               $('<button>', { class: 'btn btn-secondary', onclick: "InPageEdit.about()", text: _msg('preference-aboutAndHelp') }),
              to = $('#move-to').val();
+
               $('<button>', { class: 'btn btn-secondary', style: 'margin-left: 1em;', onclick: "InPageEdit.versionInfo()", text: _msg('preference-updatelog') }),
               if ($('#move-reason').val() === '') {
+
              $('<a>', { href: 'https://ipe.miraheze.org/wiki/', target: '_blank' }).append(
                reason = msg('rename-summary') + ' → [[:' + to + ']]';
+
                 $('<button>', { class: 'btn btn-secondary', text: _msg('preference-translate'), style: 'margin-left: 1em;' })
              } else {
+
               ),
                 reason = msg('rename-summary') + ' → [[:' + to + ']] (Reason: ' + $('#move-reason').val() + ')';
+
               $('<a>', { href: 'https://discord.gg/VUVAh8w', target: '_blank' }).append(
               }
+
                 $('<button>', { class: 'btn btn-secondary', text: _msg('preference-discord'), style: 'margin-left: 1em;' })
               new mw.Api().postWithToken('csrf', {
+
              ),
                action: 'move',
+
              $hr,
                from: from,
+
              $('<strong>', { style: 'font-size: small; line-height: 0.9em', text: _msg('preference-savelocal-label') }),
                to: to,
+
              $br,
                reason: reason,
+
              $('<span>', { style: 'font-size: small; line-height: 0.9em', text: _msg('preference-savelocal') }).append(
                movetalk: movetalk,
+
                $('<a>', { href: 'javascript:;', id: 'ipeSaveLocalShow', text: _msg('preference-savelocal-btn') }).click(function () {
                movesubpages: movesubpages,
+
                  // 永久保存(本地用户页)
                noredirect: noredirect
 
              }).done(function () {
 
                InPageEdit.progress(true);
 
                 ssi_modal.notify('success', {
 
                  className: 'in-page-edit',
 
                  content: msg('notify-rename-success'),
 
                  title: msg('notify-success')
 
                });
 
                location.href = mw.config.get('wgArticlePath').replace('$1', to);
 
              }).fail(function (errorCode, feedback, errorThrown) {
 
                InPageEdit.progress(false);
 
                ssi_modal.notify('error', {
 
                  className: 'in-page-edit',
 
                  content: msg('notify-rename-error') + ': ' + errorThrown.error.info + '<code>' + errorThrown.error.code + '</code>',
 
                  title: msg('notify-error')
 
                });
 
                if (errorThrown.error.code === 'articleexists') {
 
 
                   ssi_modal.dialog({
 
                   ssi_modal.dialog({
 
                     className: 'in-page-edit',
 
                     className: 'in-page-edit',
                    title: msg('rename-articleexists-title'),
 
 
                     center: true,
 
                     center: true,
                     content: msg('rename-articleexists'),
+
                    title: _msg('preference-savelocal-popup-title'),
 +
                     content: '<section id="ipeSaveLocal">' + _msg('preference-savelocal-popup') + '<br/><textarea style="font-size: 12px; resize: none; width: 100%; height: 10em;" readonly></textarea><br/>' + _msg('preference-savelocal-popup-notice') + '</section>',
 
                     okBtn: {
 
                     okBtn: {
                       label: msg('ok'),
+
                       className: 'btn btn-primary btn-single',
                       className: 'btn btn-primary only-btn'
+
                       label: _msg('ok')
 
                     }
 
                     }
 
                   });
 
                   });
                 }
+
                  $('#ipeSaveLocal textarea').val('/** InPageEdit preference **/\nwindow.InPageEdit = window.InPageEdit || {};\nInPageEdit.myPreference = ' + JSON.stringify($('#ipe-preference-form').data(), null, 2));
               });
+
                 })
             }
+
               )
           }],
+
             ),
           beforeShow: function () {
+
          sizeClass: 'dialog',
             if (!InPageEdit.hasRight('move')) {
+
          className: 'in-page-edit ipe-preference',
               ssi_modal.dialog({
+
           center: true,
                 title: msg('notify-no-right'),
+
           buttons: [{
                 content: msg('rename-no-right'),
+
             label: _msg('preference-reset'),
                 className: 'in-page-edit quick-deletepage',
+
            className: 'btn btn-danger',
 +
            method: function (a, modal) {
 +
               ssi_modal.confirm({
 +
                 title: _msg('preference-reset-confirm-title'),
 +
                 content: _msg('preference-reset-confirm'),
 +
                 className: 'in-page-edit',
 
                 center: true,
 
                 center: true,
 
                 okBtn: {
 
                 okBtn: {
                   className: 'btn btn-primary btn-single'
+
                  label: _msg('ok'),
 +
                   className: 'btn btn-danger'
 +
                },
 +
                cancelBtn: {
 +
                  label: _msg('cancel'),
 +
                  className: 'btn'
 +
                }
 +
              }, (res) => {
 +
                if (res) {
 +
                  InPageEdit.preference.set(InPageEdit.preference.default);
 +
                  modal.close();
 +
                } else {
 +
                  return false;
 
                 }
 
                 }
 
               });
 
               });
               return false;
+
            }
 +
          }, {
 +
            label: _msg('preference-save'),
 +
            className: 'btn btn-primary',
 +
            method: function (a, modal) {
 +
               InPageEdit.preference.set($('#ipe-preference-form').data());
 +
              modal.close();
 +
            }
 +
          }
 +
          ],
 +
          onShow: function () {
 +
            function setData() {
 +
              if (this.type === 'checkbox') {
 +
                $('#ipe-preference-form').data(this.id, this.checked);
 +
              } else if (this.type === 'text') {
 +
                $('#ipe-preference-form').data(this.id, this.value);
 +
              }
 +
            }
 +
            $('#ipe-preference-form input').each(setData).change(setData);
 +
 
 +
            if (typeof (InPageEdit.myPreference) !== 'undefined') {
 +
              $('#ipe-preference-form input, .ipe-preference .ssi-modalBtn').attr({ 'disabled': 'disabled' });
 +
              $('#ipe-preference-form').prepend(
 +
                $('<p>', { class: 'has-local-warn', style: 'padding-left: 8px; border-left: 6px solid orange; font-size: small;', html: _msg('preference-savelocal-popup-haslocal', '<a href="' + mw.util.getUrl('Special:Mypage/common.js') + '">' + _msg('preference-savelocal-popup-yourjspage') + '</a>') })
 +
              );
 
             }
 
             }
 
           }
 
           }
 
         });
 
         });
       };
+
       }
 +
    }
  
      /** 个人设置模块 **/
+
    /**
      InPageEdit.preference = function () {
+
    * @module quickDiff 快速页面差异模块
        InPageEdit.analysis({ type: 'functionCount', function: '插件设置' });
+
    * @param {Object} param standard MediaWiki API params
         var settings = JSON.parse(localStorage.getItem('InPageEditPreference')),
+
    */
          minor = settings.editMinor,
+
    InPageEdit.quickDiff = function (param) {
          summary = settings.editSummary,
+
      mw.hook('InPageEdit.quickDiff').fire();
          outSideClose = settings.outSideClose;
+
      _analysis('quick_diff');
 +
      if ($('[href*="mediawiki.diff.styles"]').length < 1) {
 +
        mw.loader.load(mw.util.wikiScript('load') + '?modules=mediawiki.legacy.shared|mediawiki.diff.styles&only=styles', 'text/css');
 +
      }
 +
      var $modalTitle,
 +
        $diffArea,
 +
        $loading;
 +
      if ($('.quick-diff').length > 0) {
 +
        console.info('[InPageEdit] Quick diff 正在加载新内容');
 +
        $modalTitle = $('.quick-diff .pageName');
 +
         $diffArea = $('.quick-diff .diffArea');
 +
        $loading = $('.quick-diff .ipe-progress');
 +
        $modalTitle.text(_msg('diff-loading'));
 +
        $diffArea.hide();
 +
        $('.quick-diff').appendTo('body');
 +
      } else {
 +
        $modalTitle = $('<span>', { class: 'pageName', text: _msg('diff-loading') });
 +
        $diffArea = $('<div>', { class: 'diffArea', style: 'display: none' });
 +
        $loading = $($progress);
  
 
         ssi_modal.show({
 
         ssi_modal.show({
           outSideClose: false,
+
           className: 'in-page-edit quick-diff',
          title: msg('preference-title') + ' - ' + InPageEdit.version,
+
           sizeClass: 'large',
           content: '<section id="InPageEditSettingBox"><h4>'+msg('preference-editor-label')+'</h4><input id="ipeSetoutSideClose" type="checkbox"/> <label for="ipeSetoutSideClose">' + msg('preference-outSideClose') + '</label><br/><input id="ipeSetMinor" type="checkbox"/> <label for="ipeSetMinor">' + msg('preference-setMinor') + '</label><br/><label><h4>' + msg('preference-summary-label') + '</h4>' + msg('preference-editSummary').replace('%br%', '<br/>').replace('$1', '<code>$oldid</code>').replace('$2', '<code>' + msg('editor-summary-rivision') + ' [[Special:Diff/oldid]]</code>').replace('$3', '<code>$section</code>').replace('$4', '<code>/* ' + msg('editor-title-editSection') + ' */</code>') + '<br/><span style="font-size:10px"></span><input id="ipeSetSummary" value="' + summary + '" style="width:100%"/></label><br/><h4>' + msg('preference-analysis-label') + '</h4><span style="font-size: small; line-height: 0.9em;">' + msg('preference-analysis-view').replace('$1', '<a href="https://doc.wjghj.cn/InPageEditAnalysis/" target="_blank">https://doc.wjghj.cn/InPageEditAnalysis/</a>') + '</span><h4>' + msg('preference-about-label') + '</h4><button class="btn btn-secondary" onclick="mw.loader.load(\'https://common.wjghj.cn/js/InPageEdit-v2.js/about\')">' + msg('preference-aboutAndHelp') + '</button>&nbsp;<button class="btn btn-secondary" onclick="InPageEdit.versionInfo()">' + msg('preference-updatelog') + '</button><hr><span style="font-size: small;line-height: 0.9em">' + msg('preference-savelocal-label') + '<br/>' + msg('preference-savelocal') + '<a href="javascript:;" id="ipeSaveLocalShow">' + msg('preference-savelocal-btn') + '</a></span></section>',
+
          fixedHeight: true,
          sizeClass: 'dialog',
+
          fitScreen: true,
          className: 'in-page-edit ipe-preference',
+
          title: $modalTitle,
          center: true,
+
          content: $('<div>').append($loading, $diffArea),
 
           buttons: [{
 
           buttons: [{
             label: msg('preference-reset'),
+
             label: _msg('diff-button-todiffpage'),
             className: 'btn btn-danger',
+
             className: 'btn btn-secondary toDiffPage',
 
             method: function () {
 
             method: function () {
               $('#InPageEditSettingBox #ipeSetoutSideClose').prop('checked', true);
+
               // ...
              $('#InPageEditSettingBox #ipeSetMinor').prop('checked', false);
 
              $('#InPageEditSettingBox #ipeSetSummary').val(msg('preference-summary-default'));
 
            }
 
          }, {
 
            label: msg('preference-save'),
 
            className: 'btn btn-primary',
 
            method: function (a, modal) {
 
              localStorage.setItem('InPageEditPreference', JSON.stringify({
 
                outSideClose: $('#InPageEditSettingBox #ipeSetoutSideClose').prop('checked'),
 
                editMinor: $('#InPageEditSettingBox #ipeSetMinor').prop('checked'),
 
                editSummary: $('#InPageEditSettingBox #ipeSetSummary').val()
 
              }));
 
 
 
              modal.close();
 
 
             }
 
             }
           }
+
           }]
          ]
 
 
         });
 
         });
        $('#ipeSaveLocalShow').click(function () {
+
      }
           ssi_modal.dialog({
+
      $loading.show().css('margin-top', $loading.parent().height() / 2);
            className: 'in-page-edit',
+
      $('.quick-diff .toDiffPage').unbind();
            center: true,
+
      param.action = 'compare';
            title: msg('preference-savelocal-popup-title'),
+
      param.prop = 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size';
            content: '<section id="ipeSaveLocal"><b>' + msg('preference-savelocal-popup-notrecommended') + '</b><br/>' + msg('preference-savelocal-popup') + '<br/><input style="width:100%" readonly="readonly" onclick="$(this).select()"/><br/>' + msg('preference-savelocal-popup-notice') + '</section>',
+
      param.format = 'json';
             okBtn: {
+
      if (param.totext) {
              className: 'btn btn-primary btn-single'
+
        param.topst = true;
            }
+
      } else if (param.fromtext) {
          });
+
        param.frompst = true;
          $('#ipeSaveLocal input').val('window.MyInPageEditPreference = ' + JSON.stringify({
+
      }
            outSideClose: $('#InPageEditSettingBox #ipeSetoutSideClose').prop('checked'),
+
      new mw.Api().post(param).then(function (data) {
            editMinor: $('#InPageEditSettingBox #ipeSetMinor').prop('checked'),
+
        var diffTable = data.compare['*'];
             editSummary: $('#InPageEditSettingBox #ipeSetSummary').val()
+
        $loading.hide();
           }) + ';');
+
        if (param.pageName === undefined) {
 +
          var toTitle = data.compare.totitle;
 +
        } else {
 +
           var toTitle = param.pageName;
 +
        }
 +
        var userlink = function (user) {
 +
          return '<a class="diff-user" href="' + mw.util.getUrl('User:' + user) + '">' + user + '</a> (<a href="' + mw.util.getUrl('User_talk:' + user) + '">' + _msg('diff-usertalk') + '</a> | <a href="' + mw.util.getUrl('Special:Contributions/' + user) + '">' + _msg('diff-usercontrib') + '</a> | <a href="' + mw.util.getUrl('Special:Block/' + user) + '">' + _msg('diff-userblock') + '</a>)';
 +
        }
 +
        $modalTitle.html(_msg('diff-title') + ': <u>' + toTitle + '</u>');
 +
        $diffArea.show().html('').append(
 +
          $('<table>', { class: 'diff difftable' }).append(
 +
            $('<colgroup>').append(
 +
              $('<col>', { class: 'diff-marker' }),
 +
              $('<col>', { class: 'diff-content' }),
 +
              $('<col>', { class: 'diff-marker' }),
 +
              $('<col>', { class: 'diff-content' })
 +
            ),
 +
             $('<tbody>').append(
 +
              $('<tr>').append(
 +
                $('<td>', { colspan: 2, class: 'diff-otitle' }).append(
 +
                  $('<a>', { href: config.wgScript + '?oldid=' + data.compare.fromrevid, text: data.compare.fromtitle }),
 +
                  ' (',
 +
                  $('<span>', { class: 'diff-version', text: _msg('diff-version') + data.compare.fromrevid }),
 +
                  ') (',
 +
                  $('<a>', { class: 'editLink', href: config.wgScript + '?action=edit&title=' + data.compare.fromtitle + '&oldid=' + data.compare.fromrevid }),
 +
                  ')',
 +
                  $br,
 +
                  userlink(data.compare.fromuser),
 +
                  $br,
 +
                  ' (',
 +
                  $('<span>', { class: 'diff-comment', text: data.compare.fromparsedcomment }),
 +
                  ') ',
 +
                  $br,
 +
                  $('<a>', { class: 'prevVersion ipe-analysis-quick_diff_modalclick', href: 'javascript:void(0);', text: '←' + _msg('diff-prev') }).click(() => {
 +
                    InPageEdit.quickDiff({
 +
                      fromrev: data.compare.fromrevid,
 +
                      torelative: 'prev'
 +
                    });
 +
                  })
 +
                ),
 +
                $('<td>', { colspan: 2, class: 'diff-ntitle' }).append(
 +
                  $('<a>', { href: config.wgScript + '?oldid=' + data.compare.torevid, text: data.compare.totitle }),
 +
                  ' (',
 +
                  $('<span>', { class: 'diff-version', text: _msg('diff-version') + data.compare.torevid }),
 +
                  ') (',
 +
                  $('<a>', { class: 'editLink', href: config.wgScript + '?action=edit&title=' + data.compare.totitle + '&oldid=' + data.compare.torevid }),
 +
                  ')',
 +
                  $br,
 +
                  userlink(data.compare.touser),
 +
                  $br,
 +
                  ' (',
 +
                  $('<span>', { class: 'diff-comment', text: data.compare.toparsedcomment }),
 +
                  ') ',
 +
                  $br,
 +
                  $('<a>', { class: 'nextVersion ipe-analysis-quick_diff_modalclick', href: 'javascript:void(0);', text: _msg('diff-nextv') + '→' }).click(() => {
 +
                    _analysis('quick_diff_modalclick');
 +
                    InPageEdit.quickDiff({
 +
                      fromrev: data.compare.torevid,
 +
                      torelative: 'next'
 +
                    });
 +
                  })
 +
                )
 +
              ),
 +
              diffTable,
 +
              $('<tr>', { class: 'diffSize', style: 'text-align: center' }).append(
 +
                $('<td>', { colspan: '2', text: data.compare.fromsize + _msg('diff-bytes') }),
 +
                $('<td>', { colspan: '2', text: data.compare.tosize + _msg('diff-bytes') })
 +
              )
 +
             )
 +
          )
 +
        );
 +
        $('.quick-diff button.toDiffPage').click(function () {
 +
           location.href = config.wgScript + '?oldid=' + data.compare.fromrevid + '&diff=' + data.compare.torevid;
 
         });
 
         });
         if (outSideClose) {
+
        InPageEdit.articleLink($('.quick-diff .editLink'));
           $('#InPageEditSettingBox #ipeSetoutSideClose').prop('checked', true);
+
        if (param.isPreview === true) {
 +
          $('.quick-diff button.toDiffPage').hide();
 +
          $diffArea.find('.diff-otitle').html('<b>' + _msg('diff-title-original-content') + '</b>');
 +
          $diffArea.find('.diff-ntitle').html('<b>' + _msg('diff-title-your-content') + '</b>');
 +
        }
 +
        if (data.compare.fromsize === undefined || data.compare.tosize === undefined) {
 +
          $diffArea.find('.diffSize').hide();
 +
        }
 +
        // 无上一版本或下一版本
 +
         if (data.compare.fromrevid === undefined && param.isPreview !== true) {
 +
           $diffArea.find('.diff-otitle').html('<span class="noPrevVerson">' + data.warnings.compare['*'] + '</span>');
 +
        } else if (data.compare.torevid === undefined && param.isPreview !== true) {
 +
          $diffArea.find('.diff-ntitle').html('<span class="noNextVerson">' + data.warnings.compare['*'] + '</span>');
 +
        }
 +
        // GitHub@issue#5 修复被隐藏版本的问题
 +
        if (data.compare.fromtexthidden !== undefined) {
 +
          $diffArea.find('.diff-otitle .diff-version').addClass('diff-hidden-history');
 +
        }
 +
        if (data.compare.totexthidden !== undefined) {
 +
          $diffArea.find('.diff-ntitle .diff-version').addClass('diff-hidden-history');
 +
        }
 +
        if (data.compare.fromuserhidden !== undefined) {
 +
          $diffArea.find('.diff-otitle .diff-user').addClass('diff-hidden-history');
 
         }
 
         }
         if (minor) {
+
         if (data.compare.touserhidden !== undefined) {
           $('#InPageEditSettingBox #ipeSetMinor').prop('checked', true);
+
           $diffArea.find('.diff-ntitle .diff-user').addClass('diff-hidden-history');
 
         }
 
         }
 
+
         if (data.compare.fromcommenthidden !== undefined) {
         if (typeof (MyInPageEditPreference) !== 'undefined') {
+
           $diffArea.find('.diff-comment').addClass('diff-hidden-history');
           $('.ipe-preference .ssi-buttons .ssi-modalBtn').attr('disabled', '');
 
          if (typeof (MyInPageEditPreference.editMinor) === 'boolean') {
 
            $('#InPageEditSettingBox #ipeSetMinor').prop('checked', MyInPageEditPreference.editMinor).attr('disabled', '');
 
          }
 
          if (typeof (MyInPageEditPreference.outSideClose) === 'boolean') {
 
            $('#InPageEditSettingBox #ipeSetoutSideClose').prop('checked', MyInPageEditPreference.outSideClose).attr('disabled', '');
 
          }
 
          if (typeof (MyInPageEditPreference.editSummary) === 'string') {
 
            $('#InPageEditSettingBox #ipeSetSummary').attr('disabled', '').val(MyInPageEditPreference.editSummary);
 
          }
 
          ssi_modal.dialog({
 
            content: msg('preference-savelocal-popup-haslocal').replace('$1', '<a href="' + mw.util.getUrl('Special:Mypage/common.js') + '">' + msg('preference-savelocal-popup-yourjspage') + '</a>'),
 
            className: 'in-page-edit',
 
            center: true,
 
            okBtn: {
 
              className: 'btn btn-primary btn-single'
 
            }
 
          });
 
 
         }
 
         }
      };
+
        if (data.compare.tocommenthidden !== undefined) {
 
+
          $diffArea.find('.diff-ntitle .diff-comment').addClass('diff-hidden-history');
      /** 快速页面差异模块 **/
 
      InPageEdit.quickDiff = function (param) {
 
        InPageEdit.analysis({ type: 'dateCount' });
 
        InPageEdit.analysis({ type: 'siteCount' });
 
        // InPageEdit.analysis({ type: 'functionCount', function: '快速差异' });
 
        if ($('[href*="mediawiki.diff.styles"]').length < 1) {
 
          mw.loader.load(mw.config.get('wgScriptPath') + '/load.php?modules=mediawiki.legacy.shared|mediawiki.diff.styles&only=styles', 'text/css');
 
 
         }
 
         }
         if ($('.quick-diff').length > 0) {
+
         if (data.hasOwnProperty('error')) {
           console.info('[InPageEdit] Quick diff 正在加载新内容');
+
           console.warn('[InPageEdit] 快速差异获取时系统告知出现问题');
           $('.in-page-edit.quick-diff .diffArea').hide().html(msg('diff-loading'));
+
           $diffArea.html(_msg('diff-error') + ': ' + data.error.info + '(<code>' + data.error.code + '</code>)');
          if (param.isPreview) {
 
            $('.quick-diff').appendTo('body');
 
          }
 
        } else {
 
          ssi_modal.show({
 
            className: 'in-page-edit quick-diff',
 
            sizeClass: 'large',
 
            fixedHeight: true,
 
            fitScreen: true,
 
            title: '<span class="pageName">' + msg('diff-loading') + '</span>',
 
            content: '<div class="ipe-progress" style="width:100%"><div class="ipe-progress-bar"></div></div><div class="diffArea"></div>',
 
            buttons: [{
 
              label: msg('diff-button-todiffpage'),
 
              className: 'btn btn-secondary toDiffPage',
 
              method: function () {
 
                // Placeholder
 
              }
 
            }]
 
          });
 
 
         }
 
         }
         $('.in-page-edit.quick-diff .ipe-progress').show().css('margin-top', $('.in-page-edit.quick-diff .ipe-progress').parent().height() / 2);
+
      }).fail(function (errorCode, feedback, errorThrown) {
         $('.quick-diff button.toDiffPage').unbind();
+
        console.warn('[InPageEdit] 快速差异获取失败');
        param.action = 'compare';
+
         $loading.hide();
        param.prop = 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size';
+
        $diffArea.show().html(_msg('diff-error') + ': ' + errorThrown.error['info'] + '(<code>' + errorThrown.error['code'] + '</code>)');
        param.format = 'json';
+
      });
        new mw.Api().post(param).then(function (data) {
+
    }
          var diffTable = data.compare['*'];
+
    // 加载预设的快速最近更改模块
           $('.in-page-edit.quick-diff .ipe-progress').hide();
+
    InPageEdit.loadQuickDiff = function () {
           if (param.pageName === undefined) {
+
      // 最近更改
             var toTitle = data.compare.totitle;
+
      function addLink(origin) {
 +
        $('.mw-changeslist-groupdiff, .mw-changeslist-diff, .mw-changeslist-diff-cur, .mw-history-histlinks a').unbind('click', ipeDiffLink);
 +
         var ipeDiffLink = $('.mw-changeslist-groupdiff, .mw-changeslist-diff, .mw-changeslist-diff-cur, .mw-history-histlinks a').click(function (e) {
 +
          e.preventDefault();
 +
          _analysis('quick_diff_recentchanges');
 +
          var $this = $(this),
 +
            href = $this.attr('href'),
 +
            diff = mw.util.getParamValue('diff', href),
 +
            curid = mw.util.getParamValue('curid', href),
 +
            oldid = mw.util.getParamValue('oldid', href);
 +
           if (diff === '0') {
 +
            InPageEdit.quickDiff({ fromrev: oldid, toid: curid });
 +
           } else if (diff === 'prev' || diff === 'next' || diff === 'cur') {
 +
             InPageEdit.quickDiff({ fromrev: oldid, torelative: diff });
 
           } else {
 
           } else {
             var toTitle = param.pageName;
+
             InPageEdit.quickDiff({ fromrev: oldid, torev: diff });
          }
 
          var userlink = function (user) {
 
            return '<a href="' + mw.util.getUrl('User:' + user) + '">' + user + '</a> ( <a href="' + mw.util.getUrl('User_talk:' + user) + '">' + msg('diff-usertalk') + '</a> | <a href="' + mw.util.getUrl('Special:Contributions/' + user) + '">' + msg('diff-usercontrib') + '</a> | <a href="' + mw.util.getUrl('Special:Block/' + user) + '">' + msg('diff-userblock') + '</a> )';
 
          }
 
          $('.quick-diff .pageName').html(msg('diff-title') + ': <u>' + toTitle + '</u>');
 
          $('.quick-diff .diffArea').show().html(
 
            '<table class="diff diffTable">' +
 
            '<colgroup>' +
 
            '<col class="diff-marker">' +
 
            '<col class="diff-content">' +
 
            '<col class="diff-marker">' +
 
            '<col class="diff-content">' +
 
            '</colgroup>' +
 
            '<tbody>' +
 
            '<tr class="diff-title">' +
 
            '<td colspan="2" class="diff-otitle">' +
 
            '<a class="" href="' + mw.config.get('wgScript') + '?oldid=' + data.compare.fromrevid + '">' + data.compare.fromtitle + '</a> (' + msg('diff-version') + data.compare.fromrevid + ') (<a class="editLink" href="' + mw.config.get('wgScript') + '?action=edit&title=' + data.compare.fromtitle + '&oldid=' + data.compare.fromrevid + '">' + msg('diff-edit') + '</a>)<br/>' + userlink(data.compare.fromuser) + '<br/>(' + data.compare.fromparsedcomment + ')<br/><a class="prevVersion" href="javascript:void(0);" onclick="InPageEdit.quickDiff({fromrev:' + data.compare.fromrevid + ',torelative:\'prev\'});InPageEdit.analysis({type:\'functionCount\',function:\'快速差异History\'});">←' + msg('diff-prev') + '</a>' +
 
            '</td>' +
 
            '<td colspan="2" class="diff-ntitle">' +
 
            '<a class="" href="' + mw.config.get('wgScript') + '?oldid=' + data.compare.torevid + '">' + data.compare.totitle + '</a> (' + msg('diff-version') + data.compare.torevid + ') (<a class="editLink" href="' + mw.config.get('wgScript') + '?action=edit&title=' + data.compare.totitle + '&oldid=' + data.compare.torevid + '">' + msg('diff-edit') + '</a>)<br/>' + userlink(data.compare.touser) + '<br/>(' + data.compare.toparsedcomment + ')<br/><a class="nextVersion" href="javascript:void(0);" onclick="InPageEdit.quickDiff({fromrev:' + data.compare.torevid + ',torelative:\'next\'});InPageEdit.analysis({type:\'functionCount\',function:\'快速差异History\'});">' + msg('diff-nextv') + '→</a>' +
 
            '</td>' +
 
            '</tr>' +
 
            diffTable +
 
            '<tr class="diffSize" style="text-align: center;"><td colspan="2">' + data.compare.fromsize + msg('diff-bytes') + '</td><td colspan="2">' + data.compare.tosize + msg('diff-bytes') + '</td></tr>' +
 
            '</tbody>' +
 
            '</table>'
 
          );
 
          $('.quick-diff button.toDiffPage').click(function () {
 
            location.href = mw.config.get('wgScript') + '?oldid=' + data.compare.fromrevid + '&diff=' + data.compare.torevid;
 
          });
 
          InPageEdit.articleLink($('.quick-diff .editLink'));
 
          if (param.isPreview === true) {
 
            $('.quick-diff button.toDiffPage').hide();
 
            $('.quick-diff .diff-otitle').html('<b>' + msg('diff-title-original-content') + '</b>');
 
            $('.quick-diff .diff-ntitle').html('<b>' + msg('diff-title-your-content') + '</b>');
 
          }
 
          if (data.compare.fromsize === undefined || data.compare.tosize === undefined) {
 
            $('.quick-diff .diffSize').hide();
 
          }
 
          if (data.compare.fromrevid === undefined && param.isPreview !== true) {
 
            $('.quick-diff .diff-otitle').html('<span class="noNextVerson"><b>没有更多了哟~</b><br/><span style="font-size:10px">没有之前的版本了!之前的版本即使是盘古也没有见过呀!</span></span>');
 
          } else if (data.compare.torevid === undefined && param.isPreview !== true) {
 
            $('.quick-diff .diff-ntitle').html('<span class="noNextVerson"><b>没有更多了哟~</b><br/><span style="font-size:10px">没有之后的版本了!一点也没有了!!真的没有了!!!</span></span>');
 
 
           }
 
           }
        }).fail(function (a, b, c) {
 
          $('.in-page-edit.quick-diff .ipe-progress').hide();
 
          $('.diffArea').html(msg('diff-error') + ': ' + b);
 
 
         });
 
         });
       };
+
       }
       // 加载预设的快速最近更改模块
+
       if ($('.mw-rcfilters-enabled').length > 0) {
      InPageEdit.loadQuickDiff = function () {
+
         setInterval(addLink, 500);
         // 最近更改
+
        $('.mw-rcfilters-enabled').addClass('ipe-continuous-active');
        function addLink(origin) {
+
      } else {
          $('.mw-changeslist-groupdiff, .mw-changeslist-diff, .mw-changeslist-diff-cur, .mw-history-histlinks a').unbind('click', ipeDiffLink);
+
        addLink();
           var ipeDiffLink = $('.mw-changeslist-groupdiff, .mw-changeslist-diff, .mw-changeslist-diff-cur, .mw-history-histlinks a').click(function (e) {
+
      }
 +
      // 查看历史页面的比较按钮与快速编辑
 +
      if (config.wgAction === 'history') {
 +
        $('.historysubmit.mw-history-compareselectedversions-button').after(
 +
           $('<button>').text(_msg('quick-diff')).click(function (e) {
 
             e.preventDefault();
 
             e.preventDefault();
             InPageEdit.analysis({ type: 'functionCount', function: '快速差异RC' });
+
             _analysis('quick_diff_history_page');
             var $this = $(this),
+
             var before = $('.selected.before').attr('data-mw-revid'),
              href = $this.attr('href'),
+
               after = $('.selected.after').attr('data-mw-revid');
              diff = mw.util.getParamValue('diff', href),
+
             InPageEdit.quickDiff({ fromrev: after, torev: before });
               curid = mw.util.getParamValue('curid', href),
+
           })
              oldid = mw.util.getParamValue('oldid', href);
+
         );
            if (diff === '0') {
+
         $('[data-mw-revid]').each(function () {
              InPageEdit.quickDiff({ fromrev: oldid, toid: curid });
+
           var $this = $(this),
            } else if (diff === 'prev' || diff === 'next' || diff === 'cur') {
+
            oldid = $this.attr('data-mw-revid');
              InPageEdit.quickDiff({ fromrev: oldid, torelative: diff });
+
           $this.find('.mw-history-undo').after(
             } else {
+
             $('<span>').html(' | <a class="in-page-edit-article-link" href="javascript:void(0);" onclick="InPageEdit.quickEdit({page:mw.config.get(\'wgPageName\'),revision:' + oldid + '});">' + _msg('quick-edit') + '</a>')
              InPageEdit.quickDiff({ fromrev: oldid, torev: diff });
 
            }
 
           });
 
         }
 
         if ($('.mw-rcfilters-enabled').length > 0) {
 
           setInterval(addLink, 500);
 
          $('.mw-rcfilters-enabled').addClass('ipe-continuous-active');
 
        } else {
 
           addLink();
 
        }
 
        // 查看历史页面的比较按钮与快速编辑
 
        if (mw.config.get('wgAction') === 'history') {
 
          $('.historysubmit.mw-history-compareselectedversions-button').after(
 
             $('<button>').text(msg('quick-diff')).click(function (e) {
 
              e.preventDefault();
 
              InPageEdit.analysis({ type: 'functionCount', function: '快速差异History' });
 
              var before = $('.selected.before').attr('data-mw-revid'),
 
                after = $('.selected.after').attr('data-mw-revid');
 
              InPageEdit.quickDiff({ fromrev: after, torev: before });
 
            })
 
 
           );
 
           );
          $('[data-mw-revid]').each(function () {
+
        });
            var $this = $(this),
+
      }
              oldid = $this.attr('data-mw-revid');
+
    }
            $this.find('.mw-history-undo').after(
 
              $('<span>').html(' | <a class="in-page-edit-article-link" href="javascript:void(0);" onclick="InPageEdit.edit({page:mw.config.get(\'wgPageName\'),revision:' + oldid + '});">' + msg('quick-edit') + '</a>')
 
            );
 
          });
 
        }
 
      };
 
  
      /** 获取段落编辑以及编辑链接 **/
+
    /**
      InPageEdit.articleLink = function (element) {
+
    * @module 获取段落编辑以及编辑链接
        if (element === undefined)
+
    * @param {Element} element parent element to find edit links
 +
    */
 +
    InPageEdit.articleLink = function (element) {
 +
      if (element === undefined) {
 +
        if (InPageEdit.preference.get('redLinkQuickEdit') === true) {
 +
          element = $('#mw-content-text a');
 +
        } else {
 
           element = $('#mw-content-text a:not(.new)');
 
           element = $('#mw-content-text a:not(.new)');
         element.each(function (i) {
+
         }
          if ($(this).attr('href') === undefined)
+
      }
            return;
+
      element.each(function (i) {
          var url = $(this).attr('href'),
+
        if ($(this).attr('href') === undefined)
            title = mw.util.getParamValue('title', url),
+
          return;
            section = mw.util.getParamValue('section', url),
+
        var url = $(this).attr('href'),
            revision = mw.util.getParamValue('oldid', url);
+
          title = mw.util.getParamValue('title', url),
 +
          section = mw.util.getParamValue('section', url),
 +
          revision = mw.util.getParamValue('oldid', url);
  
          // 不是本地编辑链接
+
        // 不是本地编辑链接
          if (url.split('/')['2'] !== location.href.split('/')['2'] && url.substr(0, 1) !== '/')
+
        if (url.split('/')['2'] !== location.href.split('/')['2'] && url.substr(0, 1) !== '/')
            return;
+
          return;
  
          // 不是 index.php?title=FOO 形式的url
+
        // 不是 index.php?title=FOO 形式的url
          if (title === null) {
+
        if (title === null) {
            var splitStr = mw.config.get('wgArticlePath').replace('$1', '');
+
          var splitStr = config.wgArticlePath.replace('$1', '');
            if (splitStr === '/') {
+
          if (splitStr === '/') {
              splitStr = mw.config.get('wgServer').substring(mw.config.get('wgServer').length - 4) + '/';
+
            splitStr = config.wgServer.substring(config.wgServer.length - 4) + '/';
            }
 
            title = url.split(splitStr).pop().split('?')['0'];
 
 
           }
 
           }
 +
          title = url.split(splitStr).pop().split('?')['0'];
 +
        }
 +
 +
        if (mw.util.getParamValue('action', url) === 'edit' && title !== undefined) {
 +
          $(this).after(
 +
            $('<span>', {
 +
              'class': 'in-page-edit-article-link-group'
 +
            }).append(
 +
              $('<a>', {
 +
                href: 'javascript:void(0)',
 +
                class: 'in-page-edit-article-link',
 +
                text: _msg('quick-edit')
 +
              }).click(function () {
 +
                var options = {};
 +
                options.page = title;
 +
                if (revision !== null) {
 +
                  options.revision = revision;
 +
                } else if (section !== null) {
 +
                  options.section = section;
 +
                }
 +
                if (!config.wgIsArticle) options.reload = false;
 +
                InPageEdit.quickEdit(options);
 +
              })
 +
            )
 +
          );
 +
        }
 +
      });
 +
    }
  
          if (mw.util.getParamValue('action', url) === 'edit' && title !== undefined && section !== 'new') {
+
    /**
            $(this).after(
+
    * @module 快速预览文章页
              $('<span>', {
+
    * @param params {Object}
                'class': 'in-page-edit-article-link-group'
+
    */
              }).append(
+
    InPageEdit.quickPreview = function (params, modalSize = 'large', center = false) {
                $('<a>', {
+
      var defaultOptions = {
                  'href': 'javascript:void(0)',
+
        action: 'parse',
                  'class': 'in-page-edit-article-link'
+
        preview: true,
                })
+
        disableeditsection: true,
                  .text(msg('quick-edit'))
+
        prop: 'text',
                  .click(function () {
+
        preview: true,
                    if (revision !== null) {
+
        format: 'json'
                      InPageEdit.edit({
+
      }
                        page: title,
+
      var options = $.extend({}, defaultOptions, params);
                        revision: revision
+
      mw.hook('InPageEdit.quickPreview').fire();
                      });
+
      var timestamp = new Date().getTime();
                    } else {
+
      console.time('[InPageEdit] Request preview');
                      InPageEdit.edit({
+
      ssi_modal.show({
                        page: title,
+
        sizeClass: new RegExp(/dialog|small|smallToMedium|medium|mediumToLarge|large|full|auto/).test(modalSize) ? modalSize : 'large',
                        section: section
+
        center: Boolean(center),
                      });
+
        className: 'in-page-edit previewbox',
                    }
+
        title: _msg('preview-title'),
                  })));
+
        content: $('<section>').append(
           }
+
          $progress,
         });
+
          $('<div>', { class: 'InPageEditPreview', 'data-timestamp': timestamp, style: 'display:none', text: _msg('preview-placeholder') })
      };
+
        ),
 +
        fixedHeight: true,
 +
        fitScreen: true,
 +
        buttons: [{ label: '', className: 'hideThisBtn' }],
 +
        onShow: function (modal) {
 +
          $('.previewbox .ipe-progress').css('margin-top', $('.previewbox .ipe-progress').parent().height() / 2);
 +
          $('.previewbox .hideThisBtn').hide();
 +
          new mw.Api().post(options).then(function (data) {
 +
            console.timeEnd('[InPageEdit] Request preview');
 +
            var content = data.parse.text['*'];
 +
            $('.previewbox .ipe-progress').hide(150);
 +
            $('.InPageEditPreview[data-timestamp="' + timestamp + '"]').fadeIn(500).html(content);
 +
          }).fail(function () {
 +
            console.timeEnd('[InPageEdit] Request preview');
 +
            console.warn('[InPageEdit] 预览失败');
 +
            $('.previewbox .ipe-progress').hide(150);
 +
            $('.InPageEditPreview[data-timestamp="' + timestamp + '"]').fadeIn(500).html(_msg('preview-error'));
 +
           });
 +
         }
 +
      });
 +
    }
  
      /** 快速预览文章页 **/
+
    /**
      InPageEdit.quickPreview = function (params) {
+
    * @module 载入中模块
         var timestamp = new Date().getTime();
+
    * @param title
         console.time('[InPageEdit] Request preview');
+
    * - √Boolean× true: Mark top progress box as done; false: Close top progress box
 +
    *  - "String" Show new progress box with title @default 'Loading...'
 +
    */
 +
    InPageEdit.progress = function (title) {
 +
      if (title === true) {
 +
         $('.in-page-edit.loadingbox .ssi-modalTitle').html(_msg('done'));
 +
        $('.in-page-edit.loadingbox .ipe-progress').addClass('done');
 +
      } else if (title === false) {
 +
        if ($('.in-page-edit.loadingbox').length > 0) {
 +
          $('.in-page-edit.loadingbox').appendTo('body');
 +
          ssi_modal.close();
 +
         }
 +
      } else {
 +
        if ($('.in-page-edit.loadingbox').length > 0) return;
 +
        if (typeof title === 'undefined') {
 +
          title = 'Loading...'
 +
        }
 
         ssi_modal.show({
 
         ssi_modal.show({
           sizeClass: 'large',
+
           title: title,
          className: 'in-page-edit previewbox',
+
           content: $progress,
           content: '<div class="ipe-progress" style="width:100%"><div class="ipe-progress-bar"></div></div><section id="InPageEditPreview" data-timestamp="' + timestamp + '" style="display:none">' + msg('preview-placeholder') + '</section>',
+
           className: 'in-page-edit loadingbox',
           title: msg('preview-title'),
+
           center: true,
           fixedHeight: true,
+
           sizeClass: 'dialog',
           fitScreen: true,
+
           closeIcon: false,
          buttons: [{ label: '', className: 'hideThisBtn' }],
+
           outSideClose: false
           onShow: function (modal) {
 
            $('.previewbox .ipe-progress').css('margin-top', $('.previewbox .ipe-progress').parent().height() / 2);
 
            $('.previewbox .hideThisBtn').hide();
 
            new mw.Api().post(params).then(function (data) {
 
              console.timeEnd('[InPageEdit] Request preview');
 
              var content = data.parse.text['*'];
 
              $('.previewbox .ipe-progress').hide(150);
 
              $('#InPageEditPreview[data-timestamp="' + timestamp + '"]').fadeIn(500).html(content);
 
            }).fail(function () {
 
              console.timeEnd('[InPageEdit] Request preview');
 
              console.warn('[InPageEdit] 预览失败');
 
              $('.previewbox .ipe-progress').hide(150);
 
              $('#InPageEditPreview[data-timestamp="' + timestamp + '"]').fadeIn(500).html(msg('preview-error'));
 
            });
 
           }
 
 
         });
 
         });
       };
+
       }
 +
    }
  
      /** 载入中模块 **/
+
    /**
      InPageEdit.progress = function (title) {
+
    * @module 版本信息模块
        if (title === true) {
+
    * @description Show Update Logs Modal box
          $('.in-page-edit.loadingbox .ssi-modalTitle').html(msg('done'));
+
    */
           $('.in-page-edit.loadingbox .ipe-progress').addClass('done');
+
    InPageEdit.versionInfo = function () {
        } else if (title === false) {
+
      // 显示模态框
          if ($('.in-page-edit.loadingbox').length > 0) {
+
      ssi_modal.show({
            $('.in-page-edit.loadingbox').appendTo('body');
+
        className: 'in-page-edit update-logs-modal',
             ssi_modal.close();
+
        title: _msg('updatelog-title') + ' - <span id="yourVersion">' + InPageEdit.version + '</span>',
 +
        content: $('<section>').append(
 +
           $('<iframe>', { style: 'margin: 0;padding: 0;width: 100%;height: 80vh;border: 0;', src: 'https://dragon-fish.github.io/inpageedit-v2/update-logs/?iframe=1' })
 +
        ),
 +
        buttons: [{
 +
          label: 'GitHub',
 +
          className: 'btn btn-secondary',
 +
          method: function () {
 +
            window.open('https://github.com/Dragon-Fish/InPageEdit-v2');
 +
          }
 +
        }, {
 +
          label: _msg('updatelog-about'),
 +
          className: 'btn btn-secondary',
 +
          method: function () {
 +
             window.open('https://dragon-fish.github.io/inpageedit-v2/');
 
           }
 
           }
         } else {
+
         }, {
           if ($('.in-page-edit.loadingbox').length > 0) return;
+
           label: _msg('close'),
           if (typeof (title) === 'undefined') {
+
           className: 'btn btn-primary',
             title = 'Loading...'
+
          method: function (a, modal) {
 +
             modal.close();
 
           }
 
           }
          ssi_modal.show({
+
        }]
            title: title,
+
      });
            content: '<div class="ipe-progress" style="width:100%"><div class="ipe-progress-bar"></div></div>',
+
    };
            className: 'in-page-edit loadingbox',
+
 
            center: true,
+
    /**
            sizeClass: 'dialog',
+
    * @module 关于插件模块
            closeIcon: false,
+
    * @description Show "What is" modal box of IPE2
            outSideClose: false
+
    */
           });
+
    InPageEdit.about = function () {
 +
      ssi_modal.show({
 +
        title: '关于InPageEdit',
 +
        className: 'in-page-edit in-page-edit-about',
 +
        // sizeClass: 'dialog',
 +
        content: $('<section>').append(
 +
          $('<iframe>', { style: 'margin: 0;padding: 0;width: 100%;height: 80vh;border: 0;', src: 'https://dragon-fish.github.io/inpageedit-v2/about/?iframe=1' })
 +
        )
 +
      });
 +
    }
 +
 
 +
    /**
 +
    * @module 特别通知
 +
    */
 +
    InPageEdit.specialNotice = function () {
 +
      ssi_modal.notify('dialog', {
 +
        className: 'in-page-edit ipe-special-notice',
 +
        title: _msg('version-notice-title'),
 +
        content: _msg('version-notice'),
 +
        okBtn: {
 +
          label: _msg('updatelog-dismiss'),
 +
           className: 'btn btn-primary'
 
         }
 
         }
       };
+
       }, function (e, modal) {
 +
        localStorage.setItem('InPageEditNoticeId', _msg('noticeid'));
 +
        modal.close();
 +
      });
 +
    }
  
      /** 提交统计信息模块 **/
+
    /**
       InPageEdit.analysis = function (params) {
+
    * @module 获取版本更新提示
        var type = params.type;
+
    */
        switch (type) {
+
    !(function () {
           case 'siteCount':
+
       var version = InPageEdit.version;
             $.ajax({
+
      // 版本更新
               url: 'https://doc.wjghj.cn/InPageEditAnalysis/site/log.php',
+
      if (localStorage.getItem('InPageEditVersion') !== version) {
               data: {
+
        ssi_modal.notify('', {
                 'sitename': mw.config.get('wgSiteName')
+
          title: _msg('updatelog-update-success-title'),
 +
          content: _msg('updatelog-update-success', version),
 +
          className: 'in-page-edit',
 +
          buttons: [{
 +
            className: 'btn btn-primary',
 +
            label: _msg('updatelog-button-versioninfo'),
 +
            method: function (a, modal) {
 +
              localStorage.InPageEditVersion = version;
 +
              InPageEdit.versionInfo();
 +
              modal.close();
 +
            }
 +
          }],
 +
          closeAfter: {
 +
            time: 30,
 +
            resetOnHover: true
 +
           },
 +
          onClose: function () {
 +
             ssi_modal.notify('', {
 +
               className: 'in-page-edit',
 +
              content: _msg('updatelog-after-close', '<a href="' + InPageEdit.api.updatelogsUrl + '" to="_blank">' + InPageEdit.api.updatelogsUrl + '</a>').replace('$2', '<a href="https://github.com/Dragon-Fish/InPageEdit-v2">' + _msg('updatelog-file-issue') + '</a>'),
 +
               closeAfter: {
 +
                 time: 10
 
               },
 
               },
               dataType: 'json'
+
               buttons: [{
 +
                className: 'btn btn-primary',
 +
                label: _msg('ok'),
 +
                method: function (a, modal) {
 +
                  modal.close();
 +
                }
 +
              }]
 
             });
 
             });
             break;
+
             localStorage.InPageEditVersion = version;
           case 'dateCount':
+
           }
            var now = new Date(),
+
        });
              y = now.getFullYear(), m = Number(now.getMonth() + 1), d = Number(now.getDate());
+
      }
            if (m < 10) m = '0' + m;
+
      if (localStorage.getItem('InPageEditNoticeId') !== _msg('noticeid')) {
            if (d < 10) d = '0' + d;
+
        InPageEdit.specialNotice();
            var time = y + '-' + m + '-' + d;
+
      }
            $.ajax({
+
    }());
              url: 'https://doc.wjghj.cn/InPageEditAnalysis/date/log.php',
 
              data: {
 
                'date': time
 
              },
 
              dataType: 'json'
 
            });
 
            break;
 
          case 'functionCount':
 
            $.ajax({
 
              url: 'https://doc.wjghj.cn/InPageEditAnalysis/function/log.php',
 
              data: {
 
                'function': params.function
 
              },
 
              dataType: 'json'
 
            });
 
            break;
 
        }
 
      };
 
  
      /** 获取用户权限信息 **/
+
    /**
      var user = mw.config.get('wgUserName');
+
    * @description 获取用户权限信息
      if (user === null) {
+
    */
        console.warn('[InPageEdit] 警告:用户未登录');
+
    !(function () {
        mw.config.set('wgUserRights', '');
+
       mw.user.getRights().then(function (rights) {
        return;
 
      }
 
       new mw.Api().get({
 
        action: 'query',
 
        list: 'users',
 
        usprop: 'rights',
 
        ususers: user
 
      }).done(function (data) {
 
 
         console.info('[InPageEdit] 成功获取用户权限信息');
 
         console.info('[InPageEdit] 成功获取用户权限信息');
         mw.config.set('wgUserRights', data.query.users[0]['rights']);
+
         mw.config.set('wgUserRights', rights);
 
       }).fail(function () {
 
       }).fail(function () {
 
         console.warn('[InPageEdit] 警告:无法获取用户权限信息');
 
         console.warn('[InPageEdit] 警告:无法获取用户权限信息');
         mw.config.set('wgUserRights', '');
+
         mw.config.set('wgUserRights', []);
 
       });
 
       });
 +
      if (mw.user.getName() !== null) {
 +
        new mw.Api().get({
 +
          action: 'query',
 +
          list: 'users',
 +
          usprop: 'blockinfo',
 +
          ususers: mw.user.getName()
 +
        }).then(function (data) {
 +
          if (data.query.users[0].hasOwnProperty('blockid')) {
 +
            mw.config.set('wgUserIsBlocked', true);
 +
          } else {
 +
            mw.config.set('wgUserIsBlocked', false);
 +
          }
 +
        });
 +
      }
 +
    }());
 +
 +
    /**
 +
    * @module 是否拥有权限
 +
    * @param {String} right
 +
    * @return {Boolean}
 +
    */
 +
    const _hasRight = function (right) {
 +
      if (config.wgUserIsBlocked === true) {
 +
        return false;
 +
      }
 +
      if (mw.config.get('wgUserRights').indexOf(right) > -1) {
 +
        return true;
 +
      } else {
 +
        return false;
 +
      }
 +
    };
 +
 +
    /**
 +
    * @module 提交统计信息模块
 +
    * @description Internal module
 +
    */
 +
    const _analysis = function (functionID) {
 +
      if (InPageEdit.doNotCollectMyInfo === true) {
 +
        // console.info('[InPageEdit] 我们已不再收集您使用插件的信息。');
 +
        // return;
 +
      }
 +
      var submitdata = {
 +
        'action': 'submit',
 +
        'url': config.wgServer + config.wgArticlePath.replace('$1', ''),
 +
        'sitename': config.wgSiteName,
 +
        'username': config.wgUserName,
 +
        'function': functionID
 +
      }
 +
      $.ajax({
 +
        url: InPageEdit.api.analysis,
 +
        data: submitdata,
 +
        type: 'post',
 +
        dataType: 'json'
 +
      }).done(function (data) {
 +
        console.log('[InPageEdit] Analysis response\nStatus: ' + data.status + '\nMessage: ' + data.msg);
 +
      });
 +
    }
 +
 +
    /**
 +
    * @description 页面载入完成,自动加载某些模块
 +
    */
 +
    !(function () {
 +
      // 初始化设定
 +
      InPageEdit.preference.set();
 +
      // 快速页面差异模块
 +
      InPageEdit.loadQuickDiff();
 +
      // 加载段落编辑模块
 +
      InPageEdit.articleLink();
 +
    }());
 +
 +
    /**
 +
    * @module Toolbox模块
 +
    */
 +
    mw.hook('InPageEdit').add(function () {
 +
      // 检测是否为文章页
 +
      if (!config.wgIsArticle || $('#ipe-edit-toolbox').length > 0) {
 +
        console.warn('[InPageEdit] 未载入 Toolbox');
 +
        return;
 +
      }
  
       InPageEdit.hasRight = function (right) {
+
       /** IPE工具盒 **/
        if (mw.config.get('wgUserRights').indexOf(right) > -1) {
+
      $('<div>', { id: 'ipe-edit-toolbox' }).append(
           return true;
+
        $('<ul>', { class: 'btn-group group1' }).append(
         } else {
+
          $('<li>', { class: 'btn-tip-group' }).append(
           return false;
+
            $('<div>', { class: 'btn-tip', text: _msg('quick-edit') }),
         }
+
            $('<button>', { id: 'edit-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-pencil"></i>' }).click(function () {
       };
+
              InPageEdit.quickEdit({
 +
                page: config.wgPageName,
 +
                revision: config.wgRevisionId
 +
              });
 +
            })
 +
          ),
 +
          $('<li>', { class: 'btn-tip-group' }).append(
 +
            $('<div>', { class: 'btn-tip', text: _msg('redirect-from') }),
 +
            $('<button>', { id: 'redirectfrom-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-sign-in"></i>' }).click(function () {
 +
              InPageEdit.quickRedirect('from');
 +
            })
 +
          ),
 +
           $('<li>', { class: 'btn-tip-group' }).append(
 +
            $('<div>', { class: 'btn-tip', text: _msg('redirect-to') }),
 +
            $('<button>', { id: 'redirectto-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-sign-out"></i>' }).click(function () {
 +
              InPageEdit.quickRedirect('to');
 +
            })
 +
          )
 +
        ),
 +
         $('<ul>', { class: 'btn-group group2' }).append(
 +
          $('<div>', { style: 'display: flex;' }).append(
 +
            $('<li>', { class: 'btn-tip-group' }).append(
 +
              $('<div>', { class: 'btn-tip', text: _msg('quick-delete') }),
 +
              $('<button>', { id: 'deletepage-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-trash"></i>' }).click(function () {
 +
                InPageEdit.quickDelete();
 +
              })
 +
            ),
 +
            $('<li>', { class: 'btn-tip-group' }).append(
 +
              $('<div>', { class: 'btn-tip', text: _msg('quick-rename') }),
 +
              $('<button>', { id: 'renamepage-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-italic"></i>' }).click(function () {
 +
                InPageEdit.quickRename();
 +
              })
 +
            ),
 +
            $('<li>', { class: 'btn-tip-group' }).append(
 +
              $('<div>', { class: 'btn-tip', text: _msg('ipe-preference') }),
 +
              $('<button>', { id: 'preference-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-gear"></i>' }).click(function () {
 +
                InPageEdit.preference.modal();
 +
              })
 +
            )
 +
           )
 +
        ),
 +
         $('<button>', { class: 'ipe-toolbox-btn', id: 'toolbox-toggle', html: '<i class="fa fa-plus"></i>' })
 +
       ).appendTo('body');
  
       /** 初始化 **/
+
       $('#ipe-edit-toolbox .btn-group button').click(function () {
      (function () {
+
         _analysis('tool_box')
         /** 额外的模块 **/
+
      });
        // 快速页面差异模块
 
        InPageEdit.loadQuickDiff();
 
  
        /** Toolbox模块 **/
+
      // 设置开关等
        // 检测是否为文章页
+
      var toolBoxInner = $('#ipe-edit-toolbox #toolbox-toggle, #ipe-edit-toolbox .btn-group');
         if (mw.config.get('wgIsArticle') === false) {
+
      $('#ipe-edit-toolbox #toolbox-toggle').click(function () {
           console.warn('%c[InPageEdit] 不是文章页面,未载入工具盒。', 'color:orange;font-size:1.2em;font-weight:bold');
+
         if ($(this).hasClass('opened') && !$(this).hasClass('click')) {
           return;
+
           InPageEdit.preference.set({ lockToolBox: true });
 +
          toolBoxInner.addClass('click');
 +
        } else if ($(this).hasClass('click')) {
 +
          InPageEdit.preference.set({ lockToolBox: false });
 +
          toolBoxInner.removeClass('click');
 +
        } else {
 +
          InPageEdit.preference.set({ lockToolBox: true });
 +
           toolBoxInner.addClass('click opened');
 
         }
 
         }
 
+
      });
        // 读取设定
+
      // 如果锁定过工具盒,就自动展开
        if (localStorage.getItem('InPageEditPreference') === null) {
+
      if (InPageEdit.preference.get('lockToolBox') === true) {
          // 没有保存任何设置
+
        toolBoxInner.addClass('click opened');
          var ipePreference = {};
+
      }
          ipePreference.outSideClose = true;
+
      $('#ipe-edit-toolbox').hover(function () {
          ipePreference.editMinor = false;
+
        toolBoxInner.addClass('hover opened');
          ipePreference.editSummary = msg('preference-summary-default');
+
      }, function () {
           localStorage.setItem('InPageEditPreference', JSON.stringify(ipePreference));
+
        toolBoxInner.removeClass('hover');
 +
        if (!$('#ipe-edit-toolbox #toolbox-toggle').hasClass('click')) {
 +
           toolBoxInner.removeClass('opened');
 
         }
 
         }
 +
      });
 +
      mw.hook('InPageEdit.toolbox').fire();
 +
    });
  
        // ipe工具盒
+
    // Init End
        $('body').append(
+
  }
          '<div id="ipe-edit-toolbox">' +
 
  
          // group1 上方的一列按钮
+
  // 花里胡哨的加载提示
          '<ul class="btn-group group1">' +
+
  mw.hook('InPageEdit').fire();
          '<li class="btn-tip-group"><div class="btn-tip">' + msg('quick-edit') + '</div><button id="edit-btn" class="ipe-toolbox-btn material-icons">edit</button></li>' +
+
  console.info('   ____      ____                  ______    ___ __              _    _____ \n  /  _/___  / __ \\____ _____ ____  / ____/___/ (_) /_            | |  / /__ \\\n  / // __ \\/ /_/ / __ `/ __ `/ _ \\/ __/ / __  / / __/  ______    | | / /__/ /\n _/ // / / / ____/ /_/ / /_/ /  __/ /___/ /_/ / / /_  /_____/    | |/ // __/ \n/___/_/ /_/_/    \\__,_/\\__, /\\___/_____/\\__,_/_/\\__/             |___//____/ \n                      /____/');
          '<li class="btn-tip-group"><div class="btn-tip">' + msg('redirect-from') + '</div><button id="redirectfrom-btn" class="ipe-toolbox-btn material-icons">flight_land</button></li>' +
 
          '<li class="btn-tip-group"><div class="btn-tip">' + msg('redirect-to') + '</div><button id="redirectto-btn" class="ipe-toolbox-btn material-icons">flight_takeoff</button></li>' +
 
          '</ul>' +
 
  
          // group2 左边的一排按钮
+
  return InPageEdit;
          '<ul class="btn-group group2"><div style="display: flex;">' +
 
          '<li class="btn-tip-group"><div class="btn-tip">' + msg('quick-delete') + '</div><button id="deletepage-btn" class="ipe-toolbox-btn material-icons">delete_forever</button></li>' +
 
          '<li class="btn-tip-group"><div class="btn-tip">' + msg('quick-rename') + '</div><button id="renamepage-btn" class="ipe-toolbox-btn material-icons">format_italic</button></li>' +
 
          '<li class="btn-tip-group"><div class="btn-tip">' + msg('ipe-preference') + '</div><button id="preference-btn" class="ipe-toolbox-btn material-icons">settings</button></li>' +
 
          '</div></ul>' +
 
 
 
          '<button class="ipe-toolbox-btn material-icons" id="toolbox-toggle">add</button>' +
 
          '</div>');
 
        $('#ipe-edit-toolbox #toolbox-toggle').click(function () {
 
          $('#ipe-edit-toolbox #toolbox-toggle, #ipe-edit-toolbox .btn-group').toggleClass('opened');
 
        });
 
        $('body > *:not(#ipe-edit-toolbox)').click(function () {
 
          $('#ipe-edit-toolbox #toolbox-toggle, #ipe-edit-toolbox .btn-group').removeClass('opened');
 
        });
 
        $('#ipe-edit-toolbox .btn-group .ipe-toolbox-btn').click(function () {
 
          InPageEdit.analysis({ type: 'functionCount', function: '工具盒' });
 
          switch ($(this).attr('id')) {
 
            case 'edit-btn':
 
              InPageEdit.edit({
 
                page: mw.config.get('wgPageName'),
 
                revision: mw.config.get('wgRevisionId')
 
              });
 
              break;
 
            case 'redirectfrom-btn':
 
              InPageEdit.redirect('from');
 
              break;
 
            case 'redirectto-btn':
 
              InPageEdit.redirect('to');
 
              break;
 
            case 'preference-btn':
 
              InPageEdit.preference();
 
              break;
 
            case 'deletepage-btn':
 
              InPageEdit.deletepage();
 
              break;
 
            case 'renamepage-btn':
 
              InPageEdit.renamepage();
 
              break;
 
          }
 
        });
 
        // 加载段落编辑模块
 
        InPageEdit.articleLink();
 
        // 花里胡哨的加载提示
 
        console.info('    ____      ____                  ______    ___ __              _    _____ \n  /  _/___  / __ \\____ _____ ____  / ____/___/ (_) /_            | |  / /__ \\\n  / // __ \\/ /_/ / __ `/ __ `/ _ \\/ __/ / __  / / __/  ______    | | / /__/ /\n _/ // / / / ____/ /_/ / /_/ /  __/ /___/ /_/ / / /_  /_____/    | |/ // __/ \n/___/_/ /_/_/    \\__,_/\\__, /\\___/_____/\\__,_/_/\\__/              |___//____/ \n                      /____/');
 
      }());
 
    }
 
  });
 
  
}());
+
}));

Latest revision as of 03:34, 10 July 2020

/**
 * @license GPL-3.0 GNU GENERAL PUBLIC LICENSE 3.0
 *
 * @name InPageEdit-v2
 * @description A JavaScript-based MediaWiki Plugin: 
 * @author 机智的小鱼君
 * @url https://github.com/Dragon-Fish/InPageEdit-v2
 */
!(function (root, factory) {
  root.InPageEdit = factory(root.jQuery);
}(this, function ($) {
  'use strict';
  /**
   * @description 检查插件是否已经运行,创建全局函数
   */
  window.InPageEdit = window.InPageEdit || {};
  if (typeof (InPageEdit.version) !== 'undefined') { throw '[InPageEdit] 已经有一个IPE插件在执行了'; }
  InPageEdit.isCanary = false;
  InPageEdit.api = {
    analysis: 'https://doc.wjghj.cn/inpageedit-v2/analysis/api/index.php',
    aboutUrl: 'https://dragon-fish.github.io/inpageedit-v2/about/',
    analysisUrl: 'https://dragon-fish.github.io/inpageedit-v2/analysis/',
    updatelogsUrl: 'https://dragon-fish.github.io/inpageedit-v2/update-logs/'
  }
  InPageEdit.version = '2.13.4-5';
  // 冻结重要全局变量
  Object.freeze(InPageEdit.api);
  Object.freeze(InPageEdit.version);

  /**
   * @description 常用变量以及函数
   */
  var config = mw.config.get(),
    _loadScript = function (src) {
      return $.ajax({
        url: src,
        dataType: 'script',
        crossDomain: !0,
        cache: !0
      });
    };

  /**
   * @name 导入依赖
   * @description 加载需要的依赖项,然后进行初始化
   */
  /* 样式表 */
  $('head').prepend(
    // 模态框
    $('<link>', { rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/src/ssi_modal/ssi-modal.min.css' }),
    // FontAwesome
    $('<link>', { rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/npm/[email protected]/css/font-awesome.min.css' }),
    // 覆写
    $('<link>', { rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/src/skin/ipe-default.min.css' })
  );
  /* I18n-js */
  _loadScript('https://cdn.jsdelivr.net/gh/dragon-fish/i18n-js@master/script.min.js'); // 因为留有钩子,无需异步,与模态框同时加载提升速度
  /* 模态框 */
  _loadScript('https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/src/ssi_modal/ssi-modal.min.js').done(() => {
    mw.hook('dfgh.i18n').add(i18nJs => {
      i18nJs.loadMessages('InPageEdit-v2').then(init);
    })
  }).fail((...res) => {
    console.error('[InPageEdit] 初始化时遇到致命错误:', ...res);
  });

  /**
   * @function InPageEdit
   */
  function init(i18n) {
    /**
     * @function i18n模块
     * @param {string} 'message-name', '$1', '$2', ...
     * @example _msg('updatelog-update-success', InPageEdit.version) => InPageEdit <version> has been installed.
     */
    function _msg(...args) {
      var msgName = args.shift();
      return i18n.msg(msgName, ...args).parse();
    }

    /**
     * @description 常用 html 结构
     */
    var $br = '<br>',
      $hr = '<hr>',
      $progress = '<div class="ipe-progress" style="width: 100%"><div class="ipe-progress-bar"></div></div>';

    /**
     * @module 快速编辑模块
     * 
     * @param {Object} options
     * @param {String} options.page edit page (default: wgPageName)
     * @param {Number} options.revision page rev ID
     * @param {Number} options.section edit section
     * @param {Boolean} options.reload if reload page after save successful (default: true)
     */
    InPageEdit.edit = InPageEdit.quickEdit = function (options) {
      mw.hook('InPageEdit.quickEdit').fire();
      /** 获取设定信息,设置缺省值 **/
      var options = options || {};
      if (typeof options === 'string') {
        options = {
          page: options
        }
      }
      var defaultOptions = {
        page: config.wgPageName,
        pageId: -1,
        revision: null,
        summaryRevision: '',
        section: null,
        editText: '',
        editMinor: false,
        editSummary: _msg('preference-summary-default'),
        editNotice: '',
        outSideClose: true,
        jsonGet: {
          action: 'parse',
          page: options.page || config.wgPageName,
          prop: 'wikitext|langlinks|categories|templates|images|sections',
          format: 'json'
        },
        jsonPost: {},
        pageDetail: {},
        jumpTo: '',
        reload: true
      }

      /** 获取用户设置 **/
      var preference = InPageEdit.preference.get();

      /** 缓存时间戳 **/
      var date = new Date(),
        timestamp = date.getTime(),
        now = date.toUTCString();

      /** 将选项合并并标准化 **/
      options = $.extend({}, defaultOptions, options, preference);
      options.page = decodeURIComponent(options.page); // 解码网址 Unicode

      _analysis('quick_edit');

      if (options.revision !== null && options.revision !== '' && options.revision !== config.wgCurRevisionId) {
        ssi_modal.notify('warning', {
          className: 'in-page-edit',
          content: _msg('notify-editing-history'),
          title: _msg('notify-info')
        });
        delete options.jsonGet.page;
        options.jsonGet.oldid = options.revision;
        options.summaryRevision = '(' + _msg('editor-summary-rivision') + '[[Special:Diff/' + options.revision + ']])';
      } else {
        if (options.section !== null && options.section !== '') {
          options.jsonGet.section = options.section;
        }
      }

      // Debug
      console.time('[InPageEdit] 获取页面源代码');
      console.info('[InPageEdit] QuickEdit start with options:');
      console.table(options);

      // 显示主窗口
      ssi_modal.show({
        title: _msg('editor-title-editing') + ': <u class="editPage">' + options.page.replace(/\_/g, ' ') + '</u>',
        content:
          $('<div>').append(
            $progress,
            $('<section>', { class: 'hideBeforeLoaded' }).append(
              // 编辑工具条
              $('<div>', { class: 'editTools' }).append(
                $('<div>', { class: 'btnGroup' }).append(
                  $('<div>', { class: 'toolSelect' }).append(
                    $('<div>', { class: 'label', text: _msg('editor-edittool-header') }),
                    $('<ul>', { class: 'ul-list' }).append(
                      $('<li>', { class: 'editToolBtn', 'data-open': '\n== ', 'data-middle': _msg('editor-edittool-header-text'), 'data-close': ' ==\n', text: 'H2' }),
                      $('<li>', { class: 'editToolBtn', 'data-open': '\n=== ', 'data-middle': _msg('editor-edittool-header-text'), 'data-close': ' ===\n', text: 'H3' }),
                      $('<li>', { class: 'editToolBtn', 'data-open': '\n==== ', 'data-middle': _msg('editor-edittool-header-text'), 'data-close': ' ====\n', text: 'H4' }),
                      $('<li>', { class: 'editToolBtn', 'data-open': '\n===== ', 'data-middle': _msg('editor-edittool-header-text'), 'data-close': ' =====\n', text: 'H5' })
                    )
                  )
                ),
                $('<div>', { class: 'btnGroup' }).append(
                  $('<span>', { class: 'label', text: '格式' }),
                  $('<button>', { class: 'editToolBtn fa fa-bold btn', 'data-open': "'''", 'data-middle': _msg('editor-edittool-bold'), 'data-close': "'''" }),
                  $('<button>', { class: 'editToolBtn fa fa-italic btn', 'data-open': "''", 'data-middle': _msg('editor-edittool-italic'), 'data-close': "''" }),
                  $('<button>', { class: 'editToolBtn fa fa-list-ul btn', 'data-open': '\n* ', 'data-middle': _msg('editor-edittool-list-bulleted'), 'data-close': '\n' }),
                  $('<button>', { class: 'editToolBtn fa fa-list-ol btn', 'data-open': '\n# ', 'data-middle': _msg('editor-edittool-list-numbered'), 'data-close': '\n' }),
                  $('<button>', { class: 'editToolBtn fa fa-won btn', 'data-open': '<' + 'nowiki>', 'data-middle': _msg('editor-edittool-nowiki'), 'data-close': '</nowiki>' }),
                  $('<button>', { class: 'editToolBtn fa fa-level-down fa-rotate-90 btn', 'data-open': '<br>\n', 'data-middle': '', 'data-close': '' })
                ),
                $('<div>', { class: 'btnGroup' }).append(
                  $('<span>', { class: 'label', text: '插入' }),
                  $('<button>', { class: 'editToolBtn fa fa-link btn', 'data-open': '[' + '[', 'data-middle': _msg('editor-edittool-internal-link'), 'data-close': ']]' }),
                  $('<button>', { class: 'editToolBtn fa fa-file-image-o btn', 'data-open': '[' + '[File:', 'data-middle': 'Example.png', 'data-close': '|thumb]]' }),
                  $('<button>', { class: 'editToolBtn btn', 'data-open': '\n<' + 'gallery>\n', 'data-middle': 'Example1.jpg|Description\nExample2.png|Description', 'data-close': '\n</gallery>\n', html: '<span class="fa-stack"><i class="fa fa-picture-o fa-stack-1x"></i><i class="fa fa-picture-o fa-stack-1x" style="left: 2px;top: 2px;text-shadow: 1px 1px 0 #fff;"></i></span>' })
                ),
                $('<div>', { class: 'btnGroup extra', style: 'display: none' }).append(
                  $('<span>', { class: 'label', text: '自定义' })
                ),
                $('<div>', { class: 'btnGroup special-tools', style: 'float: right' }).append(
                  $('<button>', { class: 'btn fa fa-search' }).click(function () {
                    InPageEdit.findAndReplace($('.ipe-editor.timestamp-' + timestamp + ' .editArea'));
                  })
                )
              ),
              // 编辑框
              $('<textarea>', { class: 'editArea', style: 'margin-top: 0;' }),
              // 页面分析
              $('<div>', { class: 'editOptionsLabel hideBeforeLoaded' }).append(
                $('<aside>', { class: 'detailArea' }).append(
                  $('<label>', { class: 'detailToggle', text: _msg('editor-detail-button-toggle') }),
                  $('<div>', { class: 'detailBtnGroup' }).append(
                    $('<a>', { href: 'javascript:;', class: 'detailBtn', id: 'showTemplates', text: _msg('editor-detail-button-templates') }),
                    ' | ',
                    $('<a>', { href: 'javascript:;', class: 'detailBtn', id: 'showImages', text: _msg('editor-detail-button-images') })
                  )
                ),
                // 摘要&小编辑
                $('<label>', { for: 'editSummary', text: _msg('editSummary') }),
                $br,
                $('<input>', { class: 'editSummary', id: 'editSummary', placeholder: 'Edit via InPageEdit~', value: options.editSummary.replace(/\$oldid/ig, options.summaryRevision) }),
                $br,
                $('<label>').append(
                  $('<input>', { type: 'checkbox', class: 'editMinor', id: 'editMinor', checked: options.editMinor }),
                  $('<span>', { text: _msg('markAsMinor') })
                ),
                $br,
                $('<label>').append(
                  $('<input>', { type: 'checkbox', class: 'reloadPage', id: 'reloadPage', checked: options.reload }),
                  $('<span>', { text: _msg('editor-reload-page') })
                )
              )
            )
          ),
        outSideClose: options.outSideClose,
        className: 'in-page-edit ipe-editor timestamp-' + timestamp,
        sizeClass: 'large',

        /* 按钮 */
        buttons: [{
          label: _msg('editor-button-save'),
          className: 'btn btn-primary leftBtn hideBeforeLoaded save-btn',
          method: function (e, modal) {
            var modal = modal;
            ssi_modal.confirm({
              className: 'in-page-edit',
              center: true,
              content: _msg('editor-confirm-save'),
              okBtn: {
                className: 'btn btn-primary',
                label: _msg('confirm')
              },
              cancelBtn: {
                className: 'btn btn-secondary',
                label: _msg('cancel')
              },
            },
              function (result) {
                if (result) {
                  var text = $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val(),
                    minor = $('.ipe-editor.timestamp-' + timestamp + ' .editMinor').prop('checked'),
                    section = options.section,
                    summary = $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val();
                  postArticle({
                    text: text,
                    page: options.page,
                    minor: minor,
                    section: section,
                    summary: summary
                  }, modal);
                }
              });
          }
        }, {
          label: _msg('editor-button-preview'),
          className: 'btn btn-secondary leftBtn hideBeforeLoaded',
          method: function () {
            _analysis('preview_edit');
            var text = $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val();
            InPageEdit.quickPreview({
              title: options.page,
              text: text,
              pst: true
            });
          }
        }, {
          label: _msg('editor-button-diff'),
          className: 'btn btn-secondary leftBtn hideBeforeLoaded diff-btn',
          method: function () {
            // ...
          }
        }, {
          label: _msg('cancel'),
          className: 'btn btn-danger',
          method: function (e, modal) {
            modal.close();
          }
        }
        ],

        /* 预加载 */
        beforeShow: function () {
          // 设置样式
          $('.ipe-editor.timestamp-' + timestamp + ' .hideBeforeLoaded').hide();
          $('.ipe-editor.timestamp-' + timestamp + ' .ipe-progress').css('margin', Number($(window).height() / 3 - 50) + 'px 0');
          $('.ipe-editor.timestamp-' + timestamp + ' .editArea').css('height', $(window).height() / 3 * 2 - 100);
          $('.ipe-editor.timestamp-' + timestamp + ' .editOptionsLabel').prependTo('.ipe-editor.timestamp-' + timestamp + ' .ssi-buttons');
          $('.ipe-editor.timestamp-' + timestamp + ' .leftBtn').appendTo('.ipe-editor.timestamp-' + timestamp + ' .ssi-leftButtons');
          $('.ipe-editor.timestamp-' + timestamp + ' .ssi-modalTitle').append(
            $('<a>', {
              class: 'showEditNotice',
              href: 'javascript:void(0);',
              html: '<i class="fa fa-info-circle"></i> ' + _msg('editor-has-editNotice'),
              style: 'display: none;'
            }).click(function () {
              ssi_modal.show({
                className: 'in-page-edit',
                center: true,
                title: _msg('editor-title-editNotice'),
                content: '<section class="editNotice">' + $('.ipe-editor.timestamp-' + timestamp).data('editNotice') + '</section>'
              });
            })
          );

          /** Edit-Tool 扩展 **/
          function insertText(strings, obj) {
            var strings = strings,
              textarea = obj || $('.in-page-edit.ipe-editor .editArea')[0],
              start = textarea.selectionStart,
              stop = textarea.selectionEnd,
              selectedText = textarea.value.slice(start, stop);
            textarea.value =
              textarea.value.slice(0, start) +
              (strings.open || '') +
              (selectedText || strings.middle || '') +
              (strings.close || '') +
              textarea.value.slice(stop);
            var selectStart = start + (strings.open.length || 0);
            textarea.setSelectionRange(selectStart, selectStart + (selectedText.length || strings.middle.length || 0));
            textarea.focus();
          }
          // 用户自定义按钮
          if (InPageEdit.buttons) {
            var btns = InPageEdit.buttons;
            $('.ipe-editor.timestamp-' + timestamp + ' .btnGroup.extra').show();
            function addBtn(open, middle, close, icon) {
              var open = open || '',
                middle = middle || '',
                close = close || '',
                icon = 'fa-' + icon || 'fa-wrench';
              $('.ipe-editor.timestamp-' + timestamp + ' .btnGroup.extra').append(
                $('<button>', { class: 'editToolBtn btn', 'data-open': open, 'data-middle': middle, 'data-close': close, html: `<i class="fa ${icon}"></i>` })
              );
            }
            for (var i = 0; i < btns.length; i++) {
              var btn = btns[i];
              addBtn(btn.open, btn.middle, btn.close, btn.text);
            }
          }
          $('.ipe-editor.timestamp-' + timestamp + ' .editToolBtn').click(function (e) {
            e.preventDefault();
            var $this = $(this),
              $open = $this.attr('data-open') || '',
              $middle = $this.attr('data-middle') || '',
              $close = $this.attr('data-close') || '';
            insertText({
              open: $open,
              middle: $middle,
              close: $close
            }, $('.ipe-editor.timestamp-' + timestamp + ' .editArea')[0]);
          });
        },
        /**
         * @event onShow
         * @description 模态框显示后
         */
        onShow: function (a, modal) {
          mw.hook('InPageEdit.quickEdit.modal').fire();
          // 绑定事件,在尝试离开页面时提示
          $('.ipe-editor.timestamp-' + timestamp + ' .editArea').change(function () {
            $(this).attr('data-modifiled', 'true');
            $(window).bind('beforeunload', function () {
              return _msg('window-leave-confirm');
            });
          });
          // 获取权限
          if (_hasRight('edit') === false) {
            ssi_modal.notify('dialog', {
              className: 'in-page-edit',
              position: 'center bottom',
              title: _msg('notify-no-right'),
              content: _msg('editor-no-right'),
              okBtn: {
                label: _msg('ok'),
                className: 'btn btn-primary',
                method: function (e, modal) {
                  modal.close();
                }
              }
            });
            $('.ipe-editor.timestamp-' + timestamp + ' .save-btn').addClass('btn-danger');
          }

          // 解析页面内容
          new mw.Api().get(options.jsonGet).done(function (data) {
            var data = data;
            console.timeEnd('[InPageEdit] 获取页面源代码');
            contentDone(data);
          }).fail(function (a, b, errorThrown) {
            console.timeEnd('[InPageEdit] 获取页面源代码');
            console.warn('[InPageEdit]警告:无法获取页面内容');
            var data = errorThrown;
            contentDone(data);
          });

          // 页面内容获取完毕,后续工作
          function contentDone(data) {
            var data = data;
            options.pageDetail = data;

            if (data.hasOwnProperty('error')) {
              console.warn('[InPageEdit]警告:无法获取页面内容');
              options.editText = '<!-- ' + data.error.info + ' -->';
              options.pageId = -1;
              $('.ipe-editor.timestamp-' + timestamp + ' .detailArea').hide();
            } else {
              options.editText = data.parse.wikitext['*'];
              options.pageId = data.parse.pageid;
            }
            // 设定一堆子样式
            $('.ipe-editor.timestamp-' + timestamp + ' .ipe-progress').hide();
            $('.ipe-editor.timestamp-' + timestamp + ' .hideBeforeLoaded').fadeIn(500);
            $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val(options.editText + '\n');

            if (options.section !== null) {
              var val = $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val();
              val = val.replace(/\$section/ig, '/* ' + data.parse.sections[0].line + ' */');
              $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val(val);
              $('.ipe-editor.timestamp-' + timestamp + ' .editPage').after('<span class="editSection">→' + data.parse.sections[0].line + '</span>');
              options.jumpTo = '#' + data.parse.sections[0].anchor;
            } else {
              var val = $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val();
              val = val.replace(/\$section/ig, '');
              $('.ipe-editor.timestamp-' + timestamp + ' .editSummary').val(val);
              options.jumpTo = '';
            }
            if (options.revision !== null && options.revision !== '' && options.revision !== config.wgCurRevisionId) {
              $('.ipe-editor.timestamp-' + timestamp + ' .editPage').after('<span class="editRevision">(' + _msg('editor-title-editRevision') + ':' + options.revision + ')</span>');
              $('.ipe-editor.timestamp-' + timestamp + ' .diff-btn').click(() => {
                _analysis('quick_diff_edit');
                var text = $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val();
                var diffJson = {
                  fromrev: options.revision,
                  totext: text,
                  hideBtn: true,
                  pageName: options.page,
                  isPreview: true
                }
                if (options.section) {
                  diffJson.fromsection = options.section;
                }
                InPageEdit.quickDiff(diffJson);
              });
            } else {
              $('.ipe-editor.timestamp-' + timestamp + ' .diff-btn').attr('disabled', true);
            }

            // 获取页面基础信息
            console.time('[InPageEdit] 获取页面基础信息');
            var queryJson = {
              action: 'query',
              prop: 'revisions|info',
              inprop: 'protection',
              format: 'json'
            }
            if (options.pageId !== -1) {
              queryJson.pageids = options.pageId;
            } else {
              queryJson.titles = options.page;
            }
            new mw.Api().get(queryJson).done(function (data) {
              var data = data;
              console.info('[InPageEdit] 获取页面基础信息成功');
              console.timeEnd('[InPageEdit] 获取页面基础信息');
              // 记录页面最后编辑时间,防止编辑冲突
              $('.ipe-editor.timestamp-' + timestamp).data('basetimestamp', data['query']['pages'][options.pageId].hasOwnProperty('revisions') ? data['query']['pages'][options.pageId]['revisions'][0]['timestamp'] : now);
              queryDone(data);
            }).fail(function (a, b, errorThrown) {
              var data = errorThrown;
              console.timeEnd('[InPageEdit] 获取页面基础信息');
              console.warn('[InPageEdit] 获取页面基础信息失败');
              $('.ipe-editor.timestamp-' + timestamp).data('basetimestamp', now);
              queryDone(data);
            });

            /** 页面保护等级和编辑提示等 **/
            function queryDone(data) {
              var data = data;
              options.namespace = data.query.pages[options.pageId].ns; // 名字空间ID
              options.protection = data.query.pages[options.pageId]['protection'] || []; // 保护等级
              if (data.query.pages[options.pageId].hasOwnProperty('revisions')) {
                options.revision = data.query.pages[options.pageId]['revisions'][0]['revid']; // 版本号
              }

              // 使页面名标准化
              options.page = data.query.pages[options.pageId].title;
              $('.ipe-editor.timestamp-' + timestamp + ' .editPage').text(options.page);

              if (options.revision) {
                $('.ipe-editor.timestamp-' + timestamp + ' .diff-btn').attr('disabled', false).click(function () {
                  _analysis('quick_diff_edit');
                  var text = $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val();
                  var diffJson = {
                    fromrev: options.revision,
                    totext: text,
                    hideBtn: true,
                    pageName: options.page,
                    isPreview: true
                  }
                  if (options.section) {
                    diffJson.fromsection = options.section;
                  }
                  InPageEdit.quickDiff(diffJson);
                })
              }

              // 页面是否被保护
              if (options.protection.length > 0) {
                for (var i = 0; i < options.protection.length; i++) {
                  if (options.protection[i].type === 'edit') {
                    if (
                      (options.protection[i].level === 'autoconfirmed' && !_hasRight('autoconfirmed')) ||
                      (options.protection[i].level === 'sysop' && !_hasRight('editprotected')) ||
                      (config.wgNamespaceNumber === 8 && !_hasRight('editinterface'))
                    ) {
                      ssi_modal.notify('dialog', {
                        className: 'in-page-edit',
                        position: 'center bottom',
                        title: _msg('notify-no-right'),
                        content: _msg('editor-no-right'),
                        okBtn: {
                          label: _msg('ok'),
                          className: 'btn btn-primary',
                          method: function (e, modal) {
                            modal.close();
                          }
                        }
                      });
                      $('.ipe-editor.timestamp-' + timestamp + ' .save-btn').addClass('btn-danger');
                    }
                  }
                }
              }

              // 获取编辑提示
              var namespaceNoticePage = 'Editnotice-' + options.namespace,
                pageNoticePage = namespaceNoticePage + '-' +
                  options.page
                    .replace(/_/, ' ') // 将页面名里的 _ 转换为空格
                    .replace(config.wgFormattedNamespaces[options.namespace] + ':', ''); // 去掉名字空间

              new mw.Api().get({
                action: 'query',
                meta: 'allmessages',
                ammessages: namespaceNoticePage + '|' + pageNoticePage
              }).done(function (data) {
                var wikitextNs = data.query.allmessages[0]['*'] || '',
                  wikitextPage = data.query.allmessages[1]['*'] || '';
                if (wikitextNs === '' && wikitextPage === '') return; // 没有编辑提示
                // 将编辑提示解析为 html
                new mw.Api().post({
                  action: 'parse',
                  title: options.page,
                  contentmodel: 'wikitext',
                  preview: true,
                  text: wikitextPage + '\n' + wikitextNs
                }).done(function (data) {
                  var data = data;
                  options.editNotice = data.parse.text['*'];
                  var notice = $('.ipe-editor.timestamp-' + timestamp).data('editNotice') || '';
                  notice += '\n' + options.editNotice;
                  $('.ipe-editor.timestamp-' + timestamp).data('editNotice', notice);
                  $('.ipe-editor.timestamp-' + timestamp + ' .showEditNotice').show();
                });
              });

            }
          }
        },

        /* 确认是否取消 */
        beforeClose: function (modal) {
          if ($('.ipe-editor.timestamp-' + timestamp + ' .editArea').attr('data-modifiled') !== 'true') {
            close();
            return;
          } else if ($('.ipe-editor.timestamp-' + timestamp + ' .editArea').attr('data-confirmclose') === 'true') {
            closeNoReload();
            return;
          }
          ssi_modal.confirm({
            className: 'in-page-edit',
            center: true,
            content: _msg('editor-leave-confirm'),
            okBtn: {
              className: 'btn btn-danger',
              label: _msg('confirm')
            },
            cancelBtn: {
              className: 'btn btn-secondary',
              label: _msg('cancel')
            }
          },
            function (result) {
              if (result === true) {
                close();
              }
            });
          function close() {
            $(window).unbind('beforeunload');
            modal.options.keepContent = false;
            modal.options.beforeClose = '';
            modal.close();
            ssi_modal.notify('info', {
              className: 'in-page-edit',
              position: 'right top',
              title: _msg('cancel'),
              content: _msg('notify-no-change')
            });
          }
          function closeNoReload() {
            $(window).unbind('beforeunload');
            modal.options.keepContent = false;
            modal.options.beforeClose = '';
            modal.close();
          }
          return false;
        }
      });

      // 页面详情模块
      $('.ipe-editor.timestamp-' + timestamp + ' .detailBtnGroup .detailBtn').click(function () {
        _analysis('quick_edit_pagedetail');
        var $this = $(this),
          id = $this.attr('id'),
          content = $('<ul>');
        switch (id) {
          case 'showTemplates':
            var templates = options.pageDetail.parse.templates,
              templateName;
            for (var i = 0; i < templates.length; i++) {
              templateName = templates[i]['*'];
              $('<li>').append(
                $('<a>', { href: mw.util.getUrl(templateName), target: '_blank', text: templateName }),
                ' (',
                $('<a>', { href: 'javascript:;', text: _msg('quick-edit'), class: 'quickEditTemplate', 'data-template-name': templateName }),
                ')'
              ).appendTo(content);
            }
            ssi_modal.show({
              className: 'in-page-edit quick-edit-detail',
              sizeClass: 'dialog',
              title: _msg('editor-detail-title-templates'),
              content: content
            });
            break;
          case 'showImages':
            var images = options.pageDetail.parse.images,
              imageName;
            for (var i = 0; i < images.length; i++) {
              imageName = images[i];
              $('<li>').append(
                $('<a>', { href: mw.util.getUrl('File:' + imageName), target: '_balnk', text: imageName }),
                ' (',
                $('<a>', { href: 'javascript:;', class: 'quickViewImage', text: _msg('editor-detail-images-quickview'), 'data-image-name': imageName }),
                ' | ',
                $('<a>', { href: config.wgScript + '?title=Special:Upload&wpDestFile=' + imageName + '&wpForReUpload=1', target: '_balnk', text: _msg('editor-detail-images-upload') }),
                ')'
              ).appendTo(content);
            }
            ssi_modal.show({
              className: 'in-page-edit quick-edit-detail',
              sizeClass: 'dialog',
              title: _msg('editor-detail-title-images'),
              content: content
            });
            break;
        }
        $('.in-page-edit.quick-edit-detail .quickEditTemplate').click(function () {
          _analysis('quick_edit_pagedetail_edit_template');
          var $this = $(this);
          var page = $this.attr('data-template-name');
          InPageEdit.quickEdit({
            page: page
          });
        });
        $('.in-page-edit.quick-edit-detail .quickViewImage').click(function () {
          _analysis('quick_edit_pagedetail_view_image');
          var $this = $(this);
          var imageName = $this.attr('data-image-name');
          ssi_modal.show({
            className: 'in-page-edit quick-view-image',
            center: true,
            title: imageName.replace(/_/g, ' '),
            content: $('<center>', { id: 'imageLayer' }).append(
              $progress
            ),
            buttons: [{
              label: _msg('editor-detail-images-upload'),
              className: 'btn btn-primary',
              method: function (a, modal) { window.open(config.wgScript + '?title=Special:Upload&wpDestFile=' + imageName + '&wpForReUpload=1') }
            }, {
              label: _msg('close'),
              className: 'btn btn-secondary',
              method: function (a, modal) { modal.close() }
            }],
            onShow: function () {
              new mw.Api().get({
                action: 'query',
                format: 'json',
                prop: 'imageinfo',
                titles: 'File:' + imageName.replace(/file:/g, ''),
                iiprop: 'url'
              }).done(function (data) {
                $('.quick-view-image .ipe-progress').hide();
                $('.quick-view-image #imageLayer').append(
                  $('<img>', { src: data.query.pages['-1'].imageinfo[0].url, class: 'loading', style: 'max-width: 80%; max-height: 60vh' })
                );
                $('.quick-view-image #imageLayer img').load(function () {
                  $(this).removeClass('loading');
                });
              })
            }
          });
        });
      });

      // 发布编辑模块
      function postArticle(pValue, modal) {
        var pValue = pValue,
          modal = modal;
        _analysis('quick_edit_save');
        InPageEdit.progress(_msg('editor-title-saving'));
        options.jsonPost = {
          action: 'edit',
          basetimestamp: $('.ipe-editor.timestamp-' + timestamp).data('basetimestamp'),
          starttimestamp: now,
          text: pValue.text,
          title: pValue.page,
          minor: pValue.minor,
          summary: pValue.summary,
          errorformat: 'plaintext'
        }
        if (pValue.section !== undefined && pValue.section !== '' && pValue.section !== null) {
          options.jsonPost.section = pValue.section;
          delete options.jsonPost.basetimestamp;
        }

        new mw.Api().postWithToken('csrf', options.jsonPost).done(saveSuccess).fail(saveError);

        // 保存正常
        function saveSuccess(data, feedback, errorThrown) {
          if (data.edit.result === 'Success') {
            InPageEdit.progress(true);
            // 是否重载页面
            if ($('.ipe-editor.timestamp-' + timestamp + ' .reloadPage').prop('checked')) {
              var content;
              $(window).unbind('beforeunload');
              content = _msg('notify-save-success');
              setTimeout(function () {
                if (pValue.page === config.wgPageName) {
                  window.location = mw.util.getUrl(pValue.page) + options.jumpTo;
                  window.location.reload();
                } else {
                  window.location.reload();
                }
              }, 500);
            } else {
              console.info('[InPageEdit] 将不会重载页面!');
              content = _msg('notify-save-success-noreload');
              setTimeout(function () {
                InPageEdit.progress(false);
                $('.ipe-editor.timestamp-' + timestamp + ' .editArea').attr('data-confirmclose', 'true');
                modal.close();
              }, 1500);
            }

            ssi_modal.notify('success', {
              className: 'in-page-edit',
              position: 'right top',
              title: _msg('notify-success'),
              content: content
            });
          } else {
            saveError(data, feedback, errorThrown)
          }
        }

        // 保存失败
        function saveError(errorCode, feedback, errorThrown) {
          InPageEdit.progress(false);
          var data = errorThrown || errorCode; // 规范错误代码
          var errorCode,
            errorInfo,
            errorMore = '';
          if (data.errors !== undefined) {
            errorCode = data.errors[0].code;
            errorInfo = data.errors[0]['*'];
            errorMore = '';
          } else if (data.edit.result !== 'Success') {
            errorCode = data.edit.code || 'Unknown';
            errorInfo = data.edit.info || 'Reason unknown.';
            errorMore = data.edit.warning || '';
          } else {
            errorCode = 'unknown';
            errorInfo = 'Reason unknown.';
            errorMore = 'Please contact plug-in author or try again.'
          }
          ssi_modal.show({
            className: 'in-page-edit',
            sizeClass: 'dialog',
            center: true,
            title: _msg('editor-save-error'),
            content: errorInfo + '<hr style="clear: both" />' + errorMore
          });
          ssi_modal.notify('error', {
            className: 'in-page-edit',
            position: 'right top',
            closeAfter: {
              time: 15
            },
            title: _msg('notify-error'),
            content: _msg('editor-save-error') + ':<code>' + errorCode + '</code>'
          });

          console.error('[InPageEdit] Submit failed: \nCode: ' + errorCode);
          return;
        }
      }
    }

    /**
     * @module 查找替换模块
     * @param {element} contengut Textarea
     */
    InPageEdit.findAndReplace = function (contengut) {
      if (contengut === this.undefined) contengut = $('.in-page-edit.ipe-editor .editArea');
      var origin = contengut.val();

      ssi_modal.show({
        className: 'in-page-edit',
        sizeClass: 'dialog',
        center: true,
        outSideClose: false,
        // position: 'right bottom',
        title: _msg('fAndR-title'),
        content:
          $('<div>', { class: 'module far-module' }).append(
            $('<div>', { class: 'module_content', id: 'findfielddiv' }).append(
              $('<section>').append(
                $('<h4>', { text: _msg('fAndR-find-text') }),
                $('<textarea>', { id: 'find_this', style: 'margin: 0', rows: 4 }),
                $('<h4>', { text: _msg('fAndR-replace-text') }),
                $('<textarea>', { id: 'replace_with', style: 'margin: 0', rows: 4 })
              ),
              $('<section>', { style: 'padding: 7px 0' }).append(
                $('<label>').append(
                  $('<input>', { type: 'checkbox', id: 'globl', checked: '' }),
                  $('<span>', { text: _msg('fAndR-globl') })
                ),
                $br,
                $('<label>').append(
                  $('<input>', { type: 'checkbox', id: 'case_sen' }),
                  $('<span>', { text: _msg('fAndR-case-sen') })
                ),
                $br,
                $('<label>').append(
                  $('<input>', { type: 'checkbox', id: 'regex_search' }),
                  $('<span>', { text: _msg('fAndR-enable-regex') })
                ),
              )
            )
          ),
        buttons: [
          {
            label: _msg('fAndR-button-undo'),
            className: 'btn btn-danger',
            method: function (e, modal) {
              contengut.val(origin);
              ssi_modal.notify('info', {
                className: 'in-page-edit',
                title: _msg('notify-info'),
                content: _msg('notify-fAndR-undo')
              });
              // modal.close();
            }
          },
          {
            className: 'btn btn-primary',
            label: _msg('fAndR-button-replace'),
            method: function (a, modal) {
              /**
               * 查找替换主函数
               * 借鉴:https://dev.fandom.com/wiki/MediaWiki:FindAndReplace/code.js
               **/
              if ($('#find_this').val() === '') return;
              var searchfor = '',
                searchexp,
                $textarea = contengut,
                replacewith = $('#replace_with').val().replace(/\r/gi, ''),
                text = $textarea.val().replace(/\r/gi, ''),
                flagg = 'g',
                flagi = 'i',
                enableregex = 0;

              if ($('#globl').prop('checked') === false) {
                flagg = '';
              }
              if ($('#case_sen').prop('checked') === true) {
                flagi = '';
              }
              if ($('#regex_search').prop('checked') === true) {
                enableregex = 1;
              }
              var flags = flagg + flagi + 'm';
              if (enableregex === 1) {
                searchfor = $('#find_this').val();
              } else {
                searchfor = $('#find_this').val().replace(/\r/gi, '').replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
              }
              searchexp = new RegExp(searchfor, flags);
              var rcount = 0;
              var matched = text.match(searchexp);
              if (matched !== null) {
                rcount = matched.length;
              }
              text = text.replace(searchexp, replacewith);
              $textarea.val(text);
              ssi_modal.notify('success', {
                className: 'in-page-edit',
                title: _msg('notify-success'),
                content: _msg('notify-fAndR-done', rcount)
              });
              // modal.close();
            }
          }
        ]
      });
    }

    /** 快速重定向模块 **/
    InPageEdit.redirect = InPageEdit.quickRedirect = function (type = 'to') {
      mw.hook('InPageEdit.quickRedirect').fire();
      var text = '#REDIRECT [[:$1]]',
        question,
        target,
        json = {
          action: 'edit',
          minor: InPageEdit.preference.get('editMinor'),
          token: mw.user.tokens.get('editToken'),
          errorformat: 'plaintext'
        },
        summary;

      if (type === 'to') {
        json.title = config.wgPageName;
        question = _msg('redirect-question-to', '<b>' + config.wgPageName.replace(/_/g, ' ') + '</b>');
      } else if (type === 'from') {
        question = _msg('redirect-question-from', '<b>' + config.wgPageName.replace(/_/g, ' ') + '</b>');
        summary = _msg('redirect-summary') + ' → [[:' + config.wgPageName + ']]';
        json.text = text.replace('$1', config.wgPageName);
      } else {
        console.error('[InPageEdit] quickRedirect only accept "from" or "to"');
        return;
      }

      ssi_modal.show({
        outSideClose: false,
        className: 'in-page-edit quick-redirect',
        center: true,
        sizeClass: 'dialog',
        title: _msg('redirect-title'),
        content: $('<div>').append(
          $('<section>').append(
            $('<span>', { html: question }),
            $br,
            $('<input>', { id: 'redirect-page', style: 'width:96%' }).click(function () { $(this).css('box-shadow', '') }),
            $br,
            $('<label>', { for: 'redirect-reason', text: _msg('editSummary') }),
            $('<input>', { id: 'redirect-reason', style: 'width:96%' })
          ),
          $($progress).css('display', 'none')
        ),
        buttons: [{
          label: _msg('confirm'),
          className: 'btn btn-primary btn-single okBtn',
          method: function (a, modal) {
            target = $('.in-page-edit.quick-redirect #redirect-page').val();
            if (target === '' || target.toLowerCase().replace(/_/g, ' ') === config.wgPageName.toLowerCase().replace(/_/g, ' ')) {
              $('.in-page-edit.quick-redirect #redirect-page').css('box-shadow', '0 0 4px #f00');
              return;
            }

            _analysis('quick_redirect');

            if (type === 'to') {
              summary = _msg('redirect-summary') + ' → [[:' + target + ']]';
              json.text = text.replace('$1', target);
            } else if (type === 'from') {
              json.title = target;
            }
            if ($('.in-page-edit.quick-redirect #redirect-reason').val() !== '') {
              summary = summary + ' (' + $('.in-page-edit.quick-redirect #redirect-reason').val() + ')';
            }
            json.summary = summary;

            $('.in-page-edit.quick-redirect .ipe-progress').show();
            $('.in-page-edit.quick-redirect section').hide();
            $('.in-page-edit.quick-redirect .okBtn').attr('disabled', 'disabled');

            new mw.Api().post(json).done(function () {
              $('.in-page-edit.quick-redirect .ipe-progress').addClass('done');
              ssi_modal.notify('success', {
                className: 'in-page-edit',
                content: _msg('notify-redirect-success'),
                title: _msg('notify-success')
              });
              if (type === 'to') {
                window.location.reload();
              } else {
                $('.in-page-edit.quick-redirect .ipe-progress').addClass('done');
                setTimeout(function () { modal.close() }, 2000);
              }
            }).fail(function () {
              $('.in-page-edit.quick-redirect .ipe-progress').hide();
              $('.in-page-edit.quick-redirect section').show();
              $('.in-page-edit.quick-redirect .okBtn').attr('disabled', false);
              $('.in-page-edit.quick-redirect .ipe-progress').addClass('done');
              ssi_modal.notify('error', {
                className: 'in-page-edit',
                content: _msg('notify-redirect-error'),
                title: _msg('notify-error')
              });
            });
          }
        }
        ]
      });
    }

    /** 删除页面模块 **/
    InPageEdit.deletepage = InPageEdit.quickDelete = function (page) {
      mw.hook('InPageEdit.quickDelete').fire();
      var reason,
        page = page || config.wgPageName;

      ssi_modal.show({
        outSideClose: false,
        className: 'in-page-edit quick-delete',
        center: true,
        sizeClass: 'dialog',
        title: _msg('delete-title'),
        content: $('<div>').append(
          $('<section>', { id: 'InPageEditDeletepage' }).append(
            $('<span>', { html: _msg('delete-reason', '<b>' + page.replace(/\_/g, ' ') + '</b>') }),
            $br,
            $('<label>', { for: 'delete-reason', text: _msg('editSummary') }),
            $('<input>', { id: 'delete-reason', style: 'width:96%', onclick: "$(this).css('box-shadow', '')" })
          )
        ),
        beforeShow: function () {
          if (!_hasRight('delete')) {
            ssi_modal.dialog({
              title: _msg('notify-no-right'),
              content: _msg('delete-no-right'),
              className: 'in-page-edit quick-deletepage',
              center: true,
              okBtn: {
                className: 'btn btn-primary btn-single'
              }
            });
            return false;
          }
        },
        buttons: [
          {
            label: _msg('cancel'),
            className: 'btn btn-primary',
            method: function (e, modal) {
              modal.close();
            }
          }, {
            label: _msg('confirm'),
            className: 'btn btn-danger',
            method: function (e, modal) {
              reason = $('#InPageEditDeletepage #delete-reason').val();
              if (reason === '') {
                $('#InPageEditDeletepage #delete-reason').css('box-shadow', '0 0 4px #f00');
                return;
              }
              _analysis('quick_delete');

              ssi_modal.confirm({
                center: true,
                className: 'in-page-edit',
                title: _msg('delete-confirm-title'),
                content: _msg('delete-confirm-content'),
                okBtn: {
                  label: _msg('confirm'),
                  className: 'btn btn-danger'
                },
                cancelBtn: {
                  label: _msg('cancel'),
                  className: 'btn'
                }
              }, function (result) {
                if (result) {
                  reason = _msg('delete-title') + ' (' + reason + ')';
                  new mw.Api().postWithToken('csrf', {
                    action: 'delete',
                    title: page,
                    reason: reason,
                    format: 'json'
                  }).then(function (data) {
                    ssi_modal.notify('success', {
                      className: 'in-page-edit',
                      title: _msg('notify-success'),
                      content: _msg('notify-delete-success', page)
                    });
                  }).fail(function (errorCode, feedback, errorThrown) {
                    ssi_modal.notify('error', {
                      className: 'in-page-edit',
                      title: _msg('notify-error'),
                      content: _msg('notify-delete-error') + ': <br/><span style="font-size:amall">' + errorThrown.error['*'] + '(<code>' + errorThrown.error['code'] + '</code>)</span>'
                    });
                  });
                  modal.close();
                } else {
                  return false;
                }
              });
            }
          }
        ]
      });
    }

    /** 重命名模块 **/
    InPageEdit.renamepage = InPageEdit.quickRename = function (from, to) {
      mw.hook('InPageEdit.quickRename').fire();
      var from = from || config.wgPageName,
        to = to || '',
        reason,
        movetalk,
        movesubpages,
        noredirect,
        ignorewarnings;

      ssi_modal.show({
        outSideClose: false,
        className: 'in-page-edit quick-rename',
        center: true,
        sizeClass: 'dialog',
        title: _msg('rename-title'),
        content:
          $('<section>').append(
            $('<label>', { for: 'move-to', html: _msg('rename-moveTo', '<b>' + from.replace(/\_/g, ' ') + '</b>') }),
            $br,
            $('<input>', { id: 'move-to', style: 'width:96%', onclick: "$(this).css('box-shadow','')" }),
            $br,
            $('<label>', { for: 'move-reason', text: _msg('editSummary') }),
            $br,
            $('<input>', { id: 'move-reason', style: 'width:96%' }),
            $br,
            $('<label>').append(
              $('<input>', { type: 'checkbox', id: 'movetalk', checked: 'checked' }),
              $('<span>', { text: _msg('rename-movetalk') })
            ),
            $br,
            $('<label>').append(
              $('<input>', { type: 'checkbox', id: 'movesubpages', checked: 'checked' }),
              $('<span>', { text: _msg('rename-movesubpages') })
            ),
            $br,

            $('<label>').append(
              $('<input>', { type: 'checkbox', id: 'noredirect' }),
              $('<span>', { text: _msg('rename-noredirect') })
            ),
          ),
        buttons: [{
          label: _msg('cancel'),
          className: 'btn btn-secondary',
          method: function (a, modal) {
            modal.close();
          }
        }, {
          label: _msg('confirm'),
          className: 'btn btn-primary',
          method: function () {
            to = $('.in-page-edit.quick-rename #move-to').val();
            if (to === '' || to === config.wgPageName || to === config.wgPageName.replace(/\_/g, ' ')) {
              $('.in-page-edit.quick-rename #move-to').css('box-shadow', '0 0 4px #f00');
              return;
            }

            _analysis('quick_move');

            InPageEdit.progress(_msg('editor-title-saving'));
            movetalk = $('.in-page-edit.quick-rename #movetalk').prop('checked');
            movesubpages = $('.in-page-edit.quick-rename #movesubpages').prop('checked');
            noredirect = $('.in-page-edit.quick-rename #noredirect').prop('checked');
            reason = $('.in-page-edit.quick-rename #move-reason').val();

            if (reason === '') {
              reason = _msg('rename-summary') + ' → [[:' + to + ']]';
            } else {
              reason = _msg('rename-summary') + ' → [[:' + to + ']] (' + reason + ')';
            }
            new mw.Api().postWithToken('csrf', {
              action: 'move',
              from: from,
              to: to,
              reason: reason,
              movetalk: movetalk,
              movesubpages: movesubpages,
              noredirect: noredirect
            }).done(function () {
              InPageEdit.progress(true);
              ssi_modal.notify('success', {
                className: 'in-page-edit',
                content: _msg('notify-rename-success'),
                title: _msg('notify-success')
              });
              location.href = config.wgArticlePath.replace('$1', to);
            }).fail(function (errorCode, feedback, errorThrown) {
              InPageEdit.progress(false);
              ssi_modal.notify('error', {
                className: 'in-page-edit',
                content: _msg('notify-rename-error') + ': ' + errorThrown.error.info + '<code>' + errorThrown.error.code + '</code>',
                title: _msg('notify-error')
              });
              if (errorThrown.error.code === 'articleexists') {
                ssi_modal.dialog({
                  className: 'in-page-edit',
                  title: _msg('rename-articleexists-title'),
                  center: true,
                  content: _msg('rename-articleexists'),
                  okBtn: {
                    label: _msg('ok'),
                    className: 'btn btn-primary only-btn'
                  }
                });
              }
            });
          }
        }],
        beforeShow: function () {
          if (!_hasRight('move')) {
            ssi_modal.dialog({
              title: _msg('notify-no-right'),
              content: _msg('rename-no-right'),
              className: 'in-page-edit quick-deletepage',
              center: true,
              okBtn: {
                className: 'btn btn-primary btn-single'
              }
            });
            return false;
          }
        }
      });
    }

    /**
     * @module 个人设置模块
     */
    InPageEdit.preference = {
      /**
       * @name 预设值
       * @return {object}
       */
      "default": {
        doNotCollectMyInfo: false,
        doNotShowLocalWarn: false,
        editMinor: false,
        editSummary: _msg('preference-summary-default'),
        lockToolBox: false,
        redLinkQuickEdit: true,
        outSideClose: true,
        watchList: Boolean(mw.user.options.get('watchdefault'))
      },
      /**
       * @name 获取设置 
       * @description 合并保存在用户页的设置以及localStorage的设置,有容错机制
       * @param {string} setting 返回相应的设置,为空时返回全部设置
       * @return {object|string}
       */
      get: function (setting) {
        var setting = setting || undefined;
        var local = localStorage.getItem('InPageEditPreference') || '{}';
        try {
          var local = JSON.parse(local);
        } catch (e) {
          var local = {};
        }
        if (typeof InPageEdit.myPreference === 'object') {
          local = $.extend({}, local, InPageEdit.myPreference);
        }
        var json = $.extend({}, InPageEdit.preference.default, local);
        if (typeof (setting) === 'string' && setting !== '') {
          return json.hasOwnProperty(setting) ? json[setting] : null;
        } else {
          return json;
        }
      },
      /**
       * @name 保存设置
       * @param {Object|string} settingKey
       * @param {any} settingValue
       * @example 可以这样 InPageEdit.preference.set({ key: 'value' }) 也可以 InPageEdit.preference.set('key', 'value')
       */
      set: function (settingKey = {}, settingValue = undefined) {
        var options = {};
        if (typeof settingKey === 'string' && settingValue !== undefined) {
          options[settingKey] = settingValue;
        } else if (typeof settingKey === 'object') {
          options = settingKey;
        } else {
          return;
        }
        options = $.extend({}, InPageEdit.preference.get(), options);
        options = JSON.stringify(options);
        localStorage.setItem('InPageEditPreference', options);
      },
      /**
       * @name 用户图形界面
       * @description 打开可视化设置窗口
       */
      modal: function () {
        // 防止多开设置页面
        if ($('#ipe-preference-form').length > 0) return;

        mw.hook('InPageEdit.preference').fire();
        InPageEdit.preference.set();
        var local = InPageEdit.preference.get();
        _analysis('plugin_setting');

        ssi_modal.show({
          outSideClose: false,
          title: _msg('preference-title') + ' - ' + InPageEdit.version,
          content:
            $('<section>', { id: 'ipe-preference-form', class: 'ipe-preference-form' }).append(
              $('<h4>', { text: _msg('preference-editor-label') }),
              $('<label>').append(
                $('<input>', { id: 'outSideClose', type: 'checkbox' }).prop('checked', local.outSideClose),
                $('<span>', { text: _msg('preference-outSideClose') })
              ),
              $br,
              $('<label>').append(
                $('<input>', { id: 'editMinor', type: 'checkbox' }).prop('checked', local.editMinor),
                $('<span>', { text: _msg('preference-setMinor') })
              ),
              $br,
              $('<h4>', { text: _msg('preference-summary-label') }),
              $('<label>', { for: 'editSummary', style: 'padding-left: 0; font-size: small', html: _msg('preference-editSummary') }),
              $br,
              $('<input>', { id: 'editSummary', style: 'width: 96%', value: local.editSummary, placeholder: 'Edit via InPageEdit, yeah~' }),
              $('<h4>', { text: _msg('preference-analysis-label') }),
              $('<span>', { style: 'font-size: small; line-height: 0.9em', html: _msg('preference-analysis-view', '<a href="' + InPageEdit.api.analysisUrl + '" target="_blank">' + InPageEdit.api.analysisUrl + '</a>') }),
              $('<h4>', { text: _msg('preference-about-label') }),
              $('<button>', { class: 'btn btn-secondary', onclick: "InPageEdit.about()", text: _msg('preference-aboutAndHelp') }),
              $('<button>', { class: 'btn btn-secondary', style: 'margin-left: 1em;', onclick: "InPageEdit.versionInfo()", text: _msg('preference-updatelog') }),
              $('<a>', { href: 'https://ipe.miraheze.org/wiki/', target: '_blank' }).append(
                $('<button>', { class: 'btn btn-secondary', text: _msg('preference-translate'), style: 'margin-left: 1em;' })
              ),
              $('<a>', { href: 'https://discord.gg/VUVAh8w', target: '_blank' }).append(
                $('<button>', { class: 'btn btn-secondary', text: _msg('preference-discord'), style: 'margin-left: 1em;' })
              ),
              $hr,
              $('<strong>', { style: 'font-size: small; line-height: 0.9em', text: _msg('preference-savelocal-label') }),
              $br,
              $('<span>', { style: 'font-size: small; line-height: 0.9em', text: _msg('preference-savelocal') }).append(
                $('<a>', { href: 'javascript:;', id: 'ipeSaveLocalShow', text: _msg('preference-savelocal-btn') }).click(function () {
                  // 永久保存(本地用户页)
                  ssi_modal.dialog({
                    className: 'in-page-edit',
                    center: true,
                    title: _msg('preference-savelocal-popup-title'),
                    content: '<section id="ipeSaveLocal">' + _msg('preference-savelocal-popup') + '<br/><textarea style="font-size: 12px; resize: none; width: 100%; height: 10em;" readonly></textarea><br/>' + _msg('preference-savelocal-popup-notice') + '</section>',
                    okBtn: {
                      className: 'btn btn-primary btn-single',
                      label: _msg('ok')
                    }
                  });
                  $('#ipeSaveLocal textarea').val('/** InPageEdit preference **/\nwindow.InPageEdit = window.InPageEdit || {};\nInPageEdit.myPreference = ' + JSON.stringify($('#ipe-preference-form').data(), null, 2));
                })
              )
            ),
          sizeClass: 'dialog',
          className: 'in-page-edit ipe-preference',
          center: true,
          buttons: [{
            label: _msg('preference-reset'),
            className: 'btn btn-danger',
            method: function (a, modal) {
              ssi_modal.confirm({
                title: _msg('preference-reset-confirm-title'),
                content: _msg('preference-reset-confirm'),
                className: 'in-page-edit',
                center: true,
                okBtn: {
                  label: _msg('ok'),
                  className: 'btn btn-danger'
                },
                cancelBtn: {
                  label: _msg('cancel'),
                  className: 'btn'
                }
              }, (res) => {
                if (res) {
                  InPageEdit.preference.set(InPageEdit.preference.default);
                  modal.close();
                } else {
                  return false;
                }
              });
            }
          }, {
            label: _msg('preference-save'),
            className: 'btn btn-primary',
            method: function (a, modal) {
              InPageEdit.preference.set($('#ipe-preference-form').data());
              modal.close();
            }
          }
          ],
          onShow: function () {
            function setData() {
              if (this.type === 'checkbox') {
                $('#ipe-preference-form').data(this.id, this.checked);
              } else if (this.type === 'text') {
                $('#ipe-preference-form').data(this.id, this.value);
              }
            }
            $('#ipe-preference-form input').each(setData).change(setData);

            if (typeof (InPageEdit.myPreference) !== 'undefined') {
              $('#ipe-preference-form input, .ipe-preference .ssi-modalBtn').attr({ 'disabled': 'disabled' });
              $('#ipe-preference-form').prepend(
                $('<p>', { class: 'has-local-warn', style: 'padding-left: 8px; border-left: 6px solid orange; font-size: small;', html: _msg('preference-savelocal-popup-haslocal', '<a href="' + mw.util.getUrl('Special:Mypage/common.js') + '">' + _msg('preference-savelocal-popup-yourjspage') + '</a>') })
              );
            }
          }
        });
      }
    }

    /**
     * @module quickDiff 快速页面差异模块
     * @param {Object} param standard MediaWiki API params
     */
    InPageEdit.quickDiff = function (param) {
      mw.hook('InPageEdit.quickDiff').fire();
      _analysis('quick_diff');
      if ($('[href*="mediawiki.diff.styles"]').length < 1) {
        mw.loader.load(mw.util.wikiScript('load') + '?modules=mediawiki.legacy.shared|mediawiki.diff.styles&only=styles', 'text/css');
      }
      var $modalTitle,
        $diffArea,
        $loading;
      if ($('.quick-diff').length > 0) {
        console.info('[InPageEdit] Quick diff 正在加载新内容');
        $modalTitle = $('.quick-diff .pageName');
        $diffArea = $('.quick-diff .diffArea');
        $loading = $('.quick-diff .ipe-progress');
        $modalTitle.text(_msg('diff-loading'));
        $diffArea.hide();
        $('.quick-diff').appendTo('body');
      } else {
        $modalTitle = $('<span>', { class: 'pageName', text: _msg('diff-loading') });
        $diffArea = $('<div>', { class: 'diffArea', style: 'display: none' });
        $loading = $($progress);

        ssi_modal.show({
          className: 'in-page-edit quick-diff',
          sizeClass: 'large',
          fixedHeight: true,
          fitScreen: true,
          title: $modalTitle,
          content: $('<div>').append($loading, $diffArea),
          buttons: [{
            label: _msg('diff-button-todiffpage'),
            className: 'btn btn-secondary toDiffPage',
            method: function () {
              // ...
            }
          }]
        });
      }
      $loading.show().css('margin-top', $loading.parent().height() / 2);
      $('.quick-diff .toDiffPage').unbind();
      param.action = 'compare';
      param.prop = 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size';
      param.format = 'json';
      if (param.totext) {
        param.topst = true;
      } else if (param.fromtext) {
        param.frompst = true;
      }
      new mw.Api().post(param).then(function (data) {
        var diffTable = data.compare['*'];
        $loading.hide();
        if (param.pageName === undefined) {
          var toTitle = data.compare.totitle;
        } else {
          var toTitle = param.pageName;
        }
        var userlink = function (user) {
          return '<a class="diff-user" href="' + mw.util.getUrl('User:' + user) + '">' + user + '</a> (<a href="' + mw.util.getUrl('User_talk:' + user) + '">' + _msg('diff-usertalk') + '</a> | <a href="' + mw.util.getUrl('Special:Contributions/' + user) + '">' + _msg('diff-usercontrib') + '</a> | <a href="' + mw.util.getUrl('Special:Block/' + user) + '">' + _msg('diff-userblock') + '</a>)';
        }
        $modalTitle.html(_msg('diff-title') + ': <u>' + toTitle + '</u>');
        $diffArea.show().html('').append(
          $('<table>', { class: 'diff difftable' }).append(
            $('<colgroup>').append(
              $('<col>', { class: 'diff-marker' }),
              $('<col>', { class: 'diff-content' }),
              $('<col>', { class: 'diff-marker' }),
              $('<col>', { class: 'diff-content' })
            ),
            $('<tbody>').append(
              $('<tr>').append(
                $('<td>', { colspan: 2, class: 'diff-otitle' }).append(
                  $('<a>', { href: config.wgScript + '?oldid=' + data.compare.fromrevid, text: data.compare.fromtitle }),
                  ' (',
                  $('<span>', { class: 'diff-version', text: _msg('diff-version') + data.compare.fromrevid }),
                  ') (',
                  $('<a>', { class: 'editLink', href: config.wgScript + '?action=edit&title=' + data.compare.fromtitle + '&oldid=' + data.compare.fromrevid }),
                  ')',
                  $br,
                  userlink(data.compare.fromuser),
                  $br,
                  ' (',
                  $('<span>', { class: 'diff-comment', text: data.compare.fromparsedcomment }),
                  ') ',
                  $br,
                  $('<a>', { class: 'prevVersion ipe-analysis-quick_diff_modalclick', href: 'javascript:void(0);', text: '←' + _msg('diff-prev') }).click(() => {
                    InPageEdit.quickDiff({
                      fromrev: data.compare.fromrevid,
                      torelative: 'prev'
                    });
                  })
                ),
                $('<td>', { colspan: 2, class: 'diff-ntitle' }).append(
                  $('<a>', { href: config.wgScript + '?oldid=' + data.compare.torevid, text: data.compare.totitle }),
                  ' (',
                  $('<span>', { class: 'diff-version', text: _msg('diff-version') + data.compare.torevid }),
                  ') (',
                  $('<a>', { class: 'editLink', href: config.wgScript + '?action=edit&title=' + data.compare.totitle + '&oldid=' + data.compare.torevid }),
                  ')',
                  $br,
                  userlink(data.compare.touser),
                  $br,
                  ' (',
                  $('<span>', { class: 'diff-comment', text: data.compare.toparsedcomment }),
                  ') ',
                  $br,
                  $('<a>', { class: 'nextVersion ipe-analysis-quick_diff_modalclick', href: 'javascript:void(0);', text: _msg('diff-nextv') + '→' }).click(() => {
                    _analysis('quick_diff_modalclick');
                    InPageEdit.quickDiff({
                      fromrev: data.compare.torevid,
                      torelative: 'next'
                    });
                  })
                )
              ),
              diffTable,
              $('<tr>', { class: 'diffSize', style: 'text-align: center' }).append(
                $('<td>', { colspan: '2', text: data.compare.fromsize + _msg('diff-bytes') }),
                $('<td>', { colspan: '2', text: data.compare.tosize + _msg('diff-bytes') })
              )
            )
          )
        );
        $('.quick-diff button.toDiffPage').click(function () {
          location.href = config.wgScript + '?oldid=' + data.compare.fromrevid + '&diff=' + data.compare.torevid;
        });
        InPageEdit.articleLink($('.quick-diff .editLink'));
        if (param.isPreview === true) {
          $('.quick-diff button.toDiffPage').hide();
          $diffArea.find('.diff-otitle').html('<b>' + _msg('diff-title-original-content') + '</b>');
          $diffArea.find('.diff-ntitle').html('<b>' + _msg('diff-title-your-content') + '</b>');
        }
        if (data.compare.fromsize === undefined || data.compare.tosize === undefined) {
          $diffArea.find('.diffSize').hide();
        }
        // 无上一版本或下一版本
        if (data.compare.fromrevid === undefined && param.isPreview !== true) {
          $diffArea.find('.diff-otitle').html('<span class="noPrevVerson">' + data.warnings.compare['*'] + '</span>');
        } else if (data.compare.torevid === undefined && param.isPreview !== true) {
          $diffArea.find('.diff-ntitle').html('<span class="noNextVerson">' + data.warnings.compare['*'] + '</span>');
        }
        // GitHub@issue#5 修复被隐藏版本的问题
        if (data.compare.fromtexthidden !== undefined) {
          $diffArea.find('.diff-otitle .diff-version').addClass('diff-hidden-history');
        }
        if (data.compare.totexthidden !== undefined) {
          $diffArea.find('.diff-ntitle .diff-version').addClass('diff-hidden-history');
        }
        if (data.compare.fromuserhidden !== undefined) {
          $diffArea.find('.diff-otitle .diff-user').addClass('diff-hidden-history');
        }
        if (data.compare.touserhidden !== undefined) {
          $diffArea.find('.diff-ntitle .diff-user').addClass('diff-hidden-history');
        }
        if (data.compare.fromcommenthidden !== undefined) {
          $diffArea.find('.diff-comment').addClass('diff-hidden-history');
        }
        if (data.compare.tocommenthidden !== undefined) {
          $diffArea.find('.diff-ntitle .diff-comment').addClass('diff-hidden-history');
        }
        if (data.hasOwnProperty('error')) {
          console.warn('[InPageEdit] 快速差异获取时系统告知出现问题');
          $diffArea.html(_msg('diff-error') + ': ' + data.error.info + '(<code>' + data.error.code + '</code>)');
        }
      }).fail(function (errorCode, feedback, errorThrown) {
        console.warn('[InPageEdit] 快速差异获取失败');
        $loading.hide();
        $diffArea.show().html(_msg('diff-error') + ': ' + errorThrown.error['info'] + '(<code>' + errorThrown.error['code'] + '</code>)');
      });
    }
    // 加载预设的快速最近更改模块
    InPageEdit.loadQuickDiff = function () {
      // 最近更改
      function addLink(origin) {
        $('.mw-changeslist-groupdiff, .mw-changeslist-diff, .mw-changeslist-diff-cur, .mw-history-histlinks a').unbind('click', ipeDiffLink);
        var ipeDiffLink = $('.mw-changeslist-groupdiff, .mw-changeslist-diff, .mw-changeslist-diff-cur, .mw-history-histlinks a').click(function (e) {
          e.preventDefault();
          _analysis('quick_diff_recentchanges');
          var $this = $(this),
            href = $this.attr('href'),
            diff = mw.util.getParamValue('diff', href),
            curid = mw.util.getParamValue('curid', href),
            oldid = mw.util.getParamValue('oldid', href);
          if (diff === '0') {
            InPageEdit.quickDiff({ fromrev: oldid, toid: curid });
          } else if (diff === 'prev' || diff === 'next' || diff === 'cur') {
            InPageEdit.quickDiff({ fromrev: oldid, torelative: diff });
          } else {
            InPageEdit.quickDiff({ fromrev: oldid, torev: diff });
          }
        });
      }
      if ($('.mw-rcfilters-enabled').length > 0) {
        setInterval(addLink, 500);
        $('.mw-rcfilters-enabled').addClass('ipe-continuous-active');
      } else {
        addLink();
      }
      // 查看历史页面的比较按钮与快速编辑
      if (config.wgAction === 'history') {
        $('.historysubmit.mw-history-compareselectedversions-button').after(
          $('<button>').text(_msg('quick-diff')).click(function (e) {
            e.preventDefault();
            _analysis('quick_diff_history_page');
            var before = $('.selected.before').attr('data-mw-revid'),
              after = $('.selected.after').attr('data-mw-revid');
            InPageEdit.quickDiff({ fromrev: after, torev: before });
          })
        );
        $('[data-mw-revid]').each(function () {
          var $this = $(this),
            oldid = $this.attr('data-mw-revid');
          $this.find('.mw-history-undo').after(
            $('<span>').html(' | <a class="in-page-edit-article-link" href="javascript:void(0);" onclick="InPageEdit.quickEdit({page:mw.config.get(\'wgPageName\'),revision:' + oldid + '});">' + _msg('quick-edit') + '</a>')
          );
        });
      }
    }

    /**
     * @module 获取段落编辑以及编辑链接
     * @param {Element} element parent element to find edit links
     */
    InPageEdit.articleLink = function (element) {
      if (element === undefined) {
        if (InPageEdit.preference.get('redLinkQuickEdit') === true) {
          element = $('#mw-content-text a');
        } else {
          element = $('#mw-content-text a:not(.new)');
        }
      }
      element.each(function (i) {
        if ($(this).attr('href') === undefined)
          return;
        var url = $(this).attr('href'),
          title = mw.util.getParamValue('title', url),
          section = mw.util.getParamValue('section', url),
          revision = mw.util.getParamValue('oldid', url);

        // 不是本地编辑链接
        if (url.split('/')['2'] !== location.href.split('/')['2'] && url.substr(0, 1) !== '/')
          return;

        // 不是 index.php?title=FOO 形式的url
        if (title === null) {
          var splitStr = config.wgArticlePath.replace('$1', '');
          if (splitStr === '/') {
            splitStr = config.wgServer.substring(config.wgServer.length - 4) + '/';
          }
          title = url.split(splitStr).pop().split('?')['0'];
        }

        if (mw.util.getParamValue('action', url) === 'edit' && title !== undefined) {
          $(this).after(
            $('<span>', {
              'class': 'in-page-edit-article-link-group'
            }).append(
              $('<a>', {
                href: 'javascript:void(0)',
                class: 'in-page-edit-article-link',
                text: _msg('quick-edit')
              }).click(function () {
                var options = {};
                options.page = title;
                if (revision !== null) {
                  options.revision = revision;
                } else if (section !== null) {
                  options.section = section;
                }
                if (!config.wgIsArticle) options.reload = false;
                InPageEdit.quickEdit(options);
              })
            )
          );
        }
      });
    }

    /**
     * @module 快速预览文章页
     * @param params {Object} 
     */
    InPageEdit.quickPreview = function (params, modalSize = 'large', center = false) {
      var defaultOptions = {
        action: 'parse',
        preview: true,
        disableeditsection: true,
        prop: 'text',
        preview: true,
        format: 'json'
      }
      var options = $.extend({}, defaultOptions, params);
      mw.hook('InPageEdit.quickPreview').fire();
      var timestamp = new Date().getTime();
      console.time('[InPageEdit] Request preview');
      ssi_modal.show({
        sizeClass: new RegExp(/dialog|small|smallToMedium|medium|mediumToLarge|large|full|auto/).test(modalSize) ? modalSize : 'large',
        center: Boolean(center),
        className: 'in-page-edit previewbox',
        title: _msg('preview-title'),
        content: $('<section>').append(
          $progress,
          $('<div>', { class: 'InPageEditPreview', 'data-timestamp': timestamp, style: 'display:none', text: _msg('preview-placeholder') })
        ),
        fixedHeight: true,
        fitScreen: true,
        buttons: [{ label: '', className: 'hideThisBtn' }],
        onShow: function (modal) {
          $('.previewbox .ipe-progress').css('margin-top', $('.previewbox .ipe-progress').parent().height() / 2);
          $('.previewbox .hideThisBtn').hide();
          new mw.Api().post(options).then(function (data) {
            console.timeEnd('[InPageEdit] Request preview');
            var content = data.parse.text['*'];
            $('.previewbox .ipe-progress').hide(150);
            $('.InPageEditPreview[data-timestamp="' + timestamp + '"]').fadeIn(500).html(content);
          }).fail(function () {
            console.timeEnd('[InPageEdit] Request preview');
            console.warn('[InPageEdit] 预览失败');
            $('.previewbox .ipe-progress').hide(150);
            $('.InPageEditPreview[data-timestamp="' + timestamp + '"]').fadeIn(500).html(_msg('preview-error'));
          });
        }
      });
    }

    /**
     * @module 载入中模块
     * @param title
     *  - √Boolean× true: Mark top progress box as done; false: Close top progress box
     *  - "String" Show new progress box with title @default 'Loading...'
     */
    InPageEdit.progress = function (title) {
      if (title === true) {
        $('.in-page-edit.loadingbox .ssi-modalTitle').html(_msg('done'));
        $('.in-page-edit.loadingbox .ipe-progress').addClass('done');
      } else if (title === false) {
        if ($('.in-page-edit.loadingbox').length > 0) {
          $('.in-page-edit.loadingbox').appendTo('body');
          ssi_modal.close();
        }
      } else {
        if ($('.in-page-edit.loadingbox').length > 0) return;
        if (typeof title === 'undefined') {
          title = 'Loading...'
        }
        ssi_modal.show({
          title: title,
          content: $progress,
          className: 'in-page-edit loadingbox',
          center: true,
          sizeClass: 'dialog',
          closeIcon: false,
          outSideClose: false
        });
      }
    }

    /**
     * @module 版本信息模块
     * @description Show Update Logs Modal box
     */
    InPageEdit.versionInfo = function () {
      // 显示模态框
      ssi_modal.show({
        className: 'in-page-edit update-logs-modal',
        title: _msg('updatelog-title') + ' - <span id="yourVersion">' + InPageEdit.version + '</span>',
        content: $('<section>').append(
          $('<iframe>', { style: 'margin: 0;padding: 0;width: 100%;height: 80vh;border: 0;', src: 'https://dragon-fish.github.io/inpageedit-v2/update-logs/?iframe=1' })
        ),
        buttons: [{
          label: 'GitHub',
          className: 'btn btn-secondary',
          method: function () {
            window.open('https://github.com/Dragon-Fish/InPageEdit-v2');
          }
        }, {
          label: _msg('updatelog-about'),
          className: 'btn btn-secondary',
          method: function () {
            window.open('https://dragon-fish.github.io/inpageedit-v2/');
          }
        }, {
          label: _msg('close'),
          className: 'btn btn-primary',
          method: function (a, modal) {
            modal.close();
          }
        }]
      });
    };

    /**
     * @module 关于插件模块
     * @description Show "What is" modal box of IPE2
     */
    InPageEdit.about = function () {
      ssi_modal.show({
        title: '关于InPageEdit',
        className: 'in-page-edit in-page-edit-about',
        // sizeClass: 'dialog',
        content: $('<section>').append(
          $('<iframe>', { style: 'margin: 0;padding: 0;width: 100%;height: 80vh;border: 0;', src: 'https://dragon-fish.github.io/inpageedit-v2/about/?iframe=1' })
        )
      });
    }

    /**
     * @module 特别通知
     */
    InPageEdit.specialNotice = function () {
      ssi_modal.notify('dialog', {
        className: 'in-page-edit ipe-special-notice',
        title: _msg('version-notice-title'),
        content: _msg('version-notice'),
        okBtn: {
          label: _msg('updatelog-dismiss'),
          className: 'btn btn-primary'
        }
      }, function (e, modal) {
        localStorage.setItem('InPageEditNoticeId', _msg('noticeid'));
        modal.close();
      });
    }

    /**
     * @module 获取版本更新提示
     */
    !(function () {
      var version = InPageEdit.version;
      // 版本更新
      if (localStorage.getItem('InPageEditVersion') !== version) {
        ssi_modal.notify('', {
          title: _msg('updatelog-update-success-title'),
          content: _msg('updatelog-update-success', version),
          className: 'in-page-edit',
          buttons: [{
            className: 'btn btn-primary',
            label: _msg('updatelog-button-versioninfo'),
            method: function (a, modal) {
              localStorage.InPageEditVersion = version;
              InPageEdit.versionInfo();
              modal.close();
            }
          }],
          closeAfter: {
            time: 30,
            resetOnHover: true
          },
          onClose: function () {
            ssi_modal.notify('', {
              className: 'in-page-edit',
              content: _msg('updatelog-after-close', '<a href="' + InPageEdit.api.updatelogsUrl + '" to="_blank">' + InPageEdit.api.updatelogsUrl + '</a>').replace('$2', '<a href="https://github.com/Dragon-Fish/InPageEdit-v2">' + _msg('updatelog-file-issue') + '</a>'),
              closeAfter: {
                time: 10
              },
              buttons: [{
                className: 'btn btn-primary',
                label: _msg('ok'),
                method: function (a, modal) {
                  modal.close();
                }
              }]
            });
            localStorage.InPageEditVersion = version;
          }
        });
      }
      if (localStorage.getItem('InPageEditNoticeId') !== _msg('noticeid')) {
        InPageEdit.specialNotice();
      }
    }());

    /**
     * @description 获取用户权限信息
     */
    !(function () {
      mw.user.getRights().then(function (rights) {
        console.info('[InPageEdit] 成功获取用户权限信息');
        mw.config.set('wgUserRights', rights);
      }).fail(function () {
        console.warn('[InPageEdit] 警告:无法获取用户权限信息');
        mw.config.set('wgUserRights', []);
      });
      if (mw.user.getName() !== null) {
        new mw.Api().get({
          action: 'query',
          list: 'users',
          usprop: 'blockinfo',
          ususers: mw.user.getName()
        }).then(function (data) {
          if (data.query.users[0].hasOwnProperty('blockid')) {
            mw.config.set('wgUserIsBlocked', true);
          } else {
            mw.config.set('wgUserIsBlocked', false);
          }
        });
      }
    }());

    /** 
     * @module 是否拥有权限
     * @param {String} right
     * @return {Boolean}
     */
    const _hasRight = function (right) {
      if (config.wgUserIsBlocked === true) {
        return false;
      }
      if (mw.config.get('wgUserRights').indexOf(right) > -1) {
        return true;
      } else {
        return false;
      }
    };

    /**
     * @module 提交统计信息模块
     * @description Internal module
     */
    const _analysis = function (functionID) {
      if (InPageEdit.doNotCollectMyInfo === true) {
        // console.info('[InPageEdit] 我们已不再收集您使用插件的信息。');
        // return;
      }
      var submitdata = {
        'action': 'submit',
        'url': config.wgServer + config.wgArticlePath.replace('$1', ''),
        'sitename': config.wgSiteName,
        'username': config.wgUserName,
        'function': functionID
      }
      $.ajax({
        url: InPageEdit.api.analysis,
        data: submitdata,
        type: 'post',
        dataType: 'json'
      }).done(function (data) {
        console.log('[InPageEdit] Analysis response\nStatus: ' + data.status + '\nMessage: ' + data.msg);
      });
    }

    /**
     * @description 页面载入完成,自动加载某些模块
     */
    !(function () {
      // 初始化设定
      InPageEdit.preference.set();
      // 快速页面差异模块
      InPageEdit.loadQuickDiff();
      // 加载段落编辑模块
      InPageEdit.articleLink();
    }());

    /**
     * @module Toolbox模块
     */
    mw.hook('InPageEdit').add(function () {
      // 检测是否为文章页
      if (!config.wgIsArticle || $('#ipe-edit-toolbox').length > 0) {
        console.warn('[InPageEdit] 未载入 Toolbox');
        return;
      }

      /** IPE工具盒 **/
      $('<div>', { id: 'ipe-edit-toolbox' }).append(
        $('<ul>', { class: 'btn-group group1' }).append(
          $('<li>', { class: 'btn-tip-group' }).append(
            $('<div>', { class: 'btn-tip', text: _msg('quick-edit') }),
            $('<button>', { id: 'edit-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-pencil"></i>' }).click(function () {
              InPageEdit.quickEdit({
                page: config.wgPageName,
                revision: config.wgRevisionId
              });
            })
          ),
          $('<li>', { class: 'btn-tip-group' }).append(
            $('<div>', { class: 'btn-tip', text: _msg('redirect-from') }),
            $('<button>', { id: 'redirectfrom-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-sign-in"></i>' }).click(function () {
              InPageEdit.quickRedirect('from');
            })
          ),
          $('<li>', { class: 'btn-tip-group' }).append(
            $('<div>', { class: 'btn-tip', text: _msg('redirect-to') }),
            $('<button>', { id: 'redirectto-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-sign-out"></i>' }).click(function () {
              InPageEdit.quickRedirect('to');
            })
          )
        ),
        $('<ul>', { class: 'btn-group group2' }).append(
          $('<div>', { style: 'display: flex;' }).append(
            $('<li>', { class: 'btn-tip-group' }).append(
              $('<div>', { class: 'btn-tip', text: _msg('quick-delete') }),
              $('<button>', { id: 'deletepage-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-trash"></i>' }).click(function () {
                InPageEdit.quickDelete();
              })
            ),
            $('<li>', { class: 'btn-tip-group' }).append(
              $('<div>', { class: 'btn-tip', text: _msg('quick-rename') }),
              $('<button>', { id: 'renamepage-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-italic"></i>' }).click(function () {
                InPageEdit.quickRename();
              })
            ),
            $('<li>', { class: 'btn-tip-group' }).append(
              $('<div>', { class: 'btn-tip', text: _msg('ipe-preference') }),
              $('<button>', { id: 'preference-btn', class: 'ipe-toolbox-btn', html: '<i class="fa fa-gear"></i>' }).click(function () {
                InPageEdit.preference.modal();
              })
            )
          )
        ),
        $('<button>', { class: 'ipe-toolbox-btn', id: 'toolbox-toggle', html: '<i class="fa fa-plus"></i>' })
      ).appendTo('body');

      $('#ipe-edit-toolbox .btn-group button').click(function () {
        _analysis('tool_box')
      });

      // 设置开关等
      var toolBoxInner = $('#ipe-edit-toolbox #toolbox-toggle, #ipe-edit-toolbox .btn-group');
      $('#ipe-edit-toolbox #toolbox-toggle').click(function () {
        if ($(this).hasClass('opened') && !$(this).hasClass('click')) {
          InPageEdit.preference.set({ lockToolBox: true });
          toolBoxInner.addClass('click');
        } else if ($(this).hasClass('click')) {
          InPageEdit.preference.set({ lockToolBox: false });
          toolBoxInner.removeClass('click');
        } else {
          InPageEdit.preference.set({ lockToolBox: true });
          toolBoxInner.addClass('click opened');
        }
      });
      // 如果锁定过工具盒,就自动展开
      if (InPageEdit.preference.get('lockToolBox') === true) {
        toolBoxInner.addClass('click opened');
      }
      $('#ipe-edit-toolbox').hover(function () {
        toolBoxInner.addClass('hover opened');
      }, function () {
        toolBoxInner.removeClass('hover');
        if (!$('#ipe-edit-toolbox #toolbox-toggle').hasClass('click')) {
          toolBoxInner.removeClass('opened');
        }
      });
      mw.hook('InPageEdit.toolbox').fire();
    });

    // Init End
  }

  // 花里胡哨的加载提示
  mw.hook('InPageEdit').fire();
  console.info('    ____      ____                   ______    ___ __              _    _____ \n   /  _/___  / __ \\____ _____ ____  / ____/___/ (_) /_            | |  / /__ \\\n   / // __ \\/ /_/ / __ `/ __ `/ _ \\/ __/ / __  / / __/  ______    | | / /__/ /\n _/ // / / / ____/ /_/ / /_/ /  __/ /___/ /_/ / / /_   /_____/    | |/ // __/ \n/___/_/ /_/_/    \\__,_/\\__, /\\___/_____/\\__,_/_/\\__/              |___//____/ \n                      /____/');

  return InPageEdit;

}));