mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
3.2 KiB
JavaScript
1 line
3.2 KiB
JavaScript
(()=>(e,t)=>{const n=async()=>{const{VideoSpeedController:n}=await t.importAsync("video-speed-controller");const s=.5;const i=.0625;const a=16;const r=()=>n.supportedRates.slice(-1)[0]+s;const o=t=>{const s=document.createElement("li");s.innerText=n.formatSpeedText(t);s.classList.add(n.classNameMap.speedMenuItem,"extended");s.dataset.value=t.toString();const i=document.createElement("i");i.classList.add("mdi","mdi-close-circle");i.addEventListener("click",(()=>{e.extendVideoSpeedList=_.pull(e.extendVideoSpeedList,t);s.remove()}));s.append(i);return s};const d=()=>{const t=e=>{const t=r().toString();e.setAttribute("min",t);e.value=t};const d=document.createElement("li");d.classList.add(n.classNameMap.speedMenuItem);const l=document.createElement("i");l.classList.add("mdi","mdi-playlist-plus");const p=document.createElement("input");p.classList.add("add-speed-entry");p.setAttribute("type","number");p.setAttribute("max",a.toString());p.setAttribute("step",s.toString());p.setAttribute("title","增加新的倍数值");t(p);p.addEventListener("keydown",(t=>{if(t.key==="Enter"){const t=parseFloat(p.value);if(!isFinite(t)){logError("无效的倍数值");return false}if(t<i){logError("倍数值太小了");return false}if(t>a){logError("倍数值太大了");return false}if(n.supportedRates.includes(t)){logError("不能重复添加已有的倍数值");return false}e.extendVideoSpeedList.push(t);e.extendVideoSpeedList=n.extendedSupportedRates;let s=d.nextElementSibling;while(!s.dataset.value||parseFloat(s.dataset.value)>n.nativeSupportedRates.slice(-1)[0]&&t<parseFloat(s.dataset.value)){s=s.nextElementSibling}s.before(o(t))}}));d.prepend(l,p);p.style.display="none";d.addEventListener("mouseenter",(()=>{t(p);p.style.display="inline";l.style.display="none"}));d.addEventListener("mouseleave",(()=>{l.style.display="inline";p.style.display="none"}));return d};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`,"extend-video-speed-style");const l=n.extendedSupportedRates.map((e=>o(e))).reverse();l.unshift(d());return l};(async()=>{const{VideoSpeedController:e}=await t.importAsync("video-speed-controller");e.init()})();return{export:{getExtraSpeedMenuItemElements:n}}})(); |