Site Notice

hello, world

MediaWiki:Js-InPageEdit-canary.js

From Project-EPB Commons
Revision as of 00:41, 28 March 2020 by 机智的小鱼君 (talk | contribs) ([InPageEdit] 没有编辑摘要)

Invoke this: https://common.wjghj.cn/js/{{#replace:{{#replace:Js-InPageEdit-canary.js|Js-|}}|.js|}}

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/**
 *『Wjghj Project Static』
 * This _JavaScript_ code is from https://common.wjghj.cn
 * GNU GENERAL PUBLIC LICENSE 3.0
 *
 * MediaWiki JS Plugin: In Page Edit Canary Edition
 * Version: InPageEdit-canary
 * Author: 机智的小鱼君
 * Url:
 ** https://github.com/Dragon-Fish/InPageEdit-v2
 ** https://common.wjghj.cn/wiki/InPageEdit-v2
 * Logs:
 ** https://common.wjghj.cn/wiki/InPageEdit-v2/version-info
 **/

(function () {
  'use strict';
  if (typeof InPageEdit !== 'undefined') throw '[InPageEdit] 已经有一个IPE插件在执行了';

  // 创建全局函数
  window.InPageEdit = {};

  /** 导入模态框插件 **/
  mw.loader.load('https://cdn.bootcss.com/ssi-modal/1.0.27/js/ssi-modal.min.js');
  $('title').after('<link id="ssi-modal-style" rel="stylesheet" href="https://cdn.bootcss.com/ssi-modal/1.0.27/styles/ssi-modal.min.css"/>');

  /** 获取版本信息 **/
  mw.loader.load('https://common.wjghj.cn/js/InPageEdit-v2.js/version-info-canary');

  /** 样式表 **/
  // 皮肤
  $('link#ssi-modal-style').after('<link rel="stylesheet" href="https://common.wjghj.cn/css/InPageEdit-v2"/>');
  // Material icons
  mw.loader.load('https://cdn.bootcss.com/material-design-icons/3.0.1/iconfont/material-icons.min.css', 'text/css');

  /*** BOT FLAG ***/
  /** InPageEdit主框架 **/
  function int(i18n) {
    // i18n
    mw.config.set('InPageEdit_i18n', i18n);
    function msg(i) {
      var i18n = mw.config.get('InPageEdit_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]
      } else {
        final = '&lt;' + i + '&gt;';
      }
      if (i18n.hasOwnProperty(lang)) {
        if (i18n[lang].hasOwnProperty(i)) {
          final = i18n[lang][i];
        }
      }
      return final;
    };

    /** 快速编辑模块 **/
    InPageEdit.edit = function (option) {
      // 变量
      if (option === undefined)
        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' });
      InPageEdit.analysis({ type: 'dateCount' });

      if (editPage === undefined) editPage = mw.config.get('wgPageName');
      if (editRevision !== undefined && editRevision !== '' && editRevision !== mw.config.get('wgCurRevisionId')) {
        ssi_modal.notify('warning', {
          className: 'in-page-edit',
          content: msg('notify-editing-history'),
          title: msg('notify-info')
        });
        delete jsonGet.page;
        jsonGet.oldid = editRevision;
        titleRevision = '<span style="font-size:small;">(' + msg('editor-title-editRevision') + ':' + editRevision + ')</span>';
        summaryRevision = '(' + msg('editor-summary-rivision') + '[[Special:Diff/' + editRevision + ']])';
      } else {
        if (editSection !== undefined && editSection !== '' && editSection !== null) {
          jsonGet.section = editSection;
          titleSection = msg('editor-title-editSection').replace('$1', editSection);
        }
      }
      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;
      ssi_modal.show({
        title: msg('editor-title-editing') + ': <u class="editPage">' + editPage + '</u>' + titleSection + titleRevision,
        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>',
        outSideClose: outSideClose,
        className: 'in-page-edit ipe-editor timestamp-' + timestamp,
        sizeClass: 'large',

        /* 按钮 */
        buttons: [{
          label: msg('editor-button-save'),
          className: 'btn btn-primary leftBtn editForm',
          method: function () {
            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 = 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'
            });
          }
        }, {
          label: msg('editor-button-diff'),
          className: 'btn btn-secondary leftBtn editForm',
          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();
          }
        }
        ],

        /* 开始执行后续程序 */
        onShow: function (modal) {
          // 绑定事件,在尝试离开页面时提示
          $(window).bind('beforeunload', function () {
            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');
          $('.ipe-editor.timestamp-' + timestamp + ' .editArea').css('height', $(window).height() / 3 * 2 - 100);
          $('.ipe-editor.timestamp-' + timestamp + ' .editOptionsLabel').prependTo('.ipe-editor.timestamp-' + timestamp + ' .ssi-buttons');
          $('.leftBtn').appendTo('.ssi-leftButtons');
          // 获取页面保护等级+最后编辑时间戳
          console.time('[InPageEdit] 获取页面基础信息');
          new mw.Api().get(jsonGetInfo).then(function (data) {
            if (data && data.query && data.query.pages) {
              var info = data.query.pages;
              for (var key in info) {
                if (key !== '-1') {
                  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 () {
            console.timeEnd('[InPageEdit] 获取页面基础信息');
            console.warn('[InPageEdit] 获取页面基础信息失败');
          });
          // 获取页面代码
          new mw.Api().get(jsonGet).then(function (data) {
            console.timeEnd('[InPageEdit] 获取页面源代码');
            if (data.error === undefined) {
              editText = data.parse.wikitext['*']
            } else {
              console.timeEnd('[InPageEdit] 获取页面源代码');
              editText = '<!-- 警告:无法获取页面内容 -->';
              console.error('[InPageEdit]警告:无法获取页面内容');
            }
            $('.ipe-editor.timestamp-' + timestamp + ' .ipe-progress').hide();
            $('.ipe-editor.timestamp-' + timestamp + ' .editForm').fadeIn(500);
            $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val(editText + '\n');
          }).fail(function (data) {
            console.timeEnd('[InPageEdit] 获取页面源代码');
            editText = '<!-- 警告:无法获取页面内容 -->';
            console.error('[InPageEdit]警告:无法获取页面内容');
            $('.ipe-editor.timestamp-' + timestamp + ' .ipe-progress').hide();
            $('.ipe-editor.timestamp-' + timestamp + ' .editForm').fadeIn(500);
            $('.ipe-editor.timestamp-' + timestamp + ' .editArea').val(editText + '\n');
          });
          // 设定状态
          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',
                      center: true,
                      title: msg('editor-title-editNotice'),
                      content: editNotice
                    });
                  })
                  .html('<i class="material-icons">info</i> ' + msg('editor-has-editNotice'))
              );
            });
          });
        },

        /* 确认是否取消 */
        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) {
        InPageEdit.analysis({ type: 'functionCount', function: '保存编辑' });
        InPageEdit.progress(msg('editor-title-saving'));
        jsonPost = {
          action: 'edit',
          basetimestamp: $('.ipe-editor.timestamp-' + timestamp).attr('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) {
          jsonPost.section = pValue.section;
          delete jsonPost.basetimestamp;
        }
        // Debug
        console.info('%c[InPageEdit] Submitting with params: ', 'color:#fe20d1');
        console.table(jsonPost);
        new mw.Api().postWithToken('csrf', jsonPost).then(function (data) {
          InPageEdit.progress(true);
          $(window).unbind('beforeunload');
          ssi_modal.notify('success', {
            className: 'in-page-edit',
            position: 'right top',
            title: msg('notify-success'),
            content: msg('notify-save-success')
          });
          setTimeout(function () {
            if (pValue.page === mw.config.get('wgPageName')) {
              window.location = mw.config.get('wgArticlePath').replace('$1', pValue.page);
            } else {
              window.location.reload();
            }
          }, 500);
        }).fail(function (errorCode, feedback, errorThrown) {
          InPageEdit.progress(false);
          ssi_modal.notify('error', {
            className: 'in-page-edit',
            position: 'right top',
            closeAfter: {
              time: 15
            },
            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]['*']);
        });
      }

    };

    /** 快速重定向模块 **/
    InPageEdit.redirect = function (type) {
      var json = {
        action: 'edit',
        minor: JSON.parse(localStorage.getItem('InPageEditPreference')).editMinor,
        token: mw.user.tokens.get('editToken'),
        errorformat: 'plaintext'
      },
        summary = msg('redirect-summary') + ' → [[:$1]]',
        text = '#REDIRECT [[:$1]]',
        question,
        target;
      switch (type) {
        case 'to':
          json.title = mw.config.get('wgPageName');
          question = msg('redirect-question-to').replace('$1', '<b>' + mw.config.get('wgPageName') + '</b>');
          break;
        case 'from':
          question = msg('redirect-question-from').replace('$1', '<b>' + mw.config.get('wgPageName') + '</b>');
          json.text = text.replace('$1', mw.config.get('wgPageName'));
          json.summary = summary.replace('$1', mw.config.get('wgPageName'));
          break;
      }
      ssi_modal.show({
        outSideClose: false,
        className: 'in-page-edit quick-redirect',
        center: true,
        sizeClass: 'dialog',
        title: msg('redirect-title'),
        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>',
        buttons: [{
          label: msg('confirm'),
          className: 'btn btn-primary btn-single okBtn',
          method: function (a, modal) {
            InPageEdit.analysis({ type: 'functionCount', function: '快速重定向' });
            InPageEdit.analysis({ type: 'dateCount' });
            InPageEdit.analysis({ type: 'siteCount' });
            var input = $('#redirect-page').val();
            if (input === '' || input === mw.config.get('wgPageName')) {
              $('#redirect-page').css('box-shadow', '0 0 4px red');
            } else {
              $('.in-page-edit.quick-redirect .ipe-progress').show();
              $('.in-page-edit.quick-redirect section').hide();
              $('.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')
                });
              });
            }
          }
        }
        ]
      });
    };

    /** 查找替换模块 **/
    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',
        // backdrop: false,
        outSideClose: false,
        position: 'right bottom',
        title: msg('fAndR-title'),
        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>',
        buttons: [
          {
            label: msg('fAndR-button-undo'),
            className: 'btn btn-danger',
            method: function (e, modal) {
              contengut.val(origin);
              ssi_modal.notify('info', {
                title: msg('fAndR-undo-title'),
                content: msg('notify-fAndR-undo')
              });
              // modal.close();
            }
          },
          {
            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) {
                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('info', {
                title: msg('notify-fAndR-done-title'),
                content: msg('notify-fAndR-done').replace('$1', rcount)
              });
              // modal.close();
            }
          }
        ]
      });
    };

    /** 删除页面模块 **/
    InPageEdit.deletepage = function (page) {
      InPageEdit.analysis({ type: 'functionCount', function: '快速删除' });
      var reasonType,
        reason = msg('delete-reason-default');
      if (page === this.undefined) page = mw.config.get('wgPageName');

      ssi_modal.show({
        outSideClose: false,
        className: 'in-page-edit quick-delete',
        center: true,
        sizeClass: 'dialog',
        title: msg('delete-title'),
        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>',
        beforeShow: function () {
          if (!InPageEdit.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) {
              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) {
                  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;
                }
              });
            }
          }
        ]
      });
    };

    /** 重命名模块 **/
    InPageEdit.renamepage = function () {
      var from = mw.config.get('wgPageName'),
        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 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>',
        buttons: [{
          label: msg('cancel'),
          className: 'btn btn-secondary',
          method: function (a, modal) {
            modal.close();
          }
        }, {
          label: msg('confirm'),
          className: 'btn btn-primary',
          method: function () {
            InPageEdit.analysis({ type: 'functionCount', function: '快速重命名' });
            InPageEdit.analysis({ type: 'dateCount' });
            InPageEdit.analysis({ type: 'siteCount' });
            InPageEdit.progress('正在和土豆交涉……');
            movetalk = $('#movetalk').prop('checked');
            movesubpages = $('#movesubpages').prop('checked');
            noredirect = $('#noredirect').prop('checked');
            to = $('#move-to').val();
            if ($('#move-reason').val() === '') {
              reason = msg('rename-summary') + ' → [[:' + to + ']]';
            } else {
              reason = msg('rename-summary') + ' → [[:' + to + ']] (Reason: ' + $('#move-reason').val() + ')';
            }
            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 = 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({
                  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 (!InPageEdit.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;
          }
        }
      });
    };

    /** 个人设置模块 **/
    InPageEdit.preference = function () {
      InPageEdit.analysis({ type: 'functionCount', function: '插件设置' });
      var settings = JSON.parse(localStorage.getItem('InPageEditPreference')),
        minor = settings.editMinor,
        summary = settings.editSummary,
        outSideClose = settings.outSideClose;

      ssi_modal.show({
        outSideClose: false,
        title: msg('preference-title') + ' - ' + InPageEdit.version,
        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>',
        sizeClass: 'dialog',
        className: 'in-page-edit ipe-preference',
        center: true,
        buttons: [{
          label: msg('preference-reset'),
          className: 'btn btn-danger',
          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({
          className: 'in-page-edit',
          center: true,
          title: msg('preference-savelocal-popup-title'),
          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>',
          okBtn: {
            className: 'btn btn-primary btn-single'
          }
        });
        $('#ipeSaveLocal input').val('window.MyInPageEditPreference = ' + JSON.stringify({
          outSideClose: $('#InPageEditSettingBox #ipeSetoutSideClose').prop('checked'),
          editMinor: $('#InPageEditSettingBox #ipeSetMinor').prop('checked'),
          editSummary: $('#InPageEditSettingBox #ipeSetSummary').val()
        }) + ';');
      });
      if (outSideClose) {
        $('#InPageEditSettingBox #ipeSetoutSideClose').prop('checked', true);
      }
      if (minor) {
        $('#InPageEditSettingBox #ipeSetMinor').prop('checked', true);
      }

      if (typeof (MyInPageEditPreference) !== 'undefined') {
        $('.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'
          }
        });
      }
    };

    /** 快速页面差异模块 **/
    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) {
        console.info('[InPageEdit] Quick diff 正在加载新内容');
        $('.in-page-edit.quick-diff .diffArea').hide().html(msg('diff-loading'));
        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);
      $('.quick-diff button.toDiffPage').unbind();
      param.action = 'compare';
      param.prop = 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size';
      param.format = 'json';
      new mw.Api().post(param).then(function (data) {
        var diffTable = data.compare['*'];
        $('.in-page-edit.quick-diff .ipe-progress').hide();
        if (param.pageName === undefined) {
          var toTitle = data.compare.totitle;
        } else {
          var toTitle = param.pageName;
        }
        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);
      });
    };
    // 加载预设的快速最近更改模块
    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();
          InPageEdit.analysis({ type: 'functionCount', function: '快速差异RC' });
          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 (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) {
      if (element === undefined)
        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 = mw.config.get('wgArticlePath').replace('$1', '');
          if (splitStr === '/') {
            splitStr = mw.config.get('wgServer').substring(mw.config.get('wgServer').length - 4) + '/';
          }
          title = url.split(splitStr).pop().split('?')['0'];
        }

        if (mw.util.getParamValue('action', url) === 'edit' && title !== undefined && section !== 'new') {
          $(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 () {
                  if (revision !== null) {
                    InPageEdit.edit({
                      page: title,
                      revision: revision
                    });
                  } else {
                    InPageEdit.edit({
                      page: title,
                      section: section
                    });
                  }
                })));
        }
      });
    };

    /** 快速预览文章页 **/
    InPageEdit.quickPreview = function (params) {
      var timestamp = new Date().getTime();
      console.time('[InPageEdit] Request preview');
      ssi_modal.show({
        sizeClass: 'large',
        className: 'in-page-edit previewbox',
        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>',
        title: msg('preview-title'),
        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(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) {
      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: '<div class="ipe-progress" style="width:100%"><div class="ipe-progress-bar"></div></div>',
          className: 'in-page-edit loadingbox',
          center: true,
          sizeClass: 'dialog',
          closeIcon: false,
          outSideClose: false
        });
      }
    };

    /** 提交统计信息模块 **/
    InPageEdit.analysis = function (params) {
      var type = params.type;
      switch (type) {
        case 'siteCount':
          $.ajax({
            url: 'https://doc.wjghj.cn/InPageEditAnalysis/site/log.php',
            data: {
              'sitename': mw.config.get('wgSiteName')
            },
            dataType: 'json'
          });
          break;
        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 (d < 10) d = '0' + d;
          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');
    if (user === null) {
      console.warn('[InPageEdit] 警告:用户未登录');
      mw.config.set('wgUserRights', '');
      return;
    }
    new mw.Api().get({
      action: 'query',
      list: 'users',
      usprop: 'rights',
      ususers: user
    }).done(function (data) {
      console.info('[InPageEdit] 成功获取用户权限信息');
      mw.config.set('wgUserRights', data.query.users[0]['rights']);
    }).fail(function () {
      console.warn('[InPageEdit] 警告:无法获取用户权限信息');
      mw.config.set('wgUserRights', '');
    });

    InPageEdit.hasRight = function (right) {
      if (mw.config.get('wgUserRights').indexOf(right) > -1) {
        return true;
      } else {
        return false;
      }
    };

    /** 页面载入完成,初始化 **/
    (function () {
      /** 额外的模块 **/
      // 快速页面差异模块
      InPageEdit.loadQuickDiff();

      /** Toolbox模块 **/
      // 检测是否为文章页
      if (mw.config.get('wgIsArticle') === false) {
        console.warn('%c[InPageEdit] 不是文章页面,未载入工具盒。', 'color:orange;font-size:1.2em;font-weight:bold');
        return;
      }

      // 读取设定
      if (localStorage.getItem('InPageEditPreference') === null) {
        // 没有保存任何设置
        var ipePreference = {};
        ipePreference.outSideClose = true;
        ipePreference.editMinor = false;
        ipePreference.editSummary = msg('preference-summary-default');
        localStorage.setItem('InPageEditPreference', JSON.stringify(ipePreference));
      }

      // ipe工具盒
      $('body').append(
        '<div id="ipe-edit-toolbox">' +

        // group1 上方的一列按钮
        '<ul class="btn-group group1">' +
        '<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>' +
        '<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 左边的一排按钮
        '<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                      /____/');
    }());
  }

  /** 
   * 多语言环境初始化/真正开始初始化
   **/
  (function () {
    var i18nTimeout = localStorage.getItem('InPageEditI18nTimeout'),
      i18nCache = localStorage.getItem('InPageEditI18n'),
      date = new Date(),
      time = date.getTime();

    if (i18nCache === null || i18nTimeout === null || time > i18nTimeout) {
      // i18n文件不存在/超过缓存时间
      $.ajax({
        url: 'https://common.wjghj.cn/api.php',
        data: {
          page: 'MediaWiki:InPageEdit-v2/i18n.json',
          action: 'parse',
          prop: 'wikitext',
          format: 'json'
        },
        dataType: 'jsonp',
        success: function (data) {
          var i18nMsg = JSON.parse(data.parse.wikitext['*']);
          localStorage.setItem('InPageEditI18n', data.parse.wikitext['*']);
          localStorage.setItem('InPageEditI18nTimeout', time + 12 * 60 * 60 * 1000);
          int(i18nMsg);
        }
      });
    } else {
      // 缓存文件存在/未超过缓存时间
      var i18nMsg = JSON.parse(i18nCache);
      int(i18nMsg);  // 执行主模块
    }
  }());

}());