2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

User:机智的小鱼君/common.js

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox/Safari:按住“Shift”的同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
  • Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
  • Internet Explorer:按住“Ctrl”的同时单击“刷新”,或按“Ctrl-F5”
  • Opera:在“工具→首选项”中清除缓存
如果您已登录但该页面出现未登录状态,请尝试在地址栏的地址最后添加代码?_=1来访问最新页面。
添加代码后的本页地址如下:-{R|https://moegirl.icu/User:%E6%9C%BA%E6%99%BA%E7%9A%84%E5%B0%8F%E9%B1%BC%E5%90%9B/common.js?_=1}-
/** User Gadgets **/
mw.loader.load(
  'https://zh.moegirl.org.cn/index.php?title=User:机智的小鱼君/gadget/index.js&action=raw&ctype=text/javascript'
)

/** InPageEdit **/
// Global variable
var InPageEdit = window.InPageEdit || {}
// Load plugin
import('http://127.0.0.1:1225/InPageEdit.js?_=' + Date.now())
  .then(
    function (payload) {
      console.info('[InPageEdit] Connected to dev server')
      var config = mw.config.get()
      return payload.InPageEdit.newFromApiEndpoint(
        config.wgServer + config.wgScriptPath + '/api.php'
      )
    },
    function (e) {
      console.info('[InPageEdit] Cannot fetch dev server', e)
      mw.loader.load('https://unpkg.com/mediawiki-inpageedit')
      return Promise.reject(e)
    }
  )
  .then(function (ctx) {
    console.info('[InPageEdit] Context', ctx)
    window.ipenext = ctx
  })

// Preferences
InPageEdit.myPreference = {
  editMinor: false,
  editSummary: '$section快速小编辑$oldid // InPageEdit-v2',
  outSideClose: false,
  plugins: [
    'toolbox.js',
    'edit-any-page.js',
    'monaco/script.js',
    'color-preview.js',
    'quick-thank.js',
  ],
  codeMirrorTheme: 'mdn-like',
}

// Test linksHere
mw.hook('InPageEdit').add(function () {
  $('#t-whatlinkshere').on('click', function (e) {
    if (!InPageEdit.linksHere) return
    e.preventDefault()
    InPageEdit.linksHere()
  })
})

// 修改 IPE 文字防止抑郁
InPageEdit.i18n = InPageEdit.i18n || {}
InPageEdit.i18n['zh-hans'] = InPageEdit.i18n['zh-hans'] || {}
InPageEdit.i18n['zh-hans']['quick-edit'] = 'IPE 快编'

/** MoeSkin switcher */
$(function () {
  window.toggleMoeskin = function (status) {
    if (typeof status === 'undefined') {
      status = !(mw.user.options.get('skin') === 'moeskin')
    } else {
      status = !!status
    }
    var api = new mw.Api({
      parameters: {
        format: 'json',
        formatversion: 2,
      },
    })
    return api
      .postWithToken('csrf', {
        format: 'json',
        action: 'options',
        change: 'skin=' + (status ? 'moeskin' : 'vector'),
      })
      .then(function (data) {
        if (data.options === 'success') {
          return true
        } else {
          return false
        }
      })
  }
})

/** More portletLinks */
$(function () {
  var conf = mw.config.get()

  // prefix index
  if (conf.wgIsArticle) {
    var prefixIndex = mw.util.addPortletLink(
      'p-tb',
      mw.util.getUrl(
        'Special:PrefixIndex/' + mw.config.get('wgPageName') + '/'
      ),
      '前缀索引',
      '前缀索引'
    )
    prefixIndex.querySelector('a').target = '_blank'
  }

  // MoeSkin switcher
  mw.util
    .addPortletLink(
      'p-navigation',
      'javascript:;',
      'Toggle MoeSkin',
      'Toggle MoeSkin'
    )
    .addEventListener('click', function () {
      if (this.innerText !== 'Toggle MoeSkin') return
      var anchorEl = this.querySelector('a')
      anchorEl.innerText = 'Loading...'
      window.toggleMoeskin().then(function (res) {
        if (res) {
          anchorEl.innerText = 'Reloading page...'
          location.reload(true)
        } else {
          anchorEl.innerText = 'Toggle MoeSkin'
        }
      })
    })
})