diff --git a/main.js b/main.js index b777fe3..d13ee35 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,6 @@ /*This plugin is licensed under the GNU/GPL-3.0*/ -let rvN, v, c, cover, cvUrlCache, songIdCache, songDataCache, accentC, textC, textCT13, textCT31, textCT56, textCT65, textCT80, bgC, bgCTSetting, bgCCache, tMsT, lrcCache, pLrcM, pLrcT, showRefrshing, thePiPWindow -, isVLsnAdded=false, DontPlay=false, DontPause=false, autoRatio, autoRatioValue=480, lastReRatio=0, nrLrc = false , lrcNowLoading = false, reRatioPending=false, debugMode=false +let rvN, v, c, cover, cvUrlCache, songIdCache, songDataCache, tMsT, lrcCache, pLrc, pLrcKeys, showRefrshing, thePiPWindow +, isVLsnAdded=false, DontPlay=false, DontPause=false, autoRatio, autoRatioValue=480, lastReRatio=0, playProgress=0, nrLrc = false , lrcNowLoading = false, reRatioPending=false, debugMode=false , t = "0:00/0:00", tC = 0, tT = 0, tP = 0, tR = 0 //显示用,Current,Total,PassedRate,Remaining , pdd = "M21 3C21.5523 3 22 3.44772 22 4V11H20V5H4V19H10V21H3C2.44772 21 2 20.5523 2 20V4C2 3.44772 2.44772 3 3 3H21ZM21 13C21.5523 13 22 13.4477 22 14V20C22 20.5523 21.5523 21 21 21H13C12.4477 21 12 20.5523 12 20V14C12 13.4477 12.4477 13 13 13H21Z" , pO = `` @@ -8,9 +8,10 @@ let rvN, v, c, cover, cvUrlCache, songIdCache, songDataCache, accentC, textC, te , readCfg = JSON.parse(localStorage.getItem("PiPWindowSettings")) , cfgDefault = ({ whenClose: "none", whenBack: "back", whenCloseOrBack_paused: "close", autoHideMainWindow: false - , showAlbum: true, originalLyricsBold: true, showTranslation: true, /*showLatinization: false,*/ lyricsTaperOff: true, lyricsMask: false, timeInfo: "CurrentTotal", lyricsFrom: "RNP", showLyricsErrorTip: true + , showAlbum: true, originalLyricsBold: false, showTranslation: true, /*showLatinization: false,*/ lyricsTaperOff: true, lyricsMask: true, timeInfo: "CurrentTotal", lyricsFrom: "LibLyric", showLyricsErrorTip: true , customFonts: "\"Segoe UI\", \"Microsoft Yahei UI\", system-ui", useJapaneseFonts: true, customJapaneseFonts: "\"Yu Gothic UI\", \"Meiryo UI\", \"Microsoft Yahei UI\", system-ui" , smoothProgessBar: false, resolutionRatio: "auto", aspectRatio: "2:1", customLoadingTxt: "正在载入猫猫…"}) +, color = ({accent: "", text: "", textT13: "", textT31: "", textT56: "", textT80: "", bg: "", bgT00: "", bgTSetting: ""}), colorCache = ({text: "", bg: ""}) 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)} @@ -125,28 +126,29 @@ function pipToggle() { } function colorPick() { //取色 - let textCT00, bgCT00; + let textTO, bgTO; function s(e, p) { return getComputedStyle(q(e)).getPropertyValue(p); } - accentC = s("body", "--themeC1"), textC = s("body", "color"); - if (q("body.material-you-theme")) {textC = s("body", "--md-accent-color-secondary")} - if (/rgba/.test(textC)) {textCT00 = textC.replace(/,([^,)]*)\)/, "")} - else {textCT00 = textC.replace(/rgb\(/, "rgba(").replace(/\)/, "")} - textC = `${textCT00})`, textCT80 = `${textCT00}, .8)`, textCT56 = `${textCT00}, .56)`, textCT31 = `${textCT00}, .31)`, textCT13 = `${textCT00}, .13)`; - bgC = s("body", "background-color"); - if (/rgba/.test(bgC)) {bgCT00 = bgC.replace(/,([^,)]*)\)/, "")} - else {bgCT00 = bgC.replace(/rgb\(/, "rgba(").replace(/\)/, "")} - bgC = `${bgCT00})`, bgCTSetting = `${bgCT00}, .3)`; - if (q("body.material-you-theme:not(.ncm-light-theme)")) {bgCTSetting = `${accentC.replace(/\)/, "")}, .1)`;} - if (bgC != bgCCache) {bgCCache=bgC;return"reHd"} - try {q("#PiPWSettingsStyle0").innerHTML=` + color.accent = s("body", "--themeC1"), color.text = s("body", "color"); + if (q("body.material-you-theme")) {color.text = s("body", "--md-accent-color-secondary")} + if (/rgba/.test(color.text)) {textTO = color.text.replace(/,([^,)]*)\)/, "")} + else {textTO = color.text.replace(/rgb\(/, "rgba(").replace(/\)/, "")} + color.text = `${textTO})`, color.textT80 = `${textTO}, .8)`, color.textT56 = `${textTO}, .56)`, color.textT31 = `${textTO}, .31)`, color.textT13 = `${textTO}, .13)`; + color.bg = s("body", "background-color"); + if (/rgba/.test(color.bg)) {bgTO = color.bg.replace(/,([^,)]*)\)/, "")} + else {bgTO = color.bg.replace(/rgb\(/, "rgba(").replace(/\)/, "")} + color.bg = `${bgTO})`, color.bgT00 = `${bgTO}, 0)`, color.bgTSetting = `${bgTO}, .3)`; + if (q("body.material-you-theme:not(.ncm-light-theme)")) {color.bgTSetting = `${color.accent.replace(/\)/, "")}, .1)`;} + try {let s0 = q("#PiPWSettingsStyle0"), s = ` #PiPWSettings { - --pipws-fg: ${accentC}; - --pipws-bg: ${bgCTSetting}; - --pipws-bg-wot: ${bgC}; - color: ${textC}; -}`} catch {} + --pipws-fg: ${color.accent}; + --pipws-bg: ${color.bgTSetting}; + --pipws-bg-wot: ${color.bg}; + color: ${color.text}; +}` + if (s0.innerHTML!=s) {s0.innerHTML=s} + } catch {} } async function loadPiP(isToPiP=true, from="unknow") { @@ -296,26 +298,48 @@ async function loadPiP(isToPiP=true, from="unknow") { }catch{} } } - async function getLrcLibLyric() { //无用,并不能对解析后的歌词做出什么反应 - if (lrcNowLoading) {return} + async function getLrcLibLyric() { + if (lrcNowLoading) {lyrics["M0"] = ldTxt;return} try { - let l = loadedPlugins.liblyric + let ll = loadedPlugins.liblyric if (nrLrc) { lrcNowLoading = true nrLrc = false - lrcCache = await l.getLyricData(data.id) - pLrcM = l.parseLyric(lrcCache.lrc.lyric) - pLrcT = l.parseLyric(lrcCache.tlyric.lyric) - console.log(lrcCache);console.log(pLrcM);console.log(pLrcT) + lrcCache = await ll.getLyricData(data.id) + pLrc = ll.parseLyric(lrcCache.lrc.lyric, lrcCache.tlyric?lrcCache.tlyric.lyric:"") + pLrcKeys = Object.keys(pLrc) + for (let i = 0; i < pLrcKeys.length; i++) { + let o = pLrc[i].originalLyric + pLrc[i].originalLyric = o.replace(/\s+/g, " ").trim(); + if (o == "") {pLrc[i].originalLyric = "· · ·", pLrc[i].translatedLyric = ""} + } + console.log(lrcCache);console.log(pLrc); lrcNowLoading = false } - } catch(e) {console.error(`PiPW Error: 获取歌词时出错,详情:\n${e}`);getLrcErr()} + let l = pLrcKeys.length + for (let i = 0; i < l; i++) { + if (playProgress*1000 > pLrc[i].time||pLrc[0].time!=0&&i==0) { + lyrics["M0"] = pLrc[i].originalLyric + lyrics["M1"] = i+1{/*封面(完毕)*/ cC.clearRect(0, 0, cvSize, cvSize); @@ -445,35 +469,35 @@ async function loadPiP(isToPiP=true, from="unknow") { if(showRefrshing){console.log(`PiPW Log: 歌曲封面绘制完成`)} } function drawRC() { - cC.beginPath(); cC.strokeStyle = bgC; cC.lineWidth = o5; xy = cvSize+o2; + cC.beginPath(); cC.strokeStyle = color.bg; cC.lineWidth = o5; xy = cvSize+o2; /*封面边框+圆角*/ cC.moveTo(xy, 0); cC.arcTo(xy, xy, 0, xy, o12); cC.lineTo(0, xy); cC.lineTo(xy, xy); cC.lineTo(xy, 0); cC.stroke(); } function drawBgAndInfo() { - cC.fillStyle = bgC; xy = cvSize; + cC.fillStyle = color.bg; xy = cvSize; cC.fillRect(xy, 0, c.width, xy+o5); /*head背景*/ - cC.beginPath(); cC.strokeStyle = bgC; cC.lineWidth = o5; xy = cvSize+o5; + cC.beginPath(); cC.strokeStyle = color.bg; cC.lineWidth = o5; xy = cvSize+o5; cC.moveTo(0, xy); cC.lineTo(c.width, xy); /*底边框*/ cC.stroke(); - cC.fillStyle = textC; cC.font = `${o55}px ${f}`; + cC.fillStyle = color.text; cC.font = `${o55}px ${f}`; cC.fillText(snM, txtMgL, o60); /*主名*/ - cC.fillStyle = textCT31; cC.font = `${o35}px ${f}`; + cC.fillStyle = color.textT31; cC.font = `${o35}px ${f}`; cC.fillText(snA==null?"":snA, txtMgL, o105); /*副名*/ - cC.fillStyle = textCT56; + cC.fillStyle = color.textT56; cC.fillText(sa, txtMgL, snA==null?o105:o150); /*歌手*/ } } cC.font = `${o30}px ${f}`; - cC.fillStyle = textCT56; + cC.fillStyle = color.textT56; let tW = cC.measureText(t).width cC.fillText(t, o15, cvSize+o35); /*时间*/ let pbMgT = cvSize+o21p5, pbMgL = tW+o30p5 - cC.fillStyle = textCT13; + cC.fillStyle = color.textT13; cC.fillRect(pbMgL, pbMgT, c.width-pbMgL, o5); /*进度条背景*/ - cC.fillStyle = accentC; + cC.fillStyle = color.accent; cC.fillRect(pbMgL, pbMgT, (c.width-pbMgL)*tP, o5); /*进度条*/ if(showRefrshing){console.log(`PiPW Log: 重绘完成,当前分辨率${c.width}x${c.height}, 请求来自${from}`)} @@ -484,8 +508,8 @@ async function loadPiP(isToPiP=true, from="unknow") { plugin.onAllPluginsLoaded(()=>{load()}); function load() {B();C();E();F() - legacyNativeCmder.appendRegisterCall("PlayProgress", "audioplayer", (_, progress) => { - let pZ = Math.floor(progress); if(pZ>tC||progress { + playProgress = p; let pZ = Math.floor(p); if(pZ>tC||p{ cP.innerHTML = `
-

PiPWindow

0.3.0

+

PiPWindow

0.3.1


by

@@ -949,7 +973,7 @@ plugin.onConfig(()=>{ -

将歌名翻译/别名替换为专辑名

+

显示专辑名 (而非翻译/别名)