Skip to content
This repository has been archived by the owner on Jan 1, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/V0.0.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
MoeHero committed May 28, 2017
2 parents c5ff210 + 8f252f0 commit adf251a
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
在您提交问题前, 请检查以下项目:
- 您在报告一个 Bug 或者提交一个 功能请求. 如果您需要一般性的帮助, 请直接和我们联系.
- 您的问题在与现有问题并不重复. 如果已有一个相同话题的问题, 请直接在其下留言.
- 如果您在报告一个 Bug 请确定它可以在最新的发行版或 master 分支下重现.
- 如果您在报告一个 Bug 请确定它可以在最新的发行版.
- 请详细说明重现问题的步骤(有屏幕截图的话就更好了).
(提交时请将上面的内容删除)

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
[![license](https://img.shields.io/badge/license-MPL--2.0-blue.svg)](https://github.com/MoeHero/BilibiliHelper/blob/master/LICENSE)

## 更新日志
`新增` 自动更新
`修复` 直播页面样式加载的瞬间不正常的问题
`修复` 尝试修复某些情况下赠送礼物包裹内礼物时提示参数错误的问题
`新增` 弹幕增强
`优化` 通知图标改用网络获取
`修复` 修复礼物包裹内礼物有时不能点击的问题
`修复` 设置页面某些分辨率下按钮显示不正常的问题

## TODO List
### 计划功能
Expand All @@ -21,7 +22,6 @@
- [x] 右上角图标弹出菜单
- [ ] 切换默认排行榜页面
- [ ] 自动参加节奏风暴
- [ ] 弹幕发送增强

### 已完成功能
- [x] 自动领取应援棒
Expand All @@ -32,12 +32,13 @@
- [x] 屏蔽设置
- [x] 抽奖统计
- [x] 自动更新
- [x] 弹幕增强

## 开发进度
- 重构屏蔽设置代码 90%
- 自动参加节奏风暴 0%
- 重构设置页面 95%
- 优化程序结构 60%
- 优化程序结构 70%
- 自动更新 50%

## License
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bilibili-helper",
"description": "Bilibili助手",
"version": "0.0.18",
"version": "0.0.19",
"author": "MoeHero",
"license": "MPL-2.0",
"homepage": "https://github.com/MoeHero/BilibiliHelper#readme",
Expand Down
2 changes: 1 addition & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var Options = {
live_autoSmallTV: true,
live_autoLighten: true,
live_giftPackage: true,
live_danmuEnhance: true,
live_hideSetting_gift: true,
live_hideSetting_vip: true,
live_hideSetting_sysmsg: true,
Expand Down Expand Up @@ -124,7 +125,6 @@ function createNotifications(param) {
}

if(window.localStorage.bh_option) {
JSON.parse(window.localStorage.bh_option).live_lighten !== undefined && (window.localStorage.bh_option = '{}');
$.extend(Options, JSON.parse(window.localStorage.bh_option));
}
saveOptions();
Expand Down
6 changes: 3 additions & 3 deletions src/live/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ Helper.sendMessage({command: 'getInfo'}, (result) => {
return;
}

Helper.addScriptByText(`var extensionID='${Helper.info.extensionID}';`);
Helper.addScriptByFile('live_inject.min.js');
Helper.addStylesheetByFile('live_inject.min.css');
Helper.init(() => {
if(!Helper.roomID || isNaN(Helper.roomID)) {
ModuleConsole.info('非直播间, 插件不加载');
return;
}
Helper.addScriptByText(`var extensionID='${Helper.info.extensionID}';`);
Helper.addScriptByFile('live_inject.min.js');

FuncSign.init();
FuncTreasure.init();
FuncAutoLottery.init();

FuncGiftPackage.init();
FuncHideSetting.init();
FuncDanmuEnhance.init();
});
});
153 changes: 153 additions & 0 deletions src/live/FuncDanmuEnhance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
class FuncDanmuEnhance {
static init() {
if(!Helper.option.live || !Helper.option.live_danmuEnhance) {
return;
}
this.danmuColorList = ['ffffff', 'ff6868', '66ccff', 'e33fff', '00fffc', '7eff00', 'ffed4f', 'ff9800', 'ff739a'];
this.danmuModeList = [{name: '滚动', mode: 1, type: 'scroll'}, {name: '顶部', mode: 5, type: 'top'}];
this.selectDanmuColor = 0;
this.selectDanmuMode = 1;
this.maxLength = Helper.userInfo.userLevel >= 20 ? 30 : 20;

this.initDOM();
this.addEvent();
}

static initDOM() {
this.danmuColorButton = $('.danmu-color').clone();
this.danmuColorPanel = $('.danmu-color-panel').clone();
this.danmuModeSelectPanel = this.danmuColorPanel.find('.mode-select-panel');
this.danmuColorSelectPanel = this.danmuColorPanel.find('.color-select-panel');
this.danmuTextbox = $('.danmu-textbox').clone().removeAttr('maxlength');
this.danmuSendButton = $('.danmu-send-btn').clone();
this.danmuLenghtText = $('.danmu-length-count').clone().text('0 / ' + this.maxLength);

$('.danmu-color').after(this.danmuColorButton).remove();
$('.danmu-color-panel').after(this.danmuColorPanel).remove();
$('.danmu-textbox').after(this.danmuTextbox).remove();
$('.danmu-send-btn').after(this.danmuSendButton).remove();
$('.danmu-length-count').after(this.danmuLenghtText).remove();
}
static addEvent() {
this.danmuColorPanel.stopPropagation();
this.danmuColorButton.on('click', () => this.danmuColorPanel.show()).stopPropagation();
$(document).on('click', () => this.danmuColorPanel.fadeOut(200));
this.danmuSendButton.on('click', () => this.sendLongDanmu());

this.danmuTextbox.on('input', () => {
let lenght = this.danmuTextbox.val().length;
let lenghtText = (lenght % this.maxLength === 0 ? this.maxLength : Number.parseInt(lenght % this.maxLength)) + ' / ' + this.maxLength;
lenght > this.maxLength && (lenghtText += ' * ' + (Number.parseInt(lenght / this.maxLength) - (lenght % this.maxLength === 0 ? 1 : 0)));
lenght === 0 && (lenghtText = '0 / ' + this.maxLength);
this.danmuLenghtText.text(lenghtText);
}).on('keydown', (e) => {
if(e.keyCode == 13) {
e.preventDefault();
this.sendLongDanmu();
}
});

Helper.addScriptByText('bh_getDanmuInfo();').remove();
Helper.getMessage((request) => {
if(request.command && request.command == 'getDanmuInfo') {
if(request.danmuInfo.selectColor === '') {
Helper.countdown(1, () => Helper.addScriptByText('bh_getDanmuInfo();').remove());
} else {
this.selectDanmuColor = this.danmuColorList.indexOf(request.danmuInfo.selectColor.substring(2));
this.selectDanmuMode = request.danmuInfo.selectMode;
this.updateDanmuColorPanel();
}
}
});
}

static updateDanmuColorPanel() {
this.danmuModeSelectPanel.empty();
this.danmuColorSelectPanel.empty();
for(let danmuMode of this.danmuModeList) {
let modeDOM = $('<a>').addClass('list danmu-mode-block ' + danmuMode.type).text(danmuMode.name)
.on('click', (e) => this.setDanmuConfig('mode', $(e.currentTarget)));
if(this.selectDanmuMode == danmuMode.mode) {
modeDOM.addClass('active');
}
this.danmuModeSelectPanel.append(modeDOM);
}
for(let i in this.danmuColorList) {
let colorDOM = $('<a>').addClass('danmu-color-block').css('background-color', '#' + this.danmuColorList[i])
.on('click', (e) => this.setDanmuConfig('color', $(e.currentTarget)));
if(this.selectDanmuColor == i) {
colorDOM.addClass('active');
}
this.danmuColorSelectPanel.append($('<li>').append(colorDOM));
}
}
static setDanmuConfig(type, target) {
let index = type == 'color' ? target.parent().index() : target.index();
if(!(type == 'color' && index == this.selectDanmuColor) && !(type == 'mode' && this.danmuModeList[index].mode == this.selectDanmuMode)) {
$.ajax({
url: '/api/ajaxSetConfig', type: 'post', dataType: 'json',
data: type == 'color' ? {color: '0x' + this.danmuColorList[index], room_id: Helper.roomID} : {mode: this.danmuModeList[index].mode, room_id: Helper.roomID}
}).done((result) => {
switch(result.code) {
case 0:
if(type == 'color') {
this.selectDanmuColor = index;
} else {
this.selectDanmuMode = index;
}
this.updateDanmuColorPanel();
break;
case -500:
Helper.liveToast(result.msg, target, 'info');
break;
default:
console.log(result);
break;
}
}).fail(() => Helper.liveToast('设置错误, 请稍后再试!', target, 'error'));
}
}

static sendLongDanmu() {
let danmu = this.danmuTextbox.val();
if(danmu !== '') {
this.danmuTextbox.val('').focus();
this.danmuLenghtText.text('0 / ' + this.maxLength);
this.sendDanmu(this.splitDanmu(danmu));
} else {
Helper.liveToast('请输入弹幕后再发送~', this.danmuSendButton, 'info');
}
}
static splitDanmu(danmu) {
let danmus = [];
for(let i = 0; i < Math.floor(danmu.length / this.maxLength) + 1; i++) {
let _danmu = danmu.substr(i * this.maxLength, this.maxLength);
_danmu !== '' && danmus.push(_danmu);
}
return danmus;
}
static sendDanmu(danmus) {
this.sendDanmu_flash(danmus[0]).then(() => {
if(danmus.length > 1) {
danmus.splice(0, 1);
Helper.countdown(2, () => this.sendDanmu(danmus));
}
});
}
static sendDanmu_flash(danmu) {
return new Promise((resolve) => {
$('#player_object')[0].sendMsg(danmu, '0x' + this.danmuColorList[this.selectDanmuColor], this.selectDanmuMode);
resolve();
});
}
static sendDanmu_post(danmu, roomID) {
return $.ajax({
url: '/msg/send', type: 'post', dataType: 'json',
data: {
color: '0x' + this.danmuColorList[this.selectDanmuColor],
msg: danmu,
room_id: roomID
}
}).promise();
}
}

0 comments on commit adf251a

Please sign in to comment.