BlitzRhythm Editor Mod Loader

A BlitzRhythm Editor Mod Loader

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

  1. // ==UserScript==
  2. // @name BlitzRhythm Editor Mod Loader
  3. // @name:zh 闪韵灵境谱面编辑器 模组加载器
  4. // @namespace cipher-editor-mods-loader
  5. // @version 1.0.0
  6. // @description A BlitzRhythm Editor Mod Loader
  7. // @description:zh 一款《闪韵灵境》谱面编辑器的Mod加载器
  8. // @author Moyuer
  9. // @author:zh 如梦Nya
  10. // @license MIT
  11. // @grant unsafeWindow
  12. // @grant GM_xmlhttpRequest
  13. // @connect githubusercontent.com
  14. // @match https://cipher-editor-cn.picovr.com/*
  15. // @match https://cipher-editor-va.picovr.com/*
  16. // @icon https://cipher-editor-va.picovr.com/favicon.ico
  17. // @require https://code.jquery.com/jquery-3.6.0.min.js
  18. // ==/UserScript==
  19.  
  20. let htmlSrc = "https://raw.githubusercontent.com/CMoyuer/BlitzRhythm-Editor-Mod-Loader/main/ModLoaderDrawer/dist/index.html"
  21.  
  22. if (GM_info.script.namespace.endsWith("-dev"))
  23. htmlSrc = "http://127.0.0.1"
  24.  
  25.  
  26. /** @type {HTMLElement} */
  27. let modloaderBox
  28. /** @type {HTMLElement} */
  29. let divMask
  30. /** @type {HTMLElement} */
  31. let iframe
  32.  
  33. function initModloaderBox() {
  34. if (modloaderBox) return
  35. modloaderBox = document.createElement("div")
  36. modloaderBox.style = "position:absolute;width:100%;height:100%;top:0;left:0;z-index:9001;pointer-events:none;"
  37.  
  38. divMask = document.createElement("div")
  39. divMask.style = "width:100%;height:100%;background-color:#00000050;display:none;pointer-events:auto;"
  40. divMask.onclick = hideIframe
  41. modloaderBox.append(divMask)
  42.  
  43. iframe = document.createElement("iframe")
  44. modloaderBox.id = "modloaderIframe"
  45. iframe.style = "box-shadow: 0 0 10px 0 black;border:none;width:360px;height:100vh;position:fixed;right:0;top:0;bottom:0;transform:translateX(100%);z-index:9999;transition: transform 0.3s ease-in-out;pointer-events: auto;"
  46. GM_xmlhttpRequest({
  47. url: htmlSrc + "?t=" + new Date().getTime(),
  48. method: "GET",
  49. onload: res => {
  50. iframe.srcdoc = res.response
  51. },
  52. onerror: res => {
  53. console.error(res)
  54. }
  55. })
  56. modloaderBox.append(iframe)
  57. document.body.append(modloaderBox)
  58. }
  59.  
  60. function showIframe() {
  61. divMask.style.display = "block"
  62. iframe.style.transform = "translateX(0)"
  63. }
  64.  
  65. function hideIframe() {
  66. divMask.style.display = "none"
  67. iframe.style.transform = "translateX(100%)"
  68. }
  69.  
  70. function initShowButton() {
  71. let btnShow = document.createElement("div")
  72. btnShow.id = "btnModLoaderShow"
  73. btnShow.innerHTML = "M"
  74. btnShow.style = "position:absolute;transform:translate(-50%, -50%);left:calc(100vw - 50px);top:calc(100vh - 50px);width:50px;height: 50px;background-color:#2196F3;border-radius:25px;z-index:9000;font-size:1.5em;line-height:50px;text-align:center;color:white;font-family:Roboto,Helvetica,Arial,sans-serif;box-shadow: 0 0 6px 0 gray;user-select:none;"
  75. let info = {
  76. handle: 0,
  77. mousedown: false,
  78. dragging: false,
  79. canClick: true,
  80. rawPos: [0, 0],
  81. position: [0, 0],
  82. }
  83.  
  84. function getMoveDistance() {
  85. return Math.abs(info.position[0] - info.rawPos[0]) + Math.abs(info.position[1] - info.rawPos[1])
  86. }
  87.  
  88. btnShow.onmousedown = res => {
  89. btnShow.style.backgroundColor = "#1769AA"
  90. info.canClick = true
  91. info.mousedown = true
  92. info.handle = setTimeout(() => {
  93. btnShow.style.boxShadow = "0 0 6px 2px white"
  94. info.dragging = true
  95. info.handle = 0
  96. }, 100)
  97. if (btnShow.style.left && btnShow.style.left.startsWith("calc"))
  98. btnShow.style.left = btnShow.offsetLeft + "px"
  99. if (btnShow.style.top && btnShow.style.top.startsWith("calc"))
  100. btnShow.style.top = btnShow.offsetTop + "px"
  101. info.rawPos = [btnShow.offsetLeft, btnShow.offsetTop]
  102. info.position = [res.clientX, res.clientY]
  103. }
  104. btnShow.onmousemove = res => {
  105. if (!info.dragging) return
  106. let x = res.clientX
  107. let y = res.clientY
  108. let deltaX = x - info.position[0]
  109. let deltaY = y - info.position[1]
  110. let left = parseInt(btnShow.style.left || 0)
  111. let top = parseInt(btnShow.style.top || 0)
  112. btnShow.style.left = left + deltaX + 'px'
  113. btnShow.style.top = top + deltaY + 'px'
  114. info.position = [x, y]
  115. }
  116. btnShow.onmouseup = btnShow.onmouseleave = () => {
  117. btnShow.style.backgroundColor = "#2196F3"
  118. btnShow.style.boxShadow = "0 0 6px 0 gray"
  119. if (info.handle > 0) {
  120. clearTimeout(info.handle)
  121. info.handle = 0
  122. }
  123. info.canClick = !info.dragging
  124. info.mousedown = false
  125. info.dragging = false
  126. }
  127. btnShow.onclick = () => {
  128. if (!info.canClick) return
  129. showIframe()
  130. }
  131.  
  132. window.onresize = () => {
  133. let left = parseInt(btnShow.style.left || 0)
  134. let top = parseInt(btnShow.style.top || 0)
  135. if (window.innerWidth < left + 50)
  136. btnShow.style.left = "calc(100vw - 50px)"
  137. if (window.innerHeight < top + 50)
  138. btnShow.style.top = "calc(100vh - 50px)"
  139. }
  140.  
  141. document.body.appendChild(btnShow)
  142. }
  143.  
  144. (function () {
  145. 'use strict'
  146. initModloaderBox()
  147.  
  148. let handle = setInterval(() => {
  149. if (!unsafeWindow.modloader) return
  150. unsafeWindow.modloader.drawer = {
  151. methods: {
  152. show: showIframe,
  153. hide: hideIframe
  154. }
  155. }
  156. initShowButton()
  157. clearInterval(handle)
  158. }, 100)
  159. })();