BlitzRhythm Editor Mod Loader

A BlitzRhythm Editor Mod Loader

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

  1. // ==UserScript==
  2. // @name BlitzRhythm Editor Mod Loader
  3. // @name:zh 闪韵灵境谱面编辑器 模组加载器
  4. // @namespace cipher-editor-mods-loader
  5. // @version 1.1.1
  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 beatsaver.com
  14. // @connect githubusercontent.com
  15. // @match https://cipher-editor-cn.picovr.com/*
  16. // @match https://cipher-editor-va.picovr.com/*
  17. // @icon https://cipher-editor-va.picovr.com/favicon.ico
  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. console.log("ModLoader loading...")
  47. GM_xmlhttpRequest({
  48. url: htmlSrc + "?t=" + new Date().getTime(),
  49. method: "GET",
  50. onload: res => {
  51. iframe.srcdoc = res.response
  52. },
  53. onerror: res => {
  54. console.error(res)
  55. alert("ModLoader load failed!")
  56. }
  57. })
  58. modloaderBox.append(iframe)
  59. document.body.append(modloaderBox)
  60. }
  61.  
  62. function showIframe() {
  63. divMask.style.display = "block"
  64. iframe.style.transform = "translateX(0)"
  65. }
  66.  
  67. function hideIframe() {
  68. divMask.style.display = "none"
  69. iframe.style.transform = "translateX(100%)"
  70. }
  71.  
  72. function initShowButton() {
  73. let btnShow = document.createElement("div")
  74. btnShow.id = "btnModLoaderShow"
  75. btnShow.innerHTML = "M"
  76. 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;"
  77. let info = {
  78. handle: 0,
  79. mousedown: false,
  80. dragging: false,
  81. canClick: true,
  82. rawPos: [0, 0],
  83. position: [0, 0],
  84. }
  85.  
  86. function getMoveDistance() {
  87. return Math.abs(info.position[0] - info.rawPos[0]) + Math.abs(info.position[1] - info.rawPos[1])
  88. }
  89.  
  90. btnShow.onmousedown = res => {
  91. btnShow.style.backgroundColor = "#1769AA"
  92. info.canClick = true
  93. info.mousedown = true
  94. info.handle = setTimeout(() => {
  95. btnShow.style.boxShadow = "0 0 6px 2px white"
  96. info.dragging = true
  97. info.handle = 0
  98. }, 100)
  99. if (btnShow.style.left && btnShow.style.left.startsWith("calc"))
  100. btnShow.style.left = btnShow.offsetLeft + "px"
  101. if (btnShow.style.top && btnShow.style.top.startsWith("calc"))
  102. btnShow.style.top = btnShow.offsetTop + "px"
  103. info.rawPos = [btnShow.offsetLeft, btnShow.offsetTop]
  104. info.position = [res.clientX, res.clientY]
  105. }
  106. btnShow.onmousemove = res => {
  107. if (!info.dragging) return
  108. let x = res.clientX
  109. let y = res.clientY
  110. let deltaX = x - info.position[0]
  111. let deltaY = y - info.position[1]
  112. let left = parseInt(btnShow.style.left || 0)
  113. let top = parseInt(btnShow.style.top || 0)
  114. btnShow.style.left = left + deltaX + 'px'
  115. btnShow.style.top = top + deltaY + 'px'
  116. info.position = [x, y]
  117. }
  118. btnShow.onmouseup = btnShow.onmouseleave = () => {
  119. btnShow.style.backgroundColor = "#2196F3"
  120. btnShow.style.boxShadow = "0 0 6px 0 gray"
  121. if (info.handle > 0) {
  122. clearTimeout(info.handle)
  123. info.handle = 0
  124. }
  125. info.canClick = !info.dragging
  126. info.mousedown = false
  127. info.dragging = false
  128. }
  129. btnShow.onclick = () => {
  130. if (!info.canClick) return
  131. showIframe()
  132. }
  133.  
  134. window.onresize = () => {
  135. let left = parseInt(btnShow.style.left || 0)
  136. let top = parseInt(btnShow.style.top || 0)
  137. if (window.innerWidth < left + 50)
  138. btnShow.style.left = "calc(100vw - 50px)"
  139. if (window.innerHeight < top + 50)
  140. btnShow.style.top = "calc(100vh - 50px)"
  141. }
  142.  
  143. document.body.appendChild(btnShow)
  144. }
  145.  
  146. (function () {
  147. 'use strict'
  148. initModloaderBox()
  149.  
  150. let handle = setInterval(() => {
  151. if (!unsafeWindow.modloader) return
  152. unsafeWindow.modloader.drawer = {
  153. methods: {
  154. show: showIframe,
  155. hide: hideIframe
  156. }
  157. }
  158. initShowButton()
  159. clearInterval(handle)
  160. }, 100)
  161. })();