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.2
  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. // @require https://greasyfork.org/scripts/473358-jszip/code/main.js?version=1237031
  19. // @require https://greasyfork.org/scripts/473361-xml-http-request-interceptor/code/main.js?version=1237032
  20. // @require https://greasyfork.org/scripts/473362-web-indexeddb-helper/code/main.js?version=1237033
  21. // @require https://greasyfork.org/scripts/474682-extra-song-search/code/main.js?version=1246392
  22. // ==/UserScript==
  23.  
  24. let htmlSrc = "https://raw.githubusercontent.com/CMoyuer/BlitzRhythm-Editor-Mod-Loader/main/ModLoaderDrawer/dist/index.html"
  25.  
  26. if (GM_info.script.namespace.endsWith("-dev"))
  27. htmlSrc = "http://127.0.0.1"
  28.  
  29.  
  30. /** @type {HTMLElement} */
  31. let modloaderBox
  32. /** @type {HTMLElement} */
  33. let divMask
  34. /** @type {HTMLElement} */
  35. let iframe
  36.  
  37. function initModloaderBox() {
  38. if (modloaderBox) return
  39. modloaderBox = document.createElement("div")
  40. modloaderBox.style = "position:absolute;width:100%;height:100%;top:0;left:0;z-index:9001;pointer-events:none;"
  41.  
  42. divMask = document.createElement("div")
  43. divMask.style = "width:100%;height:100%;background-color:#00000050;display:none;pointer-events:auto;"
  44. divMask.onclick = hideIframe
  45. modloaderBox.append(divMask)
  46.  
  47. iframe = document.createElement("iframe")
  48. modloaderBox.id = "modloaderIframe"
  49. 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;"
  50. GM_xmlhttpRequest({
  51. url: htmlSrc + "?t=" + new Date().getTime(),
  52. method: "GET",
  53. onload: res => {
  54. iframe.srcdoc = res.response
  55. },
  56. onerror: res => {
  57. console.error(res)
  58. }
  59. })
  60. modloaderBox.append(iframe)
  61. document.body.append(modloaderBox)
  62. }
  63.  
  64. function showIframe() {
  65. divMask.style.display = "block"
  66. iframe.style.transform = "translateX(0)"
  67. }
  68.  
  69. function hideIframe() {
  70. divMask.style.display = "none"
  71. iframe.style.transform = "translateX(100%)"
  72. }
  73.  
  74. function initShowButton() {
  75. let btnShow = document.createElement("div")
  76. btnShow.id = "btnModLoaderShow"
  77. btnShow.innerHTML = "M"
  78. 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;"
  79. let info = {
  80. handle: 0,
  81. mousedown: false,
  82. dragging: false,
  83. canClick: true,
  84. rawPos: [0, 0],
  85. position: [0, 0],
  86. }
  87.  
  88. function getMoveDistance() {
  89. return Math.abs(info.position[0] - info.rawPos[0]) + Math.abs(info.position[1] - info.rawPos[1])
  90. }
  91.  
  92. btnShow.onmousedown = res => {
  93. btnShow.style.backgroundColor = "#1769AA"
  94. info.canClick = true
  95. info.mousedown = true
  96. info.handle = setTimeout(() => {
  97. btnShow.style.boxShadow = "0 0 6px 2px white"
  98. info.dragging = true
  99. info.handle = 0
  100. }, 100)
  101. if (btnShow.style.left && btnShow.style.left.startsWith("calc"))
  102. btnShow.style.left = btnShow.offsetLeft + "px"
  103. if (btnShow.style.top && btnShow.style.top.startsWith("calc"))
  104. btnShow.style.top = btnShow.offsetTop + "px"
  105. info.rawPos = [btnShow.offsetLeft, btnShow.offsetTop]
  106. info.position = [res.clientX, res.clientY]
  107. }
  108. btnShow.onmousemove = res => {
  109. if (!info.dragging) return
  110. let x = res.clientX
  111. let y = res.clientY
  112. let deltaX = x - info.position[0]
  113. let deltaY = y - info.position[1]
  114. let left = parseInt(btnShow.style.left || 0)
  115. let top = parseInt(btnShow.style.top || 0)
  116. btnShow.style.left = left + deltaX + 'px'
  117. btnShow.style.top = top + deltaY + 'px'
  118. info.position = [x, y]
  119. }
  120. btnShow.onmouseup = btnShow.onmouseleave = () => {
  121. btnShow.style.backgroundColor = "#2196F3"
  122. btnShow.style.boxShadow = "0 0 6px 0 gray"
  123. if (info.handle > 0) {
  124. clearTimeout(info.handle)
  125. info.handle = 0
  126. }
  127. info.canClick = !info.dragging
  128. info.mousedown = false
  129. info.dragging = false
  130. }
  131. btnShow.onclick = () => {
  132. if (!info.canClick) return
  133. showIframe()
  134. }
  135.  
  136. window.onresize = () => {
  137. let left = parseInt(btnShow.style.left || 0)
  138. let top = parseInt(btnShow.style.top || 0)
  139. if (window.innerWidth < left + 50)
  140. btnShow.style.left = "calc(100vw - 50px)"
  141. if (window.innerHeight < top + 50)
  142. btnShow.style.top = "calc(100vh - 50px)"
  143. }
  144.  
  145. document.body.appendChild(btnShow)
  146. }
  147.  
  148. (function () {
  149. 'use strict'
  150. initModloaderBox()
  151.  
  152. let handle = setInterval(() => {
  153. if (!unsafeWindow.modloader) return
  154. unsafeWindow.modloader.drawer = {
  155. methods: {
  156. show: showIframe,
  157. hide: hideIframe
  158. }
  159. }
  160. initShowButton()
  161. clearInterval(handle)
  162. }, 100)
  163. })();