Skip to content

Commit

Permalink
feat: 支持弹幕选择blc源
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxian496 committed Apr 27, 2024
1 parent e905fad commit 5a22ff9
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 56 deletions.
1 change: 1 addition & 0 deletions src/global/enUS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const enUS = {
closeBilibiliDanmuManage: 'close bilibili danmu manage view',
openMieboManage: 'open miebo manage view',
openXiaoxiaoManage: 'open xiaoxiao manage view',
openBlcManage: 'open blc manage view',
author: 'Author:Ford',
};

Expand Down
2 changes: 2 additions & 0 deletions src/global/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export enum CloudSource {
bilibili = 'bilibili',
miebo = 'miebo',
xiaoxiao = 'xiaoxiao',
blc = 'blc',
xubao = 'xubao'
}
4 changes: 4 additions & 0 deletions src/global/i18n.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export interface Lexicon {
* 打开xiaoxiao管理后台
*/
openXiaoxiaoManage: string;
/**
* 打开blc管理后台
*/
openBlcManage: string;
/**
* 作者
*/
Expand Down
1 change: 1 addition & 0 deletions src/global/zhCN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const zhCN = {
closeBilibiliDanmuManage: '关闭bilibili弹幕姬后台',
openMieboManage: '打开miebo管理后台',
openXiaoxiaoManage: '打开xiaoxiao管理后台',
openBlcManage: '打开blc管理后台',
author: '作者:弗特马克贝因',
};

Expand Down
75 changes: 67 additions & 8 deletions src/main/barrageWin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,59 @@ function setXiaoxiaoContents(pluginUrl: string) {
);

barrageWin?.loadURL(
`https://bilichat.obh.live/#/?${pluginUrl.split('?')[0]}`
pluginUrl
// `https://bilichat.obh.live/#/?${pluginUrl.split('?')[0]}`
);
}

function setXubaoContents(pluginUrl: string) {
barrageWin?.webContents.insertCSS(
'body { flex-direction: column;overflow:hidden !important;background-color:rgba(0, 0, 0, 0.25); }'
);
barrageWin?.webContents.insertCSS(
'.ice--itemAvatar { display: flex;align-items: center;font-size: 24px; }'
);
barrageWin?.webContents.insertCSS('.ice--item img { width:60px }');
barrageWin?.webContents.insertCSS(
'.ice--item .text { padding-left:50px;font-size:24px; }'
);
barrageWin?.webContents.insertCSS(
'.ice--itemAvatar .text { color: #08CBD0;padding-left:0; }'
);
barrageWin?.webContents.insertCSS('#items { overflow: auto;height:100%}');

barrageWin?.webContents.executeJavaScript(
`
let main = document.getElementById("div_BiLiveChatOutputer_main");
let msgContainer = document.getElementById("div_BiLiveChatOutputer");
main.style.flex = 'auto';
main.style.overflow = 'hidden';
msgContainer.style.display = 'none';
const itemsDiv = document.createElement('div');
itemsDiv.id = "items";
main.prepend(itemsDiv);
`
);
barrageWin?.loadURL(pluginUrl);
}

function setBlcContents(pluginUrl: string) {
barrageWin?.webContents.insertCSS(
'html body { display:flex;flex-direction: column;background-color:rgba(0, 0, 0, 0.25) !important; }'
);
barrageWin?.webContents.insertCSS(
'#author-name { background-color: transparent !important; center;font-size: 18px;color:#fff !important }'
);

barrageWin?.webContents.insertCSS('#message { color:#fff !important;font-size: 18px; }');

barrageWin?.loadURL(pluginUrl);
}


/**
* 加载miebo云直播插件
* @param pluginUrl 插件地址
Expand All @@ -52,7 +101,7 @@ function createDanMuView(props: BarrageSetting) {

barrageWin = new BrowserWindow({
show: false,
width: 245,
width: 300,
height: 400,
type: 'panel',
frame: false,
Expand Down Expand Up @@ -104,12 +153,22 @@ function createDanMuView(props: BarrageSetting) {
`
);

if (cloudSource === CloudSource.miebo) {
setMieboContents(pluginUrl);
} else if (cloudSource === CloudSource.xiaoxiao) {
setXiaoxiaoContents(pluginUrl);
} else {
setBilibiliContents(pluginUrl);
switch (cloudSource) {
case CloudSource.miebo:
setMieboContents(pluginUrl);
break;
case CloudSource.xiaoxiao:
setXiaoxiaoContents(pluginUrl);
break;
case CloudSource.xubao:
setXubaoContents(pluginUrl);
break;
case CloudSource.blc:
setBlcContents(pluginUrl);
break;
default:
setBilibiliContents(pluginUrl);
break;
}

barrageWin.once('ready-to-show', () => {
Expand Down
114 changes: 95 additions & 19 deletions src/main/speaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let currentSpeech = false;

let currentVolume = 35;

let bilibiliDanmuElement: Element | undefined;
let bilibiliDanmuElement: Element | null = null;

let currentBroadcastIndex = 0;

Expand Down Expand Up @@ -57,15 +57,86 @@ function getMieboMessage(current: Element) {
return value;
}

function getXubaoMessage(current: Element) {
let value = null;
const itemsDiv = document.getElementById('items');

if (current) {
// 礼物
const avatarNode = current.querySelector('.avatar .img') as HTMLElement;
const userNode = current.querySelector('.id .text') as HTMLElement;
const msgNode = current.querySelector('.msg .text') as HTMLElement;
const giftNode = current.querySelector('.gift .text') as HTMLElement;

giftNode && (giftNode.style.color = 'bisque');

if (giftNode === null) {
value = `${userNode?.innerText}${msgNode?.innerText}`;
} else {
value = `${giftNode.innerText}`;
}

const item = document.createElement('div');
item.className = 'ice--item';

const itemAvatar = document.createElement('div');
itemAvatar.className = 'ice--itemAvatar';

avatarNode && itemAvatar.append(avatarNode);
userNode && itemAvatar.append(userNode);

if (msgNode) {
msgNode.style.color = '#fff';
}

item.append(itemAvatar);
msgNode && item.append(msgNode);
giftNode && item.append(giftNode);

itemsDiv?.append(item);
item.scrollIntoView();
}
return value;
}

function getBlcMessage(current: Element) {
let value = null;

if (current) {
// 礼物
const userNode = current.querySelector('#author-name') as HTMLElement;
const giftNode = current.querySelector('#purchase-amount') as HTMLElement;
const msgNode = current.querySelector('#image-and-message') as HTMLElement;

if (userNode !== null && msgNode !== null) {
value = `${userNode?.innerText}${msgNode?.innerText}`;
} else if (userNode !== null && giftNode !== null) {
value = `${userNode?.innerText}${giftNode?.innerText}`;
}
}

return value;
}

function getMessage(current: Element, cloudSource: CloudSource) {
let value = null;

if (cloudSource === CloudSource.miebo) {
value = getMieboMessage(current);
} else if (cloudSource === CloudSource.xiaoxiao) {
value = getXiaoxiaoMessage(current);
} else {
value = getBilibiliMessage(current);
switch (cloudSource) {
case CloudSource.miebo:
value = getMieboMessage(current);
break;
case CloudSource.xiaoxiao:
value = getXiaoxiaoMessage(current);
break;
case CloudSource.xubao:
value = getXubaoMessage(current);
break;
case CloudSource.blc:
value = getBlcMessage(current);
break;
default:
value = null;
break;
}

return value;
Expand All @@ -79,7 +150,7 @@ function startDanmuCirculate(cloudSource: CloudSource) {
clearTimeout(collectDanmuTimer);
if (currentSpeech === true) {
if (
bilibiliDanmuElement !== undefined &&
bilibiliDanmuElement !== null &&
bilibiliDanmuElement.children.length > currentBroadcastIndex
) {
const maxMessage = bilibiliDanmuElement.children.length;
Expand All @@ -93,7 +164,7 @@ function startDanmuCirculate(cloudSource: CloudSource) {
// 如果有弹幕,收集,计数加1
if (current) {
const msg = getMessage(current, cloudSource);

console.log(`msg:${msg}`);
if (msg !== null) {
const utterThis = new SpeechSynthesisUtterance(msg);
// console.log(`currentVolume: ${currentVolume}`);
Expand Down Expand Up @@ -124,33 +195,38 @@ function startDanmuCirculate(cloudSource: CloudSource) {
* @param speech 是否开启语音播报,true表示开启
*/
export function updateSpeech(speech: boolean, cloudSource: CloudSource) {
if (bilibiliDanmuElement === undefined) {
let current = undefined;
if (bilibiliDanmuElement === null) {
let current = null;
switch (cloudSource) {
case CloudSource.bilibili:
current = document.getElementsByClassName('danmaku');
current = document.getElementsByClassName('danmaku')[0];
break;
case CloudSource.miebo:
current = document.getElementsByClassName('dock-ul');
current = document.getElementsByClassName('dock-ul')[0];
break;
case CloudSource.xiaoxiao:
current = document.getElementsByClassName('chatarea');
current = document.getElementsByClassName('chatarea')[0];
break;
case CloudSource.xubao:
current = document.getElementById('div_BiLiveChatOutputer');
break;
case CloudSource.blc:
current = document.getElementById('chat-items');
break;
default:
current = undefined;
current = null;
break;
}
if (current) {
[bilibiliDanmuElement] = current;
}
bilibiliDanmuElement = current;
console.log('bilibiliDanmuElement: ' + bilibiliDanmuElement);
}

currentSpeech = speech;
if (speech === true) {
startDanmuCirculate(cloudSource);
} else {
// 关闭播报时的清理
bilibiliDanmuElement = undefined;
bilibiliDanmuElement = null;
currentBroadcastIndex = 0;
}
}
Expand Down
Loading

0 comments on commit 5a22ff9

Please sign in to comment.