mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
3.5 KiB
JavaScript
1 line
3.5 KiB
JavaScript
(()=>(e,t)=>{const n=async()=>{const{VideoSpeedController:n}=await t.importAsync("video-speed-controller");const{calcOrder:s,minValue:a,maxValue:i,stepValue:r,errorMessageDuration:o}=await t.importAsync("video-speed-common");const l=()=>{const e=n.supportedRates.slice(-1)[0]+r;return e>i?null:e};const d=t=>{const a=document.createElement("li");a.innerText=n.formatSpeedText(t);a.classList.add(n.classNameMap.speedMenuItem,"extended");a.dataset.value=t.toString();a.style.order=s(t);const i=document.createElement("i");i.classList.add("mdi","mdi-close-circle");i.addEventListener("click",(()=>{e.extendVideoSpeedList=_.pull(e.extendVideoSpeedList,t);a.remove()}));a.append(i);return a};const p=()=>{const t=e=>{const t=l();e.setAttribute("min",t?e.value=t.toString():(e.value="",a.toString()))};const s=document.createElement("li");s.classList.add(n.classNameMap.speedMenuItem);const p=document.createElement("i");p.classList.add("mdi","mdi-playlist-plus");const c=document.createElement("input");c.classList.add("add-speed-entry");c.setAttribute("type","number");c.setAttribute("max",i.toString());c.setAttribute("step",r.toString());c.setAttribute("title","增加新的倍数值");t(c);c.addEventListener("keydown",(r=>{if(r.key==="Enter"){const r=parseFloat(c.value);if(!isFinite(r)){logError("无效的倍数值",o);return false}if(r<a){logError("倍数值太小了",o);return false}if(r>i){logError("倍数值太大了",o);return false}if(n.supportedRates.includes(r)){logError("不能重复添加已有的倍数值",o);return false}e.extendVideoSpeedList.push(r);e.extendVideoSpeedList=n.extendedSupportedRates;let l=s.nextElementSibling;while(!l.dataset.value||parseFloat(l.dataset.value)>n.nativeSupportedRates.slice(-1)[0]&&r<parseFloat(l.dataset.value)){l=l.nextElementSibling}l.before(d(r));t(c)}}));s.prepend(p,c);c.style.display="none";s.addEventListener("mouseenter",(()=>{t(c);c.style.display="inline";p.style.display="none";c.focus()}));s.addEventListener("mouseleave",(()=>{p.style.display="inline";c.style.display="none"}));return s};t.applyStyleFromText(`\n .${n.classNameMap.speedContainer} .${n.classNameMap.speedMenuItem}:first-child .mdi-playlist-plus {\n font-size: 1.5em;\n }\n .${n.classNameMap.speedContainer} .${n.classNameMap.speedMenuItem}:first-child input {\n font-size: inherit;\n color: inherit;\n line-height: inherit;\n background: transparent;\n outline: none;\n width: 100%;\n border: none;\n text-align: center;\n }\n .${n.classNameMap.speedMenuItem} .mdi-close-circle {\n color: inherit;\n opacity: 0.5;\n display: none;\n position: absolute;\n right: 4px;\n }\n .${n.classNameMap.speedMenuItem}:not(.${n.classNameMap.active}):hover .mdi-close-circle {\n display: inline;\n }\n .${n.classNameMap.speedMenuItem} .mdi-close-circle:hover {\n opacity: 1;\n transition: all .3s;\n }\n /* https://stackoverflow.com/a/4298216 */\n /* Chrome */\n .add-speed-entry::-webkit-outer-spin-button,\n .add-speed-entry::-webkit-inner-spin-button {\n -webkit-appearance: none;\n margin: 0;\n }\n /* Firefox */\n .add-speed-entry[type=number] {\n -moz-appearance:textfield;\n }\n .${n.classNameMap.speedMenuList} {\n display: flex;\n flex-direction: column;\n overflow-y: auto;\n max-height: 360px;\n }\n`,"extend-video-speed-style");const c=n.extendedSupportedRates.map((e=>d(e))).reverse();c.unshift(p());return c};(async()=>{const{VideoSpeedController:e}=await t.importAsync("video-speed-controller");e.init()})();return{export:{getExtraSpeedMenuItemElements:n}}})(); |