// ==UserScript== // @name:en Userscript Helper for Flat-Style Netease Music Userstyle 适用于网易云音乐扁平风格样式表的辅助用户脚本 // @description:en Provides a better experience for Flat-Style Netease Music Userstyle. 为网易云音乐扁平风格样式表提供更佳的用户体验。 // @name:zh 适用于网易云音乐扁平风格样式表的辅助用户脚本 // @description:zh 为网易云音乐扁平风格样式表提供更佳的用户体验。 // @name 适用于网易云音乐扁平风格样式表的辅助用户脚本 // @description 为网易云音乐扁平风格样式表提供更佳的用户体验。 // @namespace wTonyChen.flatnmusich // @version 0.2.6-0.9.6 // @author wTonyChen // @copyright 2021 wTonyChen (https://github.com/wTonyChen) // @compatible chrome 90+ // @compatible edge 90+ // @compatible opera 74+ // @compatible firefox 88+ // @license GPL-3.0-or-later // @homepage https://wtonychen.github.io/flatnmusic/ // @supportURL https://github.com/wTonyChen/flatnmusic/issues // @match http*://music.163.com/* // @run-at document-end // @grant none // @downloadURL none // ==/UserScript== !(function () { "use strict"; let e = "wk-fnm-hi-cfg", t = document.querySelector("." + e); t || ((t = document.createElement("div")), (t.className = e), document.body.appendChild(t)); let a, s = getComputedStyle(t), l = { 86: "1f603", 85: "1f60a", 359: "263a", 95: "1f60d", 363: "1f618", 96: "1f631", 356: "1f62d", 362: "1f619", 352: "1f633", 87: "1f61e", 343: "1f601", 348: "1f61d", 353: "1f612", 361: "1f621", 341: "1f60f", 97: "1f613", 346: "1f616", 354: "1f630", 350: "1f628", 351: "1f637", 357: "1f602", 355: "1f635", 115: "1f47f", 360: "1f604", 94: "1f61c", 342: "1f614", 358: "1f622", 33: "2764", 34: "1f494", 303: "1f498", 309: "2b50", 314: "1f4a2", 89: "1f4a9", 13: "1f44d", 372: "1f44e", 14: "1f64f", 379: "1f46b", 380: "1f46f", 374: "1f645", 262: "1f481", 106: "1f48f", 376: "1f491", 367: "1f444", 81: "1f436", 78: "1f431", 100: "1f437", 459: "1f430", 450: "1f424", 461: "1f414", 116: "1f47b", 411: "1f385", 101: "1f47d", 52: "1f48e", 107: "1f381", 0: "1f466", 1: "1f467", 337: "1f382", 186: "1f51e", 312: "2b55", 313: "274c", }, n = "/style/web2/emt/emoji_", i = (e) => { let t = s.getPropertyValue("--" + e); if (t) try { t && t.indexOf("/") > -1 && (t = decodeURIComponent(t.replace(/\//g, "%"))); } catch (e) {} return ( ((0 === t.indexOf('"') && t.lastIndexOf('"') === t.length - 1) || (0 === t.indexOf("'") && t.lastIndexOf("'") === t.length - 1)) && (t = t.substr(1, t.length - 2)), t ); }, r = (e) => { let t; return window.localStorage && (t = localStorage.getItem(e)), t; }, o = (e, t) => { window.localStorage && localStorage.setItem(e, t); }, c = i("wkhi-a"), x = i("wkhi-b"); if (!x) return void t.parentElement.removeChild(t); document.documentElement.setAttribute("wk-style-assist", "true"); let d = r("wkoptin") || !1, p = function () { let e = arguments[0]; for (let t = 1; t < arguments.length; t++) { let a = RegExp("\\{" + t + "\\}", "g"); e = e.replace(a, arguments[t]); } return e; }; ((e) => { let t, a = 0, s = !1, l = document.querySelector("#g-topbar"), n = document.querySelector("#g_iframe"), i = 0, o = 0, c = !0; if (!l || !Object.is(window.self, window.top)) return; let x = 1.6 * l.getBoundingClientRect().height, d = (e) => { t && t.cancel(), (o = 0), (i = 0), (a = 0), (c = !1), (t = l.animate([{ transform: "translateY(0)" }], { duration: 200, fill: "backwards", easing: "cubic-bezier(.16,1,.29,.99)", })), (t.onfinish = (e) => { (c = !0), (l.style.transform = "translateY(0)"); }); }; n.addEventListener("load", (e) => { n.contentWindow.addEventListener("beforeunload", d), n.contentDocument.addEventListener("scroll", (e) => { c || t.cancel(), (a = n.contentWindow.scrollY), s || (window.requestAnimationFrame((e) => { ((e) => { if (r("wksdscrolling")) { let t = e - i; (o = Math.max(Math.min(o + t, x), 0)), (l.style.top = "0 !important"), (l.style.transform = `translateY(-${o}px)`); } else (l.style.top = ""), (l.style.transform = ""), (o = 0); i = e; })(a), (s = !1); }), (s = !0)); }); }); })(), r("wklrctrans") && document.body.classList.add("wk-playlist-applied"), (DocumentFragment.prototype.appendChildHost = DocumentFragment.prototype.appendChild), (DocumentFragment.prototype.appendChild = function () { if ( r("wksplayinguiani") && arguments[0].classList.contains("m-layer") && arguments[0].parentElement ) { let e = arguments[0].cloneNode(!0); arguments[0].parentElement.insertBefore(e, arguments[0]), e.addEventListener("animationend", (t) => { e.remove(); }), e.classList.add("hidden"); } let e = "", t = r("wkspipfont"), a = r("wkspipfsize"), s = r("wkspipletterspacing"), l = r("wkspipwordspacing"); if ( ("STYLE" == arguments[0].tagName && (r("wklrctrans") && (e += ".container>.line>.compare{display:none}"), t && (e += `.container{font-family:"${t.replace( /"/g, '\\"' )}" !important}`), a && !isNaN(+a) && (e += `.container>.line>.compare,.container>.line>.origin{font-size:${+a}px}`), s && !isNaN(+s) && (e += `.container{letter-spacing:${+s}px}`), l && !isNaN(+l) && (e += `.container{word-spacing:${+l}px}`), e && (this.appendChildHost.call( this, document.createElement("style") ).innerHTML = e)), !r("wksplayinguiani") || "g_playlist" != arguments[0].id) ) return this.appendChildHost.call(this, ...arguments); arguments[0].classList.add("hidden"), document.body.classList.remove("wk-playlist-showing"); }), (Element.prototype.appendChildHost = Element.prototype.appendChild), (Element.prototype.appendChild = function () { return ( r("wksplayinguiani") && "g_playlist" == arguments[0].id && (arguments[0].classList.remove("hidden"), document.body.classList.add("wk-playlist-showing")), this.appendChildHost.call(this, ...arguments) ); }), r("wksfullpl") && ((e) => { let t = i("wkhi-c"), a = i("wkhi-d"); if (t && a) { (t = t.split("|")), (a = a.split("|")); for (let e = 0; e < t.length; e++) for (let n = 0; n < a.length; n++) (s = t[e]), (l = a[n]), (document.cookie = `${s};path=${l};max-age=3153600000`); var s, l; } })(), r("wkslowbrightness") && Object.is(window.self, window.top) && (document.documentElement.style.filter = "brightness(.5)"); let f = (e) => { if ( (r("wkshiresimages") && ((e) => { let t = document.querySelectorAll("img[data-src]"); for (let e = 0; e < t; e++) t[e].dataset.src && "" == t[e].src && (t[e].src = t[e].dataset.src); let a = document.querySelectorAll('img[src*="param="]'); for (let e = 0; e < a.length; e++) { let t = a[e].src.split("?")[0]; if (a[e].src != t) { let s = new Image(), l = (n) => { a[e] && (a[e].src.split("?")[0] == t && ((a[e].src = t), a[e].classList.add("wk-hires-loaded")), s.removeEventListener("load", l, !1)); }; s.addEventListener("load", l, !1), a[e].classList.remove("wk-hires-loaded"), (s.src = t); } } })(), r("wksemojisym") && ((e) => { let t = document.querySelectorAll(`img[src*="${n}"]`); for (let e = 0; e < t.length; e++) { let a = t[e].src.split(n)[1]; a && ((a = a.split(".")[0]), !isNaN(+a) && l[+a] && (t[ e ].src = `data:image/svg+xml;charset=utf-8,%26%23x${ l[+a] };`)); } })(), r("wklrctrans") && ((e) => { if (!Object.is(window.self, window.top)) return; let t = document.querySelectorAll( ".m-playbar .listlyric>p:not(.wk-upgraded)" ); for (let e = 0; e < t.length; e++) (t[e].innerText = t[e].innerText.split("\n")[0]), t[e].classList.add("wk-upgraded"); })(), r("wksimprovedlook")) ) { if ("user" == location.pathname.substring(1).split("/")[0]) { let e = document.querySelector(".m-proifo dt img"), t = document.querySelector(".g-bd"); e && e.src && t && (document.documentElement.classList.add("has-upb"), (t.style.cssText = `--upb:url("${e.src}")`)); let a = document.querySelector(".m-proifo .name .tit"), s = document.querySelector(".m-proifo .name #j-name-wrap"); a && s && ((s.dataset.wkUsernameFull = s.title = a.innerText), s.classList.add("wk-full-username")); } let e = document.querySelector(".g-wrap>.m-info .cover img"), t = document.querySelector(".g-wrap>.m-info"); e && t && (document.documentElement.classList.add("has-mib"), (t.style.cssText = `--mib:url("${e.src}")`)); } let t = location.hash && ("video" == location.hash.substring(2).split("?")[0].split("/")[0] || "mv" == location.hash.substring(2).split("?")[0].split("/")[0]), s = "/" == location.pathname, i = "video" == location.pathname.substring(1).split("/")[0] || "mv" == location.pathname.substring(1).split("/")[0]; if ( r("wksmusicsessionmeta") && "mediaSession" in navigator && (i || (s && !t)) ) { let t = document.querySelector( i ? ".n-mv .title h2" : ".m-playbar .words .name" ), s = document.querySelector( i ? ".n-mv .title .name" : ".m-playbar .words .by" ), l = document.querySelector( i ? ".m-ctvideo .poster .pic" : ".m-playbar .head img" ), n = [], r = (document.querySelector(i ? null : ".m-playbar .btns .prv"), document.querySelector( i ? ".m-ctvideo.z-play .controls .wrap .play" : ".m-playbar .btns .ply" ), document.querySelector(i ? null : ".m-playbar .btns .nxt"), document.querySelector(i ? ".m-ctvideo" : ".m-playbar .btns .ply")); (r = r ? r.classList.contains(i ? "z-play" : "pas") ? "playing" : r.classList.contains(i ? "z-pause" : "ply") ? "paused" : "none" : "none"), l && l.src && (n = [ { src: l.src.split("?")[0] + "?param=96y96", sizes: "96x96", type: "image/jpeg", }, { src: l.src.split("?")[0] + "?param=128y128", sizes: "128x128", type: "image/jpeg", }, { src: l.src.split("?")[0] + "?param=192y192", sizes: "192x192", type: "image/jpeg", }, { src: l.src.split("?")[0] + "?param=256y256", sizes: "256x256", type: "image/jpeg", }, { src: l.src.split("?")[0] + "?param=384y384", sizes: "384x384", type: "image/jpeg", }, { src: l.src.split("?")[0] + "?param=512y512", sizes: "512x512", type: "image/jpeg", }, { src: l.src.split("?")[0], sizes: "any", type: "image/jpeg" }, ]); try { let e = { title: t ? t.innerText : document.title, artist: s ? s.innerText : "", album: s ? s.innerText : "", artwork: n, }; !((e, t) => { if ("object" == typeof e) try { e = JSON.stringify(e); } catch (e) {} if ("object" == typeof t) try { t = JSON.stringify(t); } catch (e) {} return e == t; })(e, a) && i && ((a = e), (navigator.mediaSession.metadata = new MediaMetadata(a))); } catch (e) {} } }; f(), window.setInterval(f, 500), x && (function () { if ("/user/update" == location.pathname) { let e = (e) => { let t = document.querySelector("#baseBox"); if (t) { let e = `

辅助脚本设置辅助脚本版本:0.2.6-0.9.6样式表版本:${c}

    {1}
`, a = '
  • ', s = '
  • 修改 
  • ', l = [ { label: "样式表增强外观", lsm: "wksimprovedlook", }, { label: "显示歌单内全部音乐", lsm: "wksfullpl", }, { label: "显示高清图片", lsm: "wkshiresimages", }, { label: "视频页面媒体信息显示支持", lsm: "wksmusicsessionmeta", test: "'mediaSession' in navigator", }, { label: "顶栏动态固定 (忽略顶栏滚动状态设置)", lsm: "wksdscrolling", }, { label: "表情图片以系统 Emoji 表情显示", lsm: "wksemojisym", }, { label: "正在播放歌单界面和窗口的增强动画 (刷新页面应用更改)", lsm: "wksplayinguiani", }, { label: "隐藏正在播放界面和画中画歌词翻译", lsm: "wklrctrans", }, { label: "降低页面亮度 (刷新页面应用更改)", lsm: "wkslowbrightness", }, { label: "画中画显示字体名称 (换歌应用更改)", lsm: "wkspipfont", t: "t", }, { label: "画中画歌词字体大小 (像素,换歌应用更改)", lsm: "wkspipfsize", t: "n", }, { label: "画中画显示字间距 (像素,换歌应用更改)", lsm: "wkspipletterspacing", t: "n", }, { label: "画中画显示词间距 (像素,换歌应用更改)", lsm: "wkspipwordspacing", t: "n", }, ], n = ""; for (let e = 0; e < l.length; e++) { if (l[e].roi && !d) continue; let t = !0; if (l[e].test) { t = !1; try { t = !!window.eval(l[e].test); } catch (e) {} } if (!t) continue; let i = r(l[e].lsm); "n" == l[e].t || "t" == l[e].t ? (n += p( s, l[e].label, `${ isNaN(i) || 0 == i ? "" : `value="${i}" ` }data-wk-lsm="${l[e].lsm}" data-wk-t="${ l[e].t }" data-wk-l="${l[e].label}"` )) : (n += p( a, l[e].label, `${i ? "checked " : ""}data-wk-lsm="${l[e].lsm}"` )); } n = p(e, n); let i = document.createElement("div"); (i.className = "n-priv f-cb flatnmusic-settings"), (i.style.display = "none"), (i.innerHTML = n), i.addEventListener("change", (e) => { let t = e.target.closest("[data-wk-lsm]"), a = t.dataset.wkLsm; t && a && ("checkbox" == t.type ? o(a, t.checked ? "1" : "") : o(a, t.value)); }), t.appendChild(i), i.addEventListener("click", (e) => { let t = e.target.closest("[data-wk-t]"), a = t.dataset.wkLsm, s = t.dataset.wkT, l = t.dataset.wkL, n = r(a); if (t && a) { let e = window.prompt( "请输入" + l, n || "" ); if ("n" == s && isNaN(+e) && "" != e) return void alert("无效的值"); null != e && o(a, e || ""); } }); } }; window.addEventListener("load", e); } })(); })();