Site Notice

hello, world

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

From Project-EPB Commons
([InPageEdit] 没有编辑摘要)
m (// Via InPageEdit-v2)
 
(197 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.load('https://common.wjghj.cn/js/InPageEdit-v2');
+
$.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'),
 +
            })
 +
          })
 +
        )
 +
      )
 +
    )
 +
  }
 +
})
  
function getRandomArrayElements(arr, count) {
+
if (mw.config.get('wgIsArticle')) {
     var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
+
  $('#ca-history').append(
     while (i-- > min) {
+
     $('<a>', {
        index = Math.floor((i + 1) * Math.random());
+
      href: 'javascript:void(0);',
         temp = shuffled[index];
+
      style: 'margin-left:2px;top: -1.2em;position: relative;font-size: 8px;',
        shuffled[index] = shuffled[i];
+
     })
         shuffled[i] = temp;
+
      .append($('<span>').html('最后更改'))
    }
+
      .on('click', function () {
    return shuffled.slice(min);
+
         InPageEdit.quickDiff({
 +
          fromtitle: mw.config.get('wgPageName'),
 +
          torelative: 'prev',
 +
         })
 +
      })
 +
  )
 
}
 
}
  
function randomBg() {
+
$('#firstHeading').append(
   new mw.Api().get({
+
   '<span style="font-size:12px;float:right">wgRevisionId: ' +
    action: 'parse',
+
    mw.config.get('wgRevisionId') +
     page: 'MediaWiki:Custom-RandomBackground/List',
+
     ' | wgArticleId: ' +
     prop: 'wikitext',
+
     mw.config.get('wgArticleId') +
     format: 'json'
+
     '</span>'
  }).done(function(data) {
+
)
    var wikitext = data.parse.wikitext['*'],
+
 
    json = JSON.parse(wikitext),
+
/** Wikiplus */
    item = getRandomArrayElements(json.list,1),
+
mw.loader.load(
    // item = json.list[0],
+
  'https://wikiplus.oss-cn-shanghai.aliyuncs.com/Main.development.js'
    img = item.img,
+
)
    des = item.des;
+
// 修改 IPE 文字防止抑郁
+
InPageEdit.i18n = InPageEdit.i18n || {}
    $('#firstHeading').after('<br>arr: '+item+'<br>image url: url(' + img + ')<br>Description: '+des);
+
InPageEdit.i18n['zh-hans'] = InPageEdit.i18n['zh-hans'] || {}
+
InPageEdit.i18n['zh-hans']['quick-edit'] = 'IPE 快编'
  });
 
}
 
$(function(){
 
randomBg();
 
$('#firstHeading').click(randomBg)
 
});
 

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 快编'