Site Notice

hello, world

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

From Project-EPB Commons
([InPageEdit] 没有编辑摘要)
m (// Via InPageEdit-v2)
 
(170 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',
* New discuss notify
+
  dataType: 'script',
* 近期当前页面有新讨论的提醒
+
}).then(
* Author: 机智的小鱼君(User:Xiaoyujun)
+
  function () {
**/
+
    console.log('[InPageEdit] Using local dev')
$(function () {
+
  },
  if (!mw.config.get('wgIsArticle'))
+
  function () {
     return;
+
    console.log('[InPageEdit] Local dev not found')
  var articleId = mw.config.get('wgArticleId');
+
     mw.loader.load('https://unpkg.com/mediawiki-inpageedit')
   new mw.Api().get({
+
   }
     action: 'query',
+
)
     prop: 'info',
+
 
     pageids: articleId,
+
/** InPageEdit Preferences */
     inprop: 'talkid',
+
;(window.InPageEdit = window.InPageEdit || {}).myPreference = {
     format: 'json'
+
  editMinor: false,
   }).done(function (query1) {
+
  editSummary: '$section$oldid // Via InPageEdit-v2',
     var talkId = query1.query.pages[articleId].talkid;
+
  redLinkQuickEdit: true,
     console.info('This page\'s talk page id: '+talkId);
+
  outSideClose: false,
    new mw.Api().get({
+
  watchList: true,
      action: 'query',
+
  plugins: [
      prop: 'info',
+
     'toolbox.js',
       pageids: talkId,
+
     'code-mirror/script.js',
      // inprop: 'timestamp',
+
     'color-preview.js',
      format: 'json'
+
     'edit-any-page.js',
    }).done(function (query2) {
+
     'wiki-editor.js',
      var timestamp = query2.query.pages[talkId].touched;
+
   ],
      console.info('Talk page\'s talk page recently edit at: '+new Date(timestamp));
+
}
       var timestamp = new Date(timestamp).getTime(),
+
 
          now = new Date().getTime(),
+
mw.hook('InPageEdit').add(function (ctx) {
          talkpage = query2.query.pages[talkId].title,
+
  if (mw.config.get('wgIsArticle')) {
          talklink = mw.config.get('wgArticlePath').replace('$1', talkpage);
+
     var _msg = ctx._msg
       console.info('Talk page title is: '+talkpage+'\nTalk page link: '+talklink);
+
     $('#ca-edit, #ca-viewsource').after(
       if (now - timestamp < 86400000) { // 一天之内有新讨论
+
      $('<li>', {
         mw.notify($('<section class="has-new-discuss"><p style="font-size:18px">请检查最新讨论</p><p>在近一天内,有针对当前页面新的讨论,请<a href="javascript:;" class="has-new-discuss-link">点击这里</a>确认</p></section>'), {
+
        id: 'ca-quick-edit',
          autoHide: false
+
        class: 'collapsible',
        });
+
       }).append(
        setTimeout(function () {
+
        $('<span>').append(
          $('.has-new-discuss-link').attr('href', talklink);
+
          $('<a>', {
        }, 500);
+
            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 快编'