Site Notice

hello, world

Difference between revisions of "User:机智的小鱼君/common.js"

From Project-EPB Commons
([InPageEdit] 没有编辑摘要)
m (// Via InPageEdit-v2)
 
(143 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.load('https://common.wjghj.cn/js/InPageEdit-advance');
+
$.ajax({
function quickDiff(param) {
+
  url: 'http://127.0.0.1:1005/InPageEdit.js',
   if ($('[href*="mediawiki.diff.styles"]').length < 1) {
+
  dataType: 'script',
     mw.loader.load(mw.config.get('wgScriptPath') + '/load.php?modules=mediawiki.legacy.shared|mediawiki.diff.styles&only=styles', 'text/css');
+
}).then(
 +
  function () {
 +
    console.log('[InPageEdit] Using local dev')
 +
   },
 +
  function () {
 +
    console.log('[InPageEdit] Local dev not found')
 +
     mw.loader.load('https://unpkg.com/mediawiki-inpageedit')
 
   }
 
   }
  var date = new Date(),
+
)
  timestamp = date.getTime(); // 缓存时间戳
+
 
   ssi_modal.show({
+
/** InPageEdit Preferences */
    className: 'in-page-edit quick-diff timestamp-'+timestamp,
+
;(window.InPageEdit = window.InPageEdit || {}).myPreference = {
    sizeClass: 'large',
+
   editMinor: false,
    fixedHeight: true,
+
  editSummary: '$section$oldid // Via InPageEdit-v2',
    fitScreen: true,
+
  redLinkQuickEdit: true,
     title: '<span class="pageName">正在加载差异……</span>',
+
  outSideClose: false,
     content: '<section class="diffArea"><div class="ipe-progress" style="width:100%"><div class="progress-bar"></div></div></section>'
+
  watchList: true,
  });
+
  plugins: [
  $('.in-page-edit.quick-diff .ipe-progress').css('margin-top', $('.in-page-edit.quick-diff .ipe-progress').parent().parent().height()/2);
+
     'toolbox.js',
  if (param === undefined) param = {};
+
     'code-mirror/script.js',
  param.action = 'compare';
+
    'color-preview.js',
  param.prop = 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size';
+
    'edit-any-page.js',
  param.format = 'json';
+
     'wiki-editor.js',
  new mw.Api().post(param).then(function(data){
+
   ],
    var diffTable = data.compare['*'];
 
     $('.diffArea').html('<table class="diffTable diff diff-contentalign-left">' + diffTable + '</table>');
 
  }).fail(function(){
 
    $('.diffArea').html('Fail');
 
   });
 
 
}
 
}
 +
 +
mw.hook('InPageEdit').add(function (ctx) {
 +
  if (mw.config.get('wgIsArticle')) {
 +
    var _msg = ctx._msg
 +
    $('#ca-edit, #ca-viewsource').after(
 +
      $('<li>', {
 +
        id: 'ca-quick-edit',
 +
        class: 'collapsible',
 +
      }).append(
 +
        $('<span>').append(
 +
          $('<a>', {
 +
            href: 'javascript:void(0)',
 +
            text: _msg('quick-edit'),
 +
          }).on('click', function () {
 +
            InPageEdit.edit({
 +
              page: mw.config.get('wgPageName'),
 +
              revision: mw.config.get('wgRevisionId'),
 +
            })
 +
          })
 +
        )
 +
      )
 +
    )
 +
  }
 +
})
 +
 +
if (mw.config.get('wgIsArticle')) {
 +
  $('#ca-history').append(
 +
    $('<a>', {
 +
      href: 'javascript:void(0);',
 +
      style: 'margin-left:2px;top: -1.2em;position: relative;font-size: 8px;',
 +
    })
 +
      .append($('<span>').html('最后更改'))
 +
      .on('click', function () {
 +
        InPageEdit.quickDiff({
 +
          fromtitle: mw.config.get('wgPageName'),
 +
          torelative: 'prev',
 +
        })
 +
      })
 +
  )
 +
}
 +
 +
$('#firstHeading').append(
 +
  '<span style="font-size:12px;float:right">wgRevisionId: ' +
 +
    mw.config.get('wgRevisionId') +
 +
    ' | wgArticleId: ' +
 +
    mw.config.get('wgArticleId') +
 +
    '</span>'
 +
)
 +
 +
/** Wikiplus */
 +
mw.loader.load(
 +
  'https://wikiplus.oss-cn-shanghai.aliyuncs.com/Main.development.js'
 +
)
 +
// 修改 IPE 文字防止抑郁
 +
InPageEdit.i18n = InPageEdit.i18n || {}
 +
InPageEdit.i18n['zh-hans'] = InPageEdit.i18n['zh-hans'] || {}
 +
InPageEdit.i18n['zh-hans']['quick-edit'] = 'IPE 快编'

Latest revision as of 04:35, 10 April 2022

$.ajax({
  url: 'http://127.0.0.1:1005/InPageEdit.js',
  dataType: 'script',
}).then(
  function () {
    console.log('[InPageEdit] Using local dev')
  },
  function () {
    console.log('[InPageEdit] Local dev not found')
    mw.loader.load('https://unpkg.com/mediawiki-inpageedit')
  }
)

/** InPageEdit Preferences */
;(window.InPageEdit = window.InPageEdit || {}).myPreference = {
  editMinor: false,
  editSummary: '$section$oldid // Via InPageEdit-v2',
  redLinkQuickEdit: true,
  outSideClose: false,
  watchList: true,
  plugins: [
    'toolbox.js',
    'code-mirror/script.js',
    'color-preview.js',
    'edit-any-page.js',
    'wiki-editor.js',
  ],
}

mw.hook('InPageEdit').add(function (ctx) {
  if (mw.config.get('wgIsArticle')) {
    var _msg = ctx._msg
    $('#ca-edit, #ca-viewsource').after(
      $('<li>', {
        id: 'ca-quick-edit',
        class: 'collapsible',
      }).append(
        $('<span>').append(
          $('<a>', {
            href: 'javascript:void(0)',
            text: _msg('quick-edit'),
          }).on('click', function () {
            InPageEdit.edit({
              page: mw.config.get('wgPageName'),
              revision: mw.config.get('wgRevisionId'),
            })
          })
        )
      )
    )
  }
})

if (mw.config.get('wgIsArticle')) {
  $('#ca-history').append(
    $('<a>', {
      href: 'javascript:void(0);',
      style: 'margin-left:2px;top: -1.2em;position: relative;font-size: 8px;',
    })
      .append($('<span>').html('最后更改'))
      .on('click', function () {
        InPageEdit.quickDiff({
          fromtitle: mw.config.get('wgPageName'),
          torelative: 'prev',
        })
      })
  )
}

$('#firstHeading').append(
  '<span style="font-size:12px;float:right">wgRevisionId: ' +
    mw.config.get('wgRevisionId') +
    ' | wgArticleId: ' +
    mw.config.get('wgArticleId') +
    '</span>'
)

/** Wikiplus */
mw.loader.load(
  'https://wikiplus.oss-cn-shanghai.aliyuncs.com/Main.development.js'
)
// 修改 IPE 文字防止抑郁
InPageEdit.i18n = InPageEdit.i18n || {}
InPageEdit.i18n['zh-hans'] = InPageEdit.i18n['zh-hans'] || {}
InPageEdit.i18n['zh-hans']['quick-edit'] = 'IPE 快编'