闪韵灵境编辑器模组基本库

兼容模组加载器所必须的库

当前为 2023-09-28 提交的版本,查看 最新版本

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

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