BlitzRhythm Editor Mod Base Lib

A BlitzRhythm Editor Mod Base Lib

目前为 2023-09-06 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/474680/1246368/BlitzRhythm%20Editor%20Mod%20Base%20Lib.js

  1. // ==UserScript==
  2. // @name BlitzRhythm Editor Mod Base Lib
  3. // @namespace lib-cipher-mod-base
  4. // @version 1.0.0
  5. // @description A BlitzRhythm Editor Mod Base Lib
  6. // @author Moyuer
  7. // @author:zh 如梦Nya
  8. // @license MIT
  9. // @source https://github.com/CMoyuer/BlitzRhythm-Editor-Mod-Loader
  10. // @match *://*/*
  11. // ==/UserScript==
  12.  
  13. const scriptInfo = window.GM_info.script
  14. // const icon = window.GM_info.script.icon
  15. // const scriptName = window.GM_info.script.name
  16. const scriptNamespace = scriptInfo.namespace
  17.  
  18. function log(...data) {
  19. console.log("[" + scriptNamespace + "]", ...data)
  20. }
  21.  
  22. /**
  23. * i18n
  24. * @param {string} key
  25. */
  26. function $t(key) {
  27. let language = localStorage.getItem("i18nextLng") ?? "en"
  28. if (/^zh-?/.test(language) && I18N["zh"]) language = "zh"
  29. let keys = key.split('.')
  30. try {
  31. let val = I18N[language] ?? I18N['en']
  32. keys.forEach(element => {
  33. val = val[element]
  34. })
  35. return val
  36. } catch (error) {
  37. console.warn("[" + scriptNamespace + "]I18N Key not found: " + key)
  38. return key
  39. }
  40. }
  41.  
  42. /**
  43. * Get parameter value
  44. * @param {string} parameterId
  45. */
  46. function $p(parameterId) {
  47. try {
  48. let info = JSON.parse(localStorage.getItem("mod-" + scriptNamespace))
  49. return info.parameter[parameterId].value
  50. } catch (error) {
  51. return
  52. }
  53. }
  54.  
  55. function showPluginSetupPage() {
  56. unsafeWindow.modloader.drawer.methods.show()
  57. // TODO
  58. }
  59.  
  60. function hideDrawer() {
  61. unsafeWindow.modloader.drawer.methods.hide()
  62. }
  63.  
  64. (function () {
  65. 'use strict'
  66.  
  67. let _methods = {
  68. enabled: () => {
  69. if (typeof (onEnabled) === "function")
  70. onEnabled()
  71. },
  72. disabled: () => {
  73. if (typeof (onDisabled) === "function")
  74. onDisabled()
  75. },
  76. parameterChanged: (id, val) => {
  77. if (typeof (onParameterValueChanged) === "function")
  78. onParameterValueChanged(id, val)
  79. }
  80. }
  81.  
  82. let handle = setInterval(() => {
  83. if (!unsafeWindow.modloader) return
  84. unsafeWindow.modloader.addMod({
  85. id: scriptNamespace,
  86. info: scriptInfo,
  87. parameter: PARAMETER,
  88. methods: METHODS,
  89. _methods,
  90. window,
  91. })
  92. clearInterval(handle)
  93. }, 100)
  94. })()