Bilibili-Evolved/min/danmaku-send-bar.min.js
2021-01-10 21:51:51 +08:00

1 line
1.6 KiB
JavaScript

(()=>(e,t)=>{(async()=>{if(!document.URL.match(/^https:\/\/live.bilibili.com\/(blanc\/)?(\d+)/)){return}const e=await SpinQuery.select(".bilibili-live-player-video-controller");if(!e){return}t.applyStyle("danmakuSendBarStyle");let n=false;const a="danmaku-send-bar";Observer.childList(e,(async()=>{if(!dq(e,".control-area")){return}if(dq(e,`.${a}`)){return}const t=dq(e,".left-area");const i=await SpinQuery.select(".chat-input-ctnr .chat-input");const l=await SpinQuery.select(".chat-input-ctnr ~ .bottom-actions .bl-button--primary");if([t,i,l].some((e=>e===null))){return}const r=Vue.extend({template:`\n<div class="${a}">\n<input\n type="text"\n placeholder="发个弹幕呗~"\n :value="value"\n @keydown.enter="send()"\n @input="updateValue($event.target.value)"\n maxlength="30"\n />\n</div>\n`,data(){return{value:i.value}},mounted(){i.addEventListener("input",this.listenChange);i.addEventListener("change",this.listenChange);if(!n){const e=Object.getOwnPropertyDescriptors(HTMLTextAreaElement.prototype).value;Object.defineProperty(i,"value",{...e,set(t){e.set.call(this,t);raiseEvent(i,"input")}});n=true}},beforeDestroy(){i.removeEventListener("input",this.listenChange);i.removeEventListener("change",this.listenChange)},methods:{updateValue(e){i.value=e;raiseEvent(i,"input")},send(){if(!l.disabled){this.value="";l.click()}},listenChange(e){this.value=e.target.value}}});const s=(new r).$mount().$el;t.insertAdjacentElement("afterend",s)}))})();return{reload:()=>document.body.classList.remove("danmaku-send-bar-unloaded"),unload:()=>document.body.classList.add("danmaku-send-bar-unloaded")}})();