Skip to content

Instantly share code, notes, and snippets.

@g8up
Last active December 31, 2018 09:02
Show Gist options
  • Save g8up/fac7cf4ea88d648cc0dec02e861eeebe to your computer and use it in GitHub Desktop.
Save g8up/fac7cf4ea88d648cc0dec02e861eeebe to your computer and use it in GitHub Desktop.
自动语音提醒进入斗鱼房间的观众
javascript: void ((function () {
/**
* 功能:斗鱼自动弹幕语音朗读
* 用法:需要[制作成 Chrome 书签](http://pan.baidu.com/s/1skgEosX)
* 版本:v2.0.0
* 日期:2017年12月30日 17:28:17
* 更新:2018年12月31日 16:32:25
*/
const speaker = (word, rate = 1) => {
if (word !== '') {
let utt = new SpeechSynthesisUtterance(word);
utt.lang = 'zh-CN';
utt.rate = rate;
utt.volume = 0.5;
utt.onerror = (e) => {
console.log('__xx__fishfork__welcomReminding', e);
};
window.speechSynthesis.speak(utt);
}
};
const $ = ( selector, doc = document) => doc.querySelector( selector );
const getText = ( $el )=>{
if ($el) {
return $el.textContent.trim();
}
return '';
};
const getInnerText = ( $el )=>{
if ($el) {
return $el.innerText.trim();
}
return '';
};
const $cont = $('#js-barrage-list');
const getUserMsg = ($el) => {
const $msg = $('.Barrage-content', $el);
return getText($msg);
};
/* 清除事件,避免重复绑定 */
$cont.removeEventListener("DOMNodeInserted", window.__xx__fishfork__welcomReminding, false);
window.__xx__fishfork__welcomReminding = (e) => {
const msg = getUserMsg(e.target);
if (msg) { /* 弹幕朗读 */
speaker(msg, 1.3);
}
else{
if( $('.Barrage-text', e.target) ) { /* 进入房间提醒 */
speaker(getInnerText(e.target), 1.8);
}
}
};
$cont.addEventListener("DOMNodeInserted", window.__xx__fishfork__welcomReminding, false);
})());
@hxgdzyuyi
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment