From 27c392452280cba32aeebceeb2292fa821fdf9cf Mon Sep 17 00:00:00 2001 From: Yukimura Aoi Date: Sat, 5 Oct 2024 16:40:48 +0800 Subject: [PATCH] =?UTF-8?q?v0.2.1=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 103 +++++++++++++++++++++++++++++++++++--------------- manifest.json | 2 +- preview.png | Bin 65058 -> 76934 bytes 3 files changed, 74 insertions(+), 31 deletions(-) diff --git a/main.js b/main.js index 049b609..4f6ddb0 100644 --- a/main.js +++ b/main.js @@ -4,7 +4,7 @@ let rvN, v, c, cover, cvUrlCache, accentC, textC, textCT13, textCT31, textCT56, , pO = `` , pC = `` , readCfg = JSON.parse(localStorage.getItem("PiPWindowSettings")) -, cfgDefault = ({whenClose: "none", whenBack: "back", autoHideMainWindow: false, customFonts: "\"Microsoft Yahei UI\", system-ui", showAlbum: true, moreRedraws: false, resolutionRatio: "auto"}) +, cfgDefault = ({whenClose: "none", whenBack: "back", autoHideMainWindow: false, customFonts: "\"Microsoft Yahei UI\", system-ui", showAlbum: true, moreRedraws: false, resolutionRatio: "auto", aspectRatio: "2:1"}) readCfg = {...cfgDefault, ...readCfg} //缺失配置啥的处理一下 window.PiPWShowRefrshing = (x=true)=>{if(x==true){showRefrshing=true;return true}else if(x==false){showRefrshing=false;return false}} function cE(n, d=document) {return d.createElement(n)} @@ -59,9 +59,11 @@ HTMLCanvasElement.prototype.toPiP = function(){ v.addEventListener("pause", ()=>{ncmPause()}) //小窗打开/关闭逻辑 v.addEventListener("enterpictureinpicture", ()=>{ console.log("PiPW Log: PiP窗口已创建", v) + let s = betterncm.ncm.getPlayingSong() + if (!s) {s=({state:1})} if (readCfg.autoHideMainWindow) {mwf.cef.R$call("winhelper.showWindow", "hide")} tipMsg("已打开小窗"); q("#PiPW-Toggle svg").innerHTML=pC; q("#PiPW-Toggle").setAttribute("style", "fill: currentColor; opacity: 1"); - if (player.playState=="stop"&&!q(".m-player:not(#main-player):not(.f-dn)")) {v.pause()} DontPlay=false + if (s.state==1) {v.pause()} DontPlay=false }); v.addEventListener("leavepictureinpicture", ()=>{ DontPause=true; let p = v.paused tipMsg("已关闭小窗"); q("#PiPW-Toggle svg").innerHTML=pO; q("#PiPW-Toggle").setAttribute("style", ""); @@ -281,17 +283,21 @@ async function loadPiP(isToPiP=true, from="unknow") { if (colorPick()=="reCv") {reloadCover();} /*创建canvas*/ - if (!c) { - c = cE("canvas"); - console.log("PiPW Log: canvas元素已创建", c); - } - if (c.height != r || c.width != r*2) { - c.height = r; c.width = r*2; reloadCover() - } - if (isToPiP && !PiPE) { - DontPlay=true; //解决打开小窗时自动播放的问题 - c.toPiP(); - reloadCover() + loadC() + function loadC() { + let [w, h] = readCfg.aspectRatio.split(":").map(Number), rw = Math.round(r*(w/h)) //因为width不能设为小数 + if (!c) { + c = cE("canvas"); + console.log("PiPW Log: canvas元素已创建", c); + } + if (c.width != rw || c.height != r) { + c.width = rw; c.height = r; reloadCover() + } + if (isToPiP && !PiPE) { + DontPlay=true; //解决打开小窗时自动播放的问题 + c.toPiP(); + reloadCover() + } } function reloadCover() { @@ -406,14 +412,14 @@ async function loadPiP(isToPiP=true, from="unknow") { cC.fillStyle = accentC; cC.fillRect(pbMgL, pbMgT, (c.width-pbMgL)*tP, o5); /*进度条*/ - if(showRefrshing){console.log(`PiPW Log: 重绘完成,当前分辨率${r}x${r*2}, 请求来自${from}`)} + if(showRefrshing){console.log(`PiPW Log: 重绘完成,当前分辨率${c.width}x${c.height}, 请求来自${from}`)} } catch (e) { console.error("PiPW Error: 绘制出错,详情:\n", e);tipMsg("<canvas>绘制出错,详见JavaScript控制台", "err") } } plugin.onAllPluginsLoaded(()=>{load()}); -function load() {A();B();C();D();E() +function load() {A();B();C();D();E();F() if (readCfg.moreRedraws) {setInterval(()=>{loadPiP(false, "setInterval()")},100)} async function A() { //监听播放时长变动 await betterncm.utils.waitForElement(".m-player time"); @@ -451,7 +457,25 @@ function load() {A();B();C();D();E() subtree: true, }); } - async function D() { //向歌曲信息旁添加PiP开关 + async function D() { //监听私人漫游暂停/开始播放变动 + await betterncm.utils.waitForElement(".m-player-fm .btnp-play"); + new MutationObserver(() => { + let PiPE = document.pictureInPictureElement, s = betterncm.ncm.getPlayingSong().state + if (PiPE&&PiPE.id=="PiPW-VideoE") {if (s==2) {PiPE.play()} else if (s==1) {PiPE.pause()}} + }).observe(q(".m-player-fm .btnp-play"), {attributeFilter: ["data-action"]}) + } + async function E() { //监听颜色变动 + let A = qAll("html, body"); + for(i = 0; i < A.length; i++){ + new MutationObserver(() => { + setTimeout(()=>{colorPick()}, 100) + }).observe(A[i], { + attributeFilter: ["style", "class"], + characterData: false, + }); + }; + } + async function F() { //向歌曲信息旁添加PiP开关 await betterncm.utils.waitForElement(".m-pinfo h3"); let b = cE("div"); b.id = "PiPW-Toggle"; b.classList.add("icn", "f-cp"); @@ -468,17 +492,6 @@ function load() {A();B();C();D();E() subtree: true, }); } - async function E() { //监听颜色变动 - let A = qAll("html, body"); - for(i = 0; i < A.length; i++){ - new MutationObserver(() => { - setTimeout(()=>{colorPick()}, 100) - }).observe(A[i], { - attributeFilter: ["style", "class"], - characterData: false, - }); - }; - } } async function writeCfg(Cfg) { //写配置 @@ -786,7 +799,7 @@ plugin.onConfig(()=>{ }
-

PiPWindow

0.2.0

+

PiPWindow

0.2.1


by

@@ -878,7 +891,38 @@ plugin.onConfig(()=>{

缩短重绘间隔 (可能有性能损耗,重载生效)


-

渲染分辨率 (宽高比2:1)

+

窗口宽高比

+
+
+ +

16:9

+
+
+ +

2:1

+
+
+ +

21:9

+
+
+ +

3:1

+
+
+

渲染分辨率