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