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:進入「工具→偏好設定」中清除快取。
  • 如果您已登入但該頁面出現未登入狀態,請嘗試在網址列的URL最後新增代碼?_=1來訪問最新頁面。
  1. /** User Gadgets **/
  2. mw.loader.load(
  3. 'http://zh.moegirl.tw/index.php?title=User:機智的小魚君/gadget/index.js&action=raw&ctype=text/javascript'
  4. )
  5. /** InPageEdit **/
  6. // Global variable
  7. var InPageEdit = window.InPageEdit || {}
  8. // Load plugin
  9. import('http://127.0.0.1:1225/InPageEdit.js?_=' + Date.now())
  10. .then(
  11. function (payload) {
  12. console.info('[InPageEdit] Connected to dev server')
  13. var config = mw.config.get()
  14. return payload.InPageEdit.newFromApiEndpoint(
  15. config.wgServer + config.wgScriptPath + '/api.php'
  16. )
  17. },
  18. function (e) {
  19. console.info('[InPageEdit] Cannot fetch dev server', e)
  20. mw.loader.load('https://unpkg.com/mediawiki-inpageedit')
  21. return Promise.reject(e)
  22. }
  23. )
  24. .then(function (ctx) {
  25. console.info('[InPageEdit] Context', ctx)
  26. window.ipenext = ctx
  27. })
  28. // Preferences
  29. InPageEdit.myPreference = {
  30. editMinor: false,
  31. editSummary: '$section快速小編輯$oldid // InPageEdit-v2',
  32. outSideClose: false,
  33. plugins: [
  34. 'toolbox.js',
  35. 'edit-any-page.js',
  36. 'monaco/script.js',
  37. 'color-preview.js',
  38. 'quick-thank.js',
  39. ],
  40. codeMirrorTheme: 'mdn-like',
  41. }
  42. // Test linksHere
  43. mw.hook('InPageEdit').add(function () {
  44. $('#t-whatlinkshere').on('click', function (e) {
  45. if (!InPageEdit.linksHere) return
  46. e.preventDefault()
  47. InPageEdit.linksHere()
  48. })
  49. })
  50. // 修改 IPE 文字防止抑鬱
  51. InPageEdit.i18n = InPageEdit.i18n || {}
  52. InPageEdit.i18n['zh-hans'] = InPageEdit.i18n['zh-hans'] || {}
  53. InPageEdit.i18n['zh-hans']['quick-edit'] = 'IPE 快編'
  54. /** MoeSkin switcher */
  55. $(function () {
  56. window.toggleMoeskin = function (status) {
  57. if (typeof status === 'undefined') {
  58. status = !(mw.user.options.get('skin') === 'moeskin')
  59. } else {
  60. status = !!status
  61. }
  62. var api = new mw.Api({
  63. parameters: {
  64. format: 'json',
  65. formatversion: 2,
  66. },
  67. })
  68. return api
  69. .postWithToken('csrf', {
  70. format: 'json',
  71. action: 'options',
  72. change: 'skin=' + (status ? 'moeskin' : 'vector'),
  73. })
  74. .then(function (data) {
  75. if (data.options === 'success') {
  76. return true
  77. } else {
  78. return false
  79. }
  80. })
  81. }
  82. })
  83. /** More portletLinks */
  84. $(function () {
  85. var conf = mw.config.get()
  86. // prefix index
  87. if (conf.wgIsArticle) {
  88. var prefixIndex = mw.util.addPortletLink(
  89. 'p-tb',
  90. mw.util.getUrl(
  91. 'Special:PrefixIndex/' + mw.config.get('wgPageName') + '/'
  92. ),
  93. '前綴索引',
  94. '前綴索引'
  95. )
  96. prefixIndex.querySelector('a').target = '_blank'
  97. }
  98. // MoeSkin switcher
  99. mw.util
  100. .addPortletLink(
  101. 'p-navigation',
  102. 'javascript:;',
  103. 'Toggle MoeSkin',
  104. 'Toggle MoeSkin'
  105. )
  106. .addEventListener('click', function () {
  107. if (this.innerText !== 'Toggle MoeSkin') return
  108. var anchorEl = this.querySelector('a')
  109. anchorEl.innerText = 'Loading...'
  110. window.toggleMoeskin().then(function (res) {
  111. if (res) {
  112. anchorEl.innerText = 'Reloading page...'
  113. var url = new URL(location.href)
  114. url.searchParams['delete']('useskin')
  115. if (url.hostname.startsWith('mzh.')) {
  116. url.hostname = url.hostname.replace('mzh',' zh')
  117. }
  118. location.href = url.href
  119. } else {
  120. anchorEl.innerText = 'Toggle MoeSkin'
  121. }
  122. })
  123. })
  124. })
  125. /** MoeHomeland Dev */
  126. $(function () {
  127. if ($('.mainpage').length) {
  128. try {
  129. import('http://localhost:2023/dev/autoload.ts?_=' + Date.now())
  130. } catch (e) {
  131. // NOOP
  132. }
  133. }
  134. })
此頁面最後編輯於 2025年5月14日 (週三) 22:36。
搜尋萌娘百科 (按"/"快速搜尋)
有新的未讀公告