Skip to content

Commit

Permalink
Update background.js
Browse files Browse the repository at this point in the history
  • Loading branch information
wosledon committed Jan 19, 2022
1 parent 3751a93 commit 2e2773e
Showing 1 changed file with 102 additions and 16 deletions.
118 changes: 102 additions & 16 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
var remarkReader = {

// TODO: 专属播报
// TODO: 观众可以自己屏蔽自己

global_engine: null,
global_voices: null,
global_voices_index: 15,
global_voices_index: 17,
global_messages: [
"脱下裤子说",
"偷偷亲了你一口说",
Expand All @@ -12,11 +15,54 @@ var remarkReader = {
"开着法拉利说",
"流着口水说",
"一边偷看王寡妇洗澡一边说",
"拿着肥皂对你说"
"拿着肥皂对你说",
"在基德怀里说", //使之塞上
"拿着生发液喷了喷主播说",
"拼命码字的说",
"站在冷风中说",
"萌哒哒的说",
"拍了拍主播的脑袋说"
],

global_vip: {
"使至塞上": "在基德怀里说",
"胖纸不争_熙泽": "萌哒哒的说",
"消极人员_熙泽": "骑着哈雷说",
"藏起奶糖的小兔子尾巴": "拼命码字的说",
"一言_熙泽": "gay里gay气的说",
"CV卡加_熙泽": "茶里茶气的说"
},

global_cache: null,

global_blacklist: [
//"藏起奶糖的小兔子尾巴"
],

global_referred: {
"胖纸不争_熙泽": "主播小可爱",
"ys诚㊗落忱㋀㏵满月乐": "叶诚",
"消极人员_熙泽": "员员",
"藏起奶糖的小兔子尾巴": "小尾巴",
"老宫___": "铁柱",
"一言_熙泽": "言言",
"雲尘是只猫_YLey": "雲尘",
"CV卡加_熙泽": "加加哥哥"
},

global_emoji: {
"_(:3 」∠)_": "生无可恋的躺着~",
"_(┐「ε:)_": "躺我旁边来~",
"( ̄y▽ ̄)~*": "嘿嘿嘿!",
"(ง •̀_•́)ง": "加油,呼呼!",
"(•̀ᴗ•́)و ̑̑": "机智如我!!!",
"(。-`ω´-)": "睿智的我早已看穿了一切!",
"⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄": "害羞羞~",
"(╭ ̄3 ̄)╭♡": "啾啾啾,小心心~",
"(╬ ̄皿 ̄)凸": "哼!鄙视你!",
"( ・◇・)": "啊?"
},

// 加载语音引擎
initVoiceEngine: function () {
const synthVoice = () => {
Expand All @@ -27,6 +73,7 @@ var remarkReader = {

var voices = synth.getVoices();
console.log("========>音频引擎加载完成<========")
console.log(voices)
global_voices = voices;
const utterance = new SpeechSynthesisUtterance();
utterance.voice = voices[this.global_voices_index];
Expand Down Expand Up @@ -56,7 +103,7 @@ var remarkReader = {

if ($(element).hasClass('danmaku-item')) {
var chats = $("#chat-items > .chat-item").last();
var name = chats.attr('data-uname');
var name = chats.attr('data-uname').replace("_", "");
var content = chats.attr('data-danmaku')
var command = typeof (content) == "undefined" ? "" : content.split("+");
if (command.length >= 2) {
Expand All @@ -75,6 +122,10 @@ var remarkReader = {
that.global_voices_index = 16;
that.toSpeak("猛男模式已启动。");
return;
case "台妹模式":
that.global_voices_index = 17;
that.toSpeak("台妹模式已启动。");
return;
}
return;
case "添加短语":
Expand All @@ -99,6 +150,7 @@ var remarkReader = {
delete that.global_messages[index];
that.toSpeak("短语" + dContext + "已删除。");
return;

}
}

Expand Down Expand Up @@ -128,7 +180,7 @@ var remarkReader = {
var name = $(element).find('.username').text();
var content = $(element).find('.message-content').text();
var gift = $(element).find('.gift').text();
if(that.global_cache == content){
if (that.global_cache == content) {
return;
}
that.global_cache = content;
Expand All @@ -149,6 +201,10 @@ var remarkReader = {
that.global_voices_index = 16;
that.toSpeak("猛男模式已启动。");
return;
case "台妹模式":
that.global_voices_index = 17;
that.toSpeak("台妹模式已启动。");
return;
}
return;
case "添加短语":
Expand All @@ -173,18 +229,35 @@ var remarkReader = {
delete that.global_messages[index];
that.toSpeak("短语" + dContext + "已删除。");
return;
case "pb":
return;
}
}

console.log(that.global_messages)

if (typeof (name) != "undefined" && name != "" && name != null) {
if(typeof (gift) != "undefined" && gift != "" && gift != null){
that.toSpeak("感谢" + name + content+ ",感谢你的支持,摸摸~")
}else{
that.toSpeak(name + "," + that.global_messages[Math.floor(Math.random() * that.global_messages.length)] + ":" + content);
if (that.global_blacklist.indexOf(name) < 0 && typeof (name) != "undefined" && name != "" && name != null && typeof (parseInt(content)) != "undefined") {
if (typeof (gift) != "undefined" && gift != "" && gift != null) {
that.toSpeak("感谢" + name + content + ",感谢你的支持,么么哒~")
} else {
if (content.length > 15 || content.length <= 1) {
return;
}
for (var key in that.global_emoji) {
if (content.indexOf(key) >= 0) {
content = content.replace(key, that.global_emoji[key])
console.log(key, that.global_emoji[key])
continue;
}
}
that.toSpeak((typeof (that.global_referred[name]) == "undefined" ? name : that.global_referred[name]) +
"," +
(typeof (that.global_vip[name]) == "undefined" ?
that.global_messages[Math.floor(Math.random() * that.global_messages.length)] :
that.global_vip[name]) + ":" + content);
//that.chatXiaoAi(that, name, content)
}

}
})

Expand All @@ -194,17 +267,17 @@ var remarkReader = {
// var name1 = $("#ChatBox").find('.join-queue-effect').find('.username').text();
// var name2 = $("#ChatBox").find('.join-user').text();

if($(element).hasClass('join-queue-effect')){
if ($(element).hasClass('join-queue-effect')) {
var name = $(element).find('.username').text();
if(typeof (name) != "undefined" && name != "" && name != null){
if (typeof (name) != "undefined" && name != "" && name != null) {
console.log("欢迎" + name + "进入直播间!");
that.toSpeak("欢迎" + name + "进入直播间!");
that.toSpeak("欢迎" + (typeof (that.global_referred[name]) == "undefined" ? name : that.global_referred[name]) + "进入直播间!");
}
}
if($(element).find('join-user')){

if ($(element).find('join-user')) {
var name = $(element).find('.join-user').text();
if(typeof (name) != "undefined" && name != "" && name != null){
if (typeof (name) != "undefined" && name != "" && name != null) {
console.log("欢迎" + name + "进入直播间!");
that.toSpeak("欢迎匿名大佬进入直播间!");
}
Expand All @@ -216,20 +289,31 @@ var remarkReader = {
this.initVoiceEngine();
},

close: function () {
this.global_engine = null;
},

initEngine: function () {
$(".upper-row").append('<button style="margin-right:40px;width:100px;height:30px;background-color:#2b88ad;border-radius:5px;color:white;border:0px;cursor:pointer;" id="start_helper">启动小助手</button>');
// $(".upper-row").append('<button style="margin-right:40px;width:100px;height:30px;background-color:#2b88ad;border-radius:5px;color:white;border:0px;cursor:pointer;" id="end_helper">关闭小助手</button>');
$('#start_helper').click(() => {
remarkReader.init();
this.bilibiliLive();
$('#start_helper').attr("disabled", "disabled").css("background-color", "gray");
});


$(".info-row:first-child").append('<button style="margin-left:40px;width:100px;height:30px;background-color:#2b88ad;border-radius:5px;color:white;border:0px;cursor:pointer;" id="start_helper">启动小助手</button>');
// $(".info-row:first-child").append('<button style="margin-left:40px;width:100px;height:30px;background-color:#2b88ad;border-radius:5px;color:white;border:0px;cursor:pointer;" id="start_helper">关闭小助手</button>');
$('#start_helper').click(() => {
remarkReader.init();
this.catFmLive();
$('#start_helper').attr("disabled", "disabled").css("background-color", "gray");
});
// $('#end_helper').click(() => {
// remarkReader.close();
// $('#end_helper').attr("disabled", "disabled").css("background-color", "gray");
// });

//$('.upper-row').append("<iframe id='xiaoaiframe' src=''></iframe>")
},
Expand Down Expand Up @@ -260,7 +344,9 @@ $(function () {
$('head').append('<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">');
console.log("启动");
setTimeout(() => {
remarkReader.initEngine();
remarkReader.initEngine();
// $('.input-container').find('input').setAttribute("value", 123456);
// $('.input-container').find('.btn-send').click();
}, 2 * 1000);
});
})

0 comments on commit 2e2773e

Please sign in to comment.