From c0aad4331738df9a67419e7953ef212c6ccfab13 Mon Sep 17 00:00:00 2001 From: wit_cat <96361142+little-starts@users.noreply.github.com> Date: Thu, 28 Dec 2023 23:53:14 +0800 Subject: [PATCH 1/6] More_Mouse V3.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(code):修复了显示提示被全屏遮挡的BUG fix(code):修复了在隐藏动画播放时显示提示报错的BUG fix(block):修复并重新上线全屏系列积木 --- wit_cat/More_Mouse.js | 159 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 137 insertions(+), 22 deletions(-) diff --git a/wit_cat/More_Mouse.js b/wit_cat/More_Mouse.js index 4d75289e..cae33dc9 100644 --- a/wit_cat/More_Mouse.js +++ b/wit_cat/More_Mouse.js @@ -83,7 +83,17 @@ class WitCatMouse { * 鼠标提示的div * @type {HTMLDivElement} */ - this.title = null; + this.titleDiv = null; + + /** + * 拒绝全屏次数 + */ + this.fillNum = 0; + + /** + * 全屏监听事件缓存 + */ + this.fillEvent = null; this.runtime = runtime; @@ -112,7 +122,7 @@ class WitCatMouse { this._formatMessage = runtime.getFormatMessage({ 'zh-cn': { 'WitCatMouse.copythis': '复制以下内容:', - 'WitCatMouse.name': '[beta]白猫的高级鼠标', + 'WitCatMouse.name': '白猫的高级鼠标', 'WitCatMouse.name.1': '高级鼠标', 'WitCatMouse.name.2': '手机端', 'WitCatMouse.set': '[set]右键菜单', @@ -141,7 +151,7 @@ class WitCatMouse { 'WitCatTouch.type.3': 'ID', 'WitCatMouse.fill': '[set]沉浸式全屏', 'WitCatMouse.fillask.1': '作品请求沉浸式全屏,是否同意?\n', - 'WitCatMouse.fillask.2': '/3次连续拒绝后将不再提示\n您仍可以使用 ctrl+shift+alt 切换沉浸式全屏状态', + 'WitCatMouse.fillask.2': '/3次连续拒绝后将不再提示\n您仍可以使用 esc 切换沉浸式全屏状态', 'WitCatMouse.setfill': '⚠️(危)设置分辨率高设为[num]', 'WitCatMouse.resolution': '当前分辨率高', 'WitCatMouse.cantouch': '设备支持[type]?', @@ -179,7 +189,7 @@ class WitCatMouse { }, en: { 'WitCatMouse.copythis': 'Copy the following text:', - 'WitCatMouse.name': '[beta]WitCat’s Mouse', + 'WitCatMouse.name': 'WitCat’s Mouse', 'WitCatMouse.name.1': 'more mouse', 'WitCatMouse.name.2': 'Mobile terminal', 'WitCatMouse.set': '[set]right-click menu', @@ -209,7 +219,7 @@ class WitCatMouse { 'WitCatMouse.fill': '[set]immersive full-screen', 'WitCatMouse.fillask.1': 'The project requests to turn on immersive full-screen, agree or not?\nWill stop asking if you keep on to reject for ', - 'WitCatMouse.fillask.2': '/3 times\nYou can also use Ctrl+Shift+Alt to toggle immersive full-screen later.', + 'WitCatMouse.fillask.2': '/3 times\nYou can also use esc to toggle immersive full-screen later.', 'WitCatMouse.setfill': '⚠️(danger)Set resolution height to[num]', 'WitCatMouse.resolution': 'Current high resolution', 'WitCatMouse.cantouch': 'Device support[type]?', @@ -279,7 +289,6 @@ class WitCatMouse { opcode: 'setfill', blockType: 'command', text: this.formatMessage('WitCatMouse.setfill'), - hideFromPalette: true, arguments: { num: { type: 'number', @@ -291,7 +300,6 @@ class WitCatMouse { opcode: 'fill', blockType: 'command', text: this.formatMessage('WitCatMouse.fill'), - hideFromPalette: true, arguments: { set: { type: 'bool', @@ -303,7 +311,6 @@ class WitCatMouse { opcode: 'resolution', blockType: 'reporter', text: this.formatMessage('WitCatMouse.resolution'), - hideFromPalette: true, arguments: {}, }, `---${this.formatMessage('WitCatMouse.name.1')}`, @@ -924,20 +931,61 @@ class WitCatMouse { * 全屏 * @deprecated */ - fill() { - console.warn( - '全屏因浏览器兼容问题已下线,在未来修复后将会重新上线\nFull screen has been taken offline due to browser compatibility issues. It will be back online after a future fix' - ); + fill(args) { + const canvas = this.canvas(); + console.log(canvas); + if (canvas === null) { + return 0; + } + if (this.fillNum < 3) { + if (args.set == 'true') { + this.fillNum = 0; + let fills = confirm(this.formatMessage('WitCatMouse.fillask.1') + this.fillNum + this.formatMessage('WitCatMouse.fillask.2')) + if (fills) { + resizeElementInParent(this.canvas().firstChild, false); + launchFullscreen(canvas); + canvas.firstChild.style.margin = '0 auto'; + setTimeout(() => { + resizeElementInParent(this.canvas().firstChild, false); + document.addEventListener("fullscreenchange", () => { + setTimeout(() => { + if (!document.fullscreenElement) { + resizeElementInParent(this.canvas().firstChild, true); + } + }, 100); + }, { once: true }); + this.fillEvent = window.addEventListener("resize", () => { + if (document.fullscreenElement) { + resizeElementInParent(this.canvas().firstChild, false); + } + }); + }, 100); + } + else { + this.fillNum++; + } + } else { + exitFullscreen(); + window.removeEventListener(this.fillEvent); + setTimeout(() => { + resizeElementInParent(canvas.firstChild, true); + }, 1000); + } + } } /** * 设置分辨率 * @deprecated */ - setfill() { - console.warn( - '全屏因浏览器兼容问题已下线,在未来修复后将会重新上线\nFull screen has been taken offline due to browser compatibility issues. It will be back online after a future fix' - ); + setfill(args) { + const canvas = this.canvas(); + console.log(canvas); + if (canvas === null) { + return 0; + } + canvas.firstChild.height = Number(args.num); + canvas.firstChild.width = (Number(args.num) * this.runtime.stageWidth) / this.runtime.stageHeight; } /** @@ -949,7 +997,7 @@ class WitCatMouse { if (canvas === null) { return 0; } - return canvas.height; + return canvas.firstChild.height; } /** @@ -1079,16 +1127,20 @@ class WitCatMouse { } titlenow(args) { + const canvas = this.canvas(); + if (canvas === null) { + return; + } if (args.show === 'true') { if (this.titleDiv == null) { this.titleDiv = document.createElement("div"); this.titleDiv.innerText = String(args.text); - this.titleDiv.style = `transition: transform 0.2s ease-in-out;transform: scale(0, 0);border:1px solid #000000 ;transform-origin:0px 0px;border-radius:10px;background-color:#ffffff;padding:5px;position:fixed;top:${this.MouseY + 10}px;left:${this.MouseX + 10}px`; + this.titleDiv.style = `transition: transform 0.2s ease-in-out;transform: scale(0, 0);z-index: 10000;border:1px solid #000000 ;transform-origin:0px 0px;border-radius:10px;background-color:#ffffff;padding:5px;position:fixed;top:${this.MouseY + 10}px;left:${this.MouseX + 10}px`; this.MouseTitle = setInterval(() => { this.titleDiv.style.top = (this.MouseY + 10) + 'px'; this.titleDiv.style.left = (this.MouseX + 10) + 'px'; }, 1); - document.body.appendChild(this.titleDiv); + canvas.append(this.titleDiv); setTimeout(() => { this.titleDiv.style.transform = 'scale(1, 1)'; }, 10); @@ -1104,8 +1156,9 @@ class WitCatMouse { } } else { - if (this.titleDiv !== null) { + if (this.MouseTitle !== null) { clearInterval(this.MouseTitle); + this.MouseTitle = null; this.titleDiv.style.transform = 'scale(0, 0)'; setTimeout(() => { document.body.removeChild(this.titleDiv); @@ -1610,12 +1663,74 @@ window.tempExt = { }, l10n: { "zh-cn": { - "WitCatMouse.name": "[beta]白猫的高级鼠标", + "WitCatMouse.name": "白猫的高级鼠标 V3.2", "WitCatMouse.descp": "更精准的控制鼠标/触屏/全屏!" }, en: { - "WitCatMouse.name": "[beta]WitCat’s Mouse", + "WitCatMouse.name": "WitCat’s Mouse V3.2", "WitCatMouse.descp": "More precise mouse/touch/full screen control!" } } }; + +/** + * 将元素全屏 + * @param {Element} element 需要全屏的元素 + */ +function launchFullscreen(element) { + if (element.requestFullscreen) { + element.requestFullscreen(); + } else if (element.mozRequestFullScreen) { + element.mozRequestFullScreen(); + } else if (element.msRequestFullscreen) { + element.msRequestFullscreen(); + } else if (element.webkitRequestFullscreen) { + element.webkitRequestFullScreen(); + } +} + +/** + * 退出全屏模式 + */ +function exitFullscreen() { + if (document.exitFullscreen) { + document.exitFullscreen(); + } else if (document.msExitFullscreen) { + document.msExitFullscreen(); + } else if (document.mozCancelFullScreen) { + document.mozCancelFullScreen(); + } else if (document.webkitExitFullscreen) { + document.webkitExitFullscreen(); + } +} + +/** + * 计算舞台在全屏/非全屏的大小 + * @param {Element} element 需要被计算中心点的角色 + * @param {Boolean} type 模式(true:最小化,false:全屏) + */ +function resizeElementInParent(element, type) { + if (type) { + var parent = element.parentElement; + var parentWidth = parent.clientWidth; + var parentHeight = parent.clientHeight; + } + else { + var parentWidth = screen.width; + var parentHeight = screen.height; + } + + var elementWidth = element.offsetWidth; + var elementHeight = element.offsetHeight; + + var widthRatio = parentWidth / elementWidth; + var heightRatio = parentHeight / elementHeight; + + var scale = Math.min(widthRatio, heightRatio); + + var newWidth = elementWidth * scale; + var newHeight = elementHeight * scale; + + element.style.width = newWidth + "px"; + element.style.height = newHeight + "px"; +} From e7c5c48a25c232dba5f94d52584b7ca6371d1202 Mon Sep 17 00:00:00 2001 From: wit_cat <96361142+little-starts@users.noreply.github.com> Date: Sun, 31 Dec 2023 15:07:35 +0800 Subject: [PATCH 2/6] fix More_Mouse V3.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(code):全屏可能导致的BUG feat(block):检测是否全屏,当退出全屏 --- wit_cat/More_Mouse.js | 207 +++++++++++++++++++++++++++++++----------- 1 file changed, 155 insertions(+), 52 deletions(-) diff --git a/wit_cat/More_Mouse.js b/wit_cat/More_Mouse.js index cae33dc9..d5dd6d8a 100644 --- a/wit_cat/More_Mouse.js +++ b/wit_cat/More_Mouse.js @@ -93,7 +93,14 @@ class WitCatMouse { /** * 全屏监听事件缓存 */ - this.fillEvent = null; + this.fillEvent = [null, null]; + + this.fillEvent[1] = new MutationObserver((mutationsList) => { + resizeElementInParent(mutationsList[0].target.parentElement.parentElement, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + resizeElementInParent(mutationsList[0].target.parentElement, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + resizeElementInParent(mutationsList[0].target.parentElement.nextSibling.firstChild, false, 'zoom'); + resizeElementInParent(mutationsList[0].target, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + }); this.runtime = runtime; @@ -113,6 +120,18 @@ class WitCatMouse { } }; + this.canvasSelf = () => { + try { + const { canvas } = this.runtime.renderer; + if (canvas instanceof HTMLCanvasElement) { + return canvas; + } + return null; + } catch (err) { + return null; + } + }; + if (this.canvas() === null) { console.error('当前页面不支持多指触控/全屏,请前往作品详情页体验完整作品!'); // 注意:在提示之后,扩展仍然在运行。需要在后面引用 Canvas 的部分进行判断。 @@ -150,6 +169,8 @@ class WitCatMouse { 'WitCatTouch.type.2': 'Y', 'WitCatTouch.type.3': 'ID', 'WitCatMouse.fill': '[set]沉浸式全屏', + 'WitCatMouse.whenoutfill': '当退出全屏', + 'WitCatMouse.isfill': '全屏?', 'WitCatMouse.fillask.1': '作品请求沉浸式全屏,是否同意?\n', 'WitCatMouse.fillask.2': '/3次连续拒绝后将不再提示\n您仍可以使用 esc 切换沉浸式全屏状态', 'WitCatMouse.setfill': '⚠️(危)设置分辨率高设为[num]', @@ -217,6 +238,8 @@ class WitCatMouse { 'WitCatTouch.type.2': 'Y', 'WitCatTouch.type.3': 'ID', 'WitCatMouse.fill': '[set]immersive full-screen', + 'WitCatMouse.whenoutfill': 'When exiting full screen', + 'WitCatMouse.isfill': 'full screen?', 'WitCatMouse.fillask.1': 'The project requests to turn on immersive full-screen, agree or not?\nWill stop asking if you keep on to reject for ', 'WitCatMouse.fillask.2': '/3 times\nYou can also use esc to toggle immersive full-screen later.', @@ -296,6 +319,19 @@ class WitCatMouse { }, }, }, + { + opcode: 'whenOutFill', + blockType: 'hat', + text: this.formatMessage('WitCatMouse.whenoutfill'), + isEdgeActivated: false, + arguments: {}, + }, + { + opcode: 'isfill', + blockType: 'Boolean', + text: this.formatMessage('WitCatMouse.isfill'), + arguments: {}, + }, { opcode: 'fill', blockType: 'command', @@ -784,7 +820,7 @@ class WitCatMouse { * @returns 菜单 */ _spriteMenu() { - var e = []; + let e = []; return this.runtime.targets.forEach((function (t) { t.isOriginal && !t.isStage && e.push({ text: t.sprite.name, @@ -932,8 +968,7 @@ class WitCatMouse { * @deprecated */ fill(args) { - const canvas = this.canvas(); - console.log(canvas); + const canvas = this.canvasSelf(); if (canvas === null) { return 0; } @@ -942,23 +977,61 @@ class WitCatMouse { this.fillNum = 0; let fills = confirm(this.formatMessage('WitCatMouse.fillask.1') + this.fillNum + this.formatMessage('WitCatMouse.fillask.2')) if (fills) { - resizeElementInParent(this.canvas().firstChild, false); - launchFullscreen(canvas); - canvas.firstChild.style.margin = '0 auto'; + launchFullscreen(this.canvas().parentElement.parentElement); + this.canvas().parentElement.parentElement.style.overflow = 'visible'; + this.canvas().parentElement.parentElement.style.display = 'flex'; + this.canvas().parentElement.parentElement.style.alignItems = 'center'; + this.canvas().parentElement.style.display = 'flex'; + this.canvas().parentElement.style.alignItems = 'center'; + this.canvas().style.display = 'flex'; + this.canvas().style.alignItems = 'center'; setTimeout(() => { - resizeElementInParent(this.canvas().firstChild, false); + setTimeout(() => { + resizeElementInParent(this.canvas().parentElement, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + resizeElementInParent(this.canvas(), false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + resizeElementInParent(this.canvas().nextSibling.firstChild, false, 'zoom'); + resizeElementInParent(canvas, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + this.runtime.renderer.dirty = true; + this.runtime.renderer.draw(); + let button = document.getElementsByClassName('gandi_button_btn_dCMn2 gandi_stage-header_stage-button_hkl9B')[0] || + document.getElementsByClassName('action-item-P9SP6')[0] || + document.getElementsByClassName('c-actionItem')[0]; + if (button.innerHTML.includes("进入") || button.innerHTML.includes("M12.5 7.5l5-5m0 0h-5m5 0v5m-10 0l-5-5m0 0v5m0-5h5m0 10l-5 5m0 0h5m-5 0v-5m10 0l5 5m0 0v-5m0 5h-5")) { + button.click(); + } + }, 100); document.addEventListener("fullscreenchange", () => { - setTimeout(() => { - if (!document.fullscreenElement) { - resizeElementInParent(this.canvas().firstChild, true); - } - }, 100); - }, { once: true }); - this.fillEvent = window.addEventListener("resize", () => { - if (document.fullscreenElement) { - resizeElementInParent(this.canvas().firstChild, false); + if (!document.fullscreenElement) { + console.log("111") + this.fillEvent[1].disconnect(); + setTimeout(() => { + this.canvas().style = ""; + canvas.style.width = "100%"; + canvas.style.height = "100%"; + resizeElementInParent(this.canvas().parentElement, true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + resizeElementInParent(this.canvas(), true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + this.canvas().style.width = "auto"; + this.canvas().style.height = "auto"; + this.canvas().parentElement.style.width = "auto"; + this.canvas().parentElement.style.height = "auto"; + resizeElementInParent(this.canvas().nextSibling.firstChild, true, 'zoom'); + resizeElementInParent(canvas, true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + this.runtime.startHats(`${witcat_more_mouse_extensionId}_whenOutFill`); + }, 100); } - }); + }, { once: true }); + const config = { childList: true, attributeFilter: ['style'] }; + this.fillEvent[1].observe(canvas, config); + if (this.fillEvent[0] === null) { + this.fillEvent[0] = window.addEventListener('resize', function reSizeFill() { + if (document.fullscreenElement) { + resizeElementInParent(this.canvas().parentElement, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + resizeElementInParent(this.canvas(), false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + resizeElementInParent(this.canvas().nextSibling.firstChild, false, 'zoom'); + resizeElementInParent(canvas, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + } + }.bind(this)); + } }, 100); } else { @@ -966,26 +1039,45 @@ class WitCatMouse { } } else { exitFullscreen(); - window.removeEventListener(this.fillEvent); + this.fillEvent[1].disconnect(); setTimeout(() => { - resizeElementInParent(canvas.firstChild, true); - }, 1000); + this.canvas().style = ""; + canvas.style.width = "100%"; + canvas.style.height = "100%"; + resizeElementInParent(this.canvas().parentElement, true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + resizeElementInParent(this.canvas(), true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + this.canvas().style.width = "auto"; + this.canvas().style.height = "auto"; + this.canvas().parentElement.style.width = "auto"; + this.canvas().parentElement.style.height = "auto"; + resizeElementInParent(this.canvas().nextSibling.firstChild, true, 'zoom'); + resizeElementInParent(canvas, true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); + }, 100); } } } + whenOutFill() { + return true; + } + + isfill() { + return Boolean(document.fullscreenElement); + } + /** * 设置分辨率 * @deprecated */ setfill(args) { - const canvas = this.canvas(); - console.log(canvas); + const canvas = this.canvasSelf(); if (canvas === null) { return 0; } - canvas.firstChild.height = Number(args.num); - canvas.firstChild.width = (Number(args.num) * this.runtime.stageWidth) / this.runtime.stageHeight; + canvas.height = Number(args.num); + canvas.width = (Number(args.num) * this.runtime.stageWidth) / this.runtime.stageHeight; + this.runtime.renderer.dirty = true; + this.runtime.renderer.draw(); } /** @@ -993,11 +1085,11 @@ class WitCatMouse { * @returns {number} */ resolution() { - const canvas = this.canvas(); + const canvas = this.canvasSelf(); if (canvas === null) { return 0; } - return canvas.firstChild.height; + return canvas.height; } /** @@ -1174,8 +1266,8 @@ class WitCatMouse { * @returns {string} 转换后的文本 */ Uint8ArrayToString(fileData) { - var dataString = ""; - for (var i = 0; i < fileData.length; i++) { + let dataString = ""; + for (let i = 0; i < fileData.length; i++) { dataString += String.fromCharCode(fileData[i]); } return dataString @@ -1364,8 +1456,8 @@ class WitCatMouse { `; document.body.appendChild(div); - var modal = document.getElementById('myModal'); - var span = document.querySelector('.close'); + let modal = document.getElementById('myModal'); + let span = document.querySelector('.close'); //创建点击事件 span.onclick = function () { div.style.backgroundColor = '#00000000'; @@ -1709,28 +1801,39 @@ function exitFullscreen() { * @param {Element} element 需要被计算中心点的角色 * @param {Boolean} type 模式(true:最小化,false:全屏) */ -function resizeElementInParent(element, type) { +function resizeElementInParent(element, type, types, aspectRatio) { + let parentWidth, parentHeight; + if (type) { - var parent = element.parentElement; - var parentWidth = parent.clientWidth; - var parentHeight = parent.clientHeight; - } - else { - var parentWidth = screen.width; - var parentHeight = screen.height; + let parent + if (types === 'zoom') { + parent = element.parentElement.parentElement; + } + else { + parent = element.parentElement; + } + parentWidth = parent.clientWidth; + parentHeight = parent.clientHeight; + } else { + parentWidth = document.body.clientWidth; + parentHeight = document.body.clientHeight; } - var elementWidth = element.offsetWidth; - var elementHeight = element.offsetHeight; - - var widthRatio = parentWidth / elementWidth; - var heightRatio = parentHeight / elementHeight; - - var scale = Math.min(widthRatio, heightRatio); - - var newWidth = elementWidth * scale; - var newHeight = elementHeight * scale; - - element.style.width = newWidth + "px"; - element.style.height = newHeight + "px"; + let elementWidth = element.offsetWidth; + let elementHeight = element.offsetHeight; + + if (types === 'zoom') { + let widthRatio = parentWidth / elementWidth; + let heightRatio = parentHeight / elementHeight; + let scale = Math.min(widthRatio, heightRatio); + element.style.transform = 'scale(' + scale + ')'; + } else { + if (parentWidth / parentHeight > aspectRatio) { + element.style.height = parentHeight + 'px'; + element.style.width = parentWidth / (aspectRatio / (parentWidth / parentHeight)) + 'px'; + } else { + element.style.width = parentWidth + 'px'; + element.style.height = parentHeight / (aspectRatio / (parentWidth / parentHeight)) + 'px'; + } + } } From 370ca42f8db87597cba4772d582c412bbce9cf76 Mon Sep 17 00:00:00 2001 From: wit_cat <96361142+little-starts@users.noreply.github.com> Date: Sat, 6 Jan 2024 20:30:59 +0800 Subject: [PATCH 3/6] More_Mouse V3.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(block):下线全屏积木 --- wit_cat/More_Mouse.js | 89 +------------------------------------------ 1 file changed, 2 insertions(+), 87 deletions(-) diff --git a/wit_cat/More_Mouse.js b/wit_cat/More_Mouse.js index d5dd6d8a..53490320 100644 --- a/wit_cat/More_Mouse.js +++ b/wit_cat/More_Mouse.js @@ -336,6 +336,7 @@ class WitCatMouse { opcode: 'fill', blockType: 'command', text: this.formatMessage('WitCatMouse.fill'), + hideFromPalette: true, arguments: { set: { type: 'bool', @@ -968,93 +969,7 @@ class WitCatMouse { * @deprecated */ fill(args) { - const canvas = this.canvasSelf(); - if (canvas === null) { - return 0; - } - if (this.fillNum < 3) { - if (args.set == 'true') { - this.fillNum = 0; - let fills = confirm(this.formatMessage('WitCatMouse.fillask.1') + this.fillNum + this.formatMessage('WitCatMouse.fillask.2')) - if (fills) { - launchFullscreen(this.canvas().parentElement.parentElement); - this.canvas().parentElement.parentElement.style.overflow = 'visible'; - this.canvas().parentElement.parentElement.style.display = 'flex'; - this.canvas().parentElement.parentElement.style.alignItems = 'center'; - this.canvas().parentElement.style.display = 'flex'; - this.canvas().parentElement.style.alignItems = 'center'; - this.canvas().style.display = 'flex'; - this.canvas().style.alignItems = 'center'; - setTimeout(() => { - setTimeout(() => { - resizeElementInParent(this.canvas().parentElement, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - resizeElementInParent(this.canvas(), false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - resizeElementInParent(this.canvas().nextSibling.firstChild, false, 'zoom'); - resizeElementInParent(canvas, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - this.runtime.renderer.dirty = true; - this.runtime.renderer.draw(); - let button = document.getElementsByClassName('gandi_button_btn_dCMn2 gandi_stage-header_stage-button_hkl9B')[0] || - document.getElementsByClassName('action-item-P9SP6')[0] || - document.getElementsByClassName('c-actionItem')[0]; - if (button.innerHTML.includes("进入") || button.innerHTML.includes("M12.5 7.5l5-5m0 0h-5m5 0v5m-10 0l-5-5m0 0v5m0-5h5m0 10l-5 5m0 0h5m-5 0v-5m10 0l5 5m0 0v-5m0 5h-5")) { - button.click(); - } - }, 100); - document.addEventListener("fullscreenchange", () => { - if (!document.fullscreenElement) { - console.log("111") - this.fillEvent[1].disconnect(); - setTimeout(() => { - this.canvas().style = ""; - canvas.style.width = "100%"; - canvas.style.height = "100%"; - resizeElementInParent(this.canvas().parentElement, true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - resizeElementInParent(this.canvas(), true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - this.canvas().style.width = "auto"; - this.canvas().style.height = "auto"; - this.canvas().parentElement.style.width = "auto"; - this.canvas().parentElement.style.height = "auto"; - resizeElementInParent(this.canvas().nextSibling.firstChild, true, 'zoom'); - resizeElementInParent(canvas, true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - this.runtime.startHats(`${witcat_more_mouse_extensionId}_whenOutFill`); - }, 100); - } - }, { once: true }); - const config = { childList: true, attributeFilter: ['style'] }; - this.fillEvent[1].observe(canvas, config); - if (this.fillEvent[0] === null) { - this.fillEvent[0] = window.addEventListener('resize', function reSizeFill() { - if (document.fullscreenElement) { - resizeElementInParent(this.canvas().parentElement, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - resizeElementInParent(this.canvas(), false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - resizeElementInParent(this.canvas().nextSibling.firstChild, false, 'zoom'); - resizeElementInParent(canvas, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - } - }.bind(this)); - } - }, 100); - } - else { - this.fillNum++; - } - } else { - exitFullscreen(); - this.fillEvent[1].disconnect(); - setTimeout(() => { - this.canvas().style = ""; - canvas.style.width = "100%"; - canvas.style.height = "100%"; - resizeElementInParent(this.canvas().parentElement, true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - resizeElementInParent(this.canvas(), true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - this.canvas().style.width = "auto"; - this.canvas().style.height = "auto"; - this.canvas().parentElement.style.width = "auto"; - this.canvas().parentElement.style.height = "auto"; - resizeElementInParent(this.canvas().nextSibling.firstChild, true, 'zoom'); - resizeElementInParent(canvas, true, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - }, 100); - } - } + console.warn('全屏因浏览器兼容问题已下线,并不会再上线\nFull screen has been taken offline due to browser compatibility issues. And never back online.') } whenOutFill() { From f00091fcb9d880eb6d3adc0bbf4b7a2d2ed81f24 Mon Sep 17 00:00:00 2001 From: wit_cat <96361142+little-starts@users.noreply.github.com> Date: Sat, 6 Jan 2024 20:38:16 +0800 Subject: [PATCH 4/6] More_Mouse V3.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(code):删除多余的函数 --- wit_cat/More_Mouse.js | 49 ------------------------------------------- 1 file changed, 49 deletions(-) diff --git a/wit_cat/More_Mouse.js b/wit_cat/More_Mouse.js index 53490320..c7a7f9a8 100644 --- a/wit_cat/More_Mouse.js +++ b/wit_cat/More_Mouse.js @@ -2,7 +2,6 @@ const witcat_more_mouse_picture = "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSI const witcat_more_mouse_icon = "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIxNzcuMDg4NTUiIGhlaWdodD0iMTc3LjA4ODU1IiB2aWV3Qm94PSIwLDAsMTc3LjA4ODU1LDE3Ny4wODg1NSI+PGRlZnM+PGxpbmVhckdyYWRpZW50IHgxPSIyNDcuMDc3MyIgeTE9IjExOS4xNDIzMSIgeDI9IjI0Ny4wNzczIiB5Mj0iMjIyLjA2OTQ4IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgaWQ9ImNvbG9yLTEiPjxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIvPjxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iI2U1ZWFmMyIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxnIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0xNTEuNDU1NzYsLTkxLjQ1NTc0KSI+PGcgZGF0YS1wYXBlci1kYXRhPSJ7JnF1b3Q7aXNQYWludGluZ0xheWVyJnF1b3Q7OnRydWV9IiBmaWxsLXJ1bGU9Im5vbnplcm8iIHN0cm9rZS13aWR0aD0iMCIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBzdHJva2UtZGFzaGFycmF5PSIiIHN0cm9rZS1kYXNob2Zmc2V0PSIwIiBzdHlsZT0ibWl4LWJsZW5kLW1vZGU6IG5vcm1hbCI+PHBhdGggZD0iTTE1MS40NTU3NiwyNjguNTQ0Mjl2LTE3Ny4wODg1NWgxNzcuMDg4NTV2MTc3LjA4ODU1eiIgZmlsbD0iIzhlYWNlMSIgc3Ryb2tlPSJub25lIiBzdHJva2UtbGluZWNhcD0iYnV0dCIvPjxwYXRoIGQ9Ik0yMzguMjAwNywyNDAuODU3NjlsLTEwLjQ4NDQxLC0zNS4xNjgwMmwtMjEuMzAyNDQsMjEuOTAwNjJsNC40Njc1OCwtMTA0Ljg5OTUxbDYzLjcxNjM3LDc5LjQ1MzQ5bC0yOS4yODgyNCwtMS41OTkxMmw5LjIwMDkxLDM0LjM1MTE1eiIgZmlsbD0iIzcyOGJiNSIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2UtbGluZWNhcD0icm91bmQiLz48cGF0aCBkPSJNMjQ1Ljg4MDQ3LDIyMi4wNjk0OGwtMTEuOTY4MjcsLTMwLjUxOTFsLTIwLjM0NjA3LDIwLjM0NjA3di05Mi43NTQxM2w2Ny4wMjIzNCw2Ny4wMjIzNGgtMjkuMzIyMjdsMTAuNjUxNTEsMjkuODYwM3oiIGZpbGw9InVybCgjY29sb3ItMSkiIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIi8+PC9nPjwvZz48L3N2Zz48IS0tcm90YXRpb25DZW50ZXI6ODguNTQ0MjQ0OTk5OTk5OTk6ODguNTQ0MjU1LS0+"; -// eslint-disable-next-line camelcase const witcat_more_mouse_extensionId = 'WitCatMouse'; /** @typedef {string|number} SCarg 来自Scratch圆形框的参数,虽然这个框可能只能输入数字,但是可以放入变量,因此有可能获得数字和文本,需要同时处理 */ @@ -85,23 +84,6 @@ class WitCatMouse { */ this.titleDiv = null; - /** - * 拒绝全屏次数 - */ - this.fillNum = 0; - - /** - * 全屏监听事件缓存 - */ - this.fillEvent = [null, null]; - - this.fillEvent[1] = new MutationObserver((mutationsList) => { - resizeElementInParent(mutationsList[0].target.parentElement.parentElement, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - resizeElementInParent(mutationsList[0].target.parentElement, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - resizeElementInParent(mutationsList[0].target.parentElement.nextSibling.firstChild, false, 'zoom'); - resizeElementInParent(mutationsList[0].target, false, 'aspectRatio', this.runtime.stageWidth / this.runtime.stageHeight); - }); - this.runtime = runtime; /** @@ -1680,37 +1662,6 @@ window.tempExt = { } }; -/** - * 将元素全屏 - * @param {Element} element 需要全屏的元素 - */ -function launchFullscreen(element) { - if (element.requestFullscreen) { - element.requestFullscreen(); - } else if (element.mozRequestFullScreen) { - element.mozRequestFullScreen(); - } else if (element.msRequestFullscreen) { - element.msRequestFullscreen(); - } else if (element.webkitRequestFullscreen) { - element.webkitRequestFullScreen(); - } -} - -/** - * 退出全屏模式 - */ -function exitFullscreen() { - if (document.exitFullscreen) { - document.exitFullscreen(); - } else if (document.msExitFullscreen) { - document.msExitFullscreen(); - } else if (document.mozCancelFullScreen) { - document.mozCancelFullScreen(); - } else if (document.webkitExitFullscreen) { - document.webkitExitFullscreen(); - } -} - /** * 计算舞台在全屏/非全屏的大小 * @param {Element} element 需要被计算中心点的角色 From b2c0cface96e5a0ef1110d333ca7673527af5756 Mon Sep 17 00:00:00 2001 From: wit_cat <96361142+little-starts@users.noreply.github.com> Date: Fri, 26 Jan 2024 17:32:09 +0800 Subject: [PATCH 5/6] More_Mouse V3.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(code):修复设置分辨率导致gandi渲染出问题的BUG --- wit_cat/More_Mouse.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/wit_cat/More_Mouse.js b/wit_cat/More_Mouse.js index c7a7f9a8..c875f579 100644 --- a/wit_cat/More_Mouse.js +++ b/wit_cat/More_Mouse.js @@ -38,6 +38,11 @@ class WitCatMouse { */ this.MouseWheel = 0; + /** + * 上次设置分辨率的时间 + */ + this.LastSet = 0; + /** * 鼠标速度重置计时器 * @type {null|number} @@ -967,14 +972,20 @@ class WitCatMouse { * @deprecated */ setfill(args) { - const canvas = this.canvasSelf(); - if (canvas === null) { - return 0; + if (Date.now() - this.LastSet > 1000) { + this.LastSet = Date.now(); + const canvas = this.canvasSelf(); + if (canvas === null) { + return 0; + } + if (Number(args.num) < window.screen.height) { + this.runtime.renderer.resize((Number(args.num) * this.runtime.stageWidth) / this.runtime.stageHeight, Number(args.num)); + } else { + console.warn("分辨率超过屏幕,将产生额外性能消耗\nResolution exceeding the screen will incur additional performance costs"); + } + } else { + console.warn("设置分辨率太过频繁\nSetting the resolution too often"); } - canvas.height = Number(args.num); - canvas.width = (Number(args.num) * this.runtime.stageWidth) / this.runtime.stageHeight; - this.runtime.renderer.dirty = true; - this.runtime.renderer.draw(); } /** From c8df939973d941cf7d4213503a716fff2d554145 Mon Sep 17 00:00:00 2001 From: wit_cat <96361142+little-starts@users.noreply.github.com> Date: Mon, 11 Mar 2024 13:09:51 +0800 Subject: [PATCH 6/6] More_Mouse V3.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pref(code):优化鼠标滚轮老是卡住的问题,减小概率 --- wit_cat/More_Mouse.js | 62 +++++-------------------------------------- 1 file changed, 7 insertions(+), 55 deletions(-) diff --git a/wit_cat/More_Mouse.js b/wit_cat/More_Mouse.js index c875f579..bcbc286c 100644 --- a/wit_cat/More_Mouse.js +++ b/wit_cat/More_Mouse.js @@ -1630,19 +1630,13 @@ class WitCatMouse { }, 50); }); // 给页面绑定滑轮滚动事件 - document.addEventListener( - 'wheel', - (e) => { - this.MouseWheel = e.deltaY; - if (this.timer !== null) { - clearTimeout(this.timer); - } - this.timer = setTimeout(() => { - this.MouseWheel = 0; - }, 30); - }, - { capture: true } - ); + document.addEventListener('wheel', (e) => { + clearTimeout(this.timer); + this.MouseWheel = e.deltaY; + this.timer = setTimeout(() => { + this.MouseWheel = 0; + }, 30); + }, { capture: true }); window.addEventListener('deviceorientation', (e) => { this.Gyroscope = e; }); @@ -1672,45 +1666,3 @@ window.tempExt = { } } }; - -/** - * 计算舞台在全屏/非全屏的大小 - * @param {Element} element 需要被计算中心点的角色 - * @param {Boolean} type 模式(true:最小化,false:全屏) - */ -function resizeElementInParent(element, type, types, aspectRatio) { - let parentWidth, parentHeight; - - if (type) { - let parent - if (types === 'zoom') { - parent = element.parentElement.parentElement; - } - else { - parent = element.parentElement; - } - parentWidth = parent.clientWidth; - parentHeight = parent.clientHeight; - } else { - parentWidth = document.body.clientWidth; - parentHeight = document.body.clientHeight; - } - - let elementWidth = element.offsetWidth; - let elementHeight = element.offsetHeight; - - if (types === 'zoom') { - let widthRatio = parentWidth / elementWidth; - let heightRatio = parentHeight / elementHeight; - let scale = Math.min(widthRatio, heightRatio); - element.style.transform = 'scale(' + scale + ')'; - } else { - if (parentWidth / parentHeight > aspectRatio) { - element.style.height = parentHeight + 'px'; - element.style.width = parentWidth / (aspectRatio / (parentWidth / parentHeight)) + 'px'; - } else { - element.style.width = parentWidth + 'px'; - element.style.height = parentHeight / (aspectRatio / (parentWidth / parentHeight)) + 'px'; - } - } -}