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.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
MoeHero committed May 4, 2017
2 parents 03436e5 + 29ac981 commit c629eed
Show file tree
Hide file tree
Showing 20 changed files with 361 additions and 331 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

## Update Log
`新增` 直播设置支持更多选项
`优化` 取消检测其他插件机制
`优化` 通知图标显示图标多样化
`优化` 自动领取瓜子后瓜子数量动态更新
`修复` 自动领瓜子一直显示领取中的问题
`优化` 自动签到仅在一个直播间开启
`优化` 无法赠送礼物包裹内物品时显示提示
`修复` B站改版导致部分直播页面错位的问题

## TODO List
### 计划功能
- [ ] 切换默认排行榜页面
- [ ] 赠送礼物增强
- [ ] 主站功能
- [ ] 自动更新

### 后续版本功能
- [ ] 直播设置支持保存
Expand All @@ -31,10 +31,11 @@
- [x] 抽奖统计

## Develop Progress
- 重构自动领瓜子代码 0%
- 重构礼物包裹代码 0%
- 重构直播设置代码 0%
- 优化程序结构 10%
- 优化程序结构 40%
- 重构设置页面 0%
- 自动更新 0%

## License
※ 本项目使用 [Mozilla Public License 2.0](https://github.com/MoeHero/BilibiliHelper/blob/master/LICENSE) 许可协议
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gulp.task('set:d', function() {

gulp.task('live', function() {
return gulp.src('./src/bilibili_live/*.js')
.pipe($.order(['Live*.js', 'Module*.class.js', 'Func*.class.js', '!Core.js', 'Core.js']))
.pipe($.order(['Live.js', 'Module*.js', 'Func*.js', '!Core.js', 'Core.js']))
.pipe($.jshintChannel())
.pipe($.concat('bilibili_live.js'))
.pipe($.if(path == 'release', $.babel({presets: ['babili']})))
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.11",
"version": "0.0.12",
"author": "MoeHero",
"license": "MPL-2.0",
"homepage": "https://github.com/MoeHero/BilibiliHelper#readme",
Expand Down
39 changes: 27 additions & 12 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
console.log('Start Loading...');

var Treasure = {
var Sign = {
showID: false,
tabID: false,
getTreasure: function() {
return Treasure;
getSign: () => Sign,
setSign: function(options) {
Sign.showID = options.showID;
Sign.tabID = options.tabID;
},
delSign: function() {
Sign.showID = false;
Sign.tabID = false;
}
};
var Treasure = {
showID: false,
tabID: false,
getTreasure: () => Treasure,
setTreasure: function(options) {
Treasure.showID = options.showID;
Treasure.tabID = options.tabID;
Expand All @@ -18,9 +29,7 @@ var Treasure = {
var SmallTV = {
showID: false,
tabID: false,
getSmallTV: function() {
return SmallTV;
},
getSmallTV: () => SmallTV,
setSmallTV: function(options) {
SmallTV.showID = options.showID;
SmallTV.tabID = options.tabID;
Expand All @@ -33,9 +42,7 @@ var SmallTV = {
var Lighten = {
showID: false,
tabID: false,
getLighten: function() {
return Lighten;
},
getLighten: () => Lighten,
setLighten: function(options) {
Lighten.showID = options.showID;
Lighten.tabID = options.tabID;
Expand All @@ -45,6 +52,7 @@ var Lighten = {
Lighten.tabID = false;
}
};

var Option = {
live_autoSign: true,
live_autoTreasure: true,
Expand Down Expand Up @@ -95,6 +103,16 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tabInfo) {

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
switch(request.command) {
case 'getSign':
sendResponse(Sign.getSign());
break;
case 'setSign':
Sign.setSign({tabID: sender.tab.id, showID: request.showID});
break;
case 'delSign':
sendResponse(Sign.delSign());
break;

case 'getTreasure':
sendResponse(Treasure.getTreasure());
break;
Expand All @@ -104,9 +122,6 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
case 'delTreasure':
sendResponse(Treasure.delTreasure());
break;
case 'checkNewTask':
chrome.tabs.sendMessage(Treasure.tabID, {command: 'checkNewTask'});
break;

case 'getSmallTV':
sendResponse(SmallTV.getSmallTV());
Expand Down
35 changes: 11 additions & 24 deletions src/bilibili_live/ALPlugin_Lighten.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ class ALPlugin_Lighten {
this.addEvent();
}
static getInfo() {
let info = {};
info.name = '应援棒';
info.times = ModuleStore.getTimes('lighten');
let info = {
name: '应援棒',
times: ModuleStore.getTimes('lighten')
};
info.statinfo = {'应援棒': info.times};
return info;
}
Expand All @@ -25,30 +26,14 @@ class ALPlugin_Lighten {
this.getLightenID(request.url.match(/com\/(.+)/)[1]);
}
});
this.event('enabled');
ModuleNotify.lighten('enabled');
ModuleConsole.lighten('enabled');
} else {
this.event('exist', result);
ModuleConsole.lighten('exist', result);
}
});
}

static event(key, param) {
switch(key) {
case 'enabled':
ModuleNotify.lighten('enabled');
ModuleConsole.lighten('enabled');
break;
case 'exist':
ModuleConsole.lighten('exist', param);
break;
case 'award':
ModuleStore.addTimes('lighten', 1);
ModuleNotify.lighten('award');
ModuleConsole.lighten('award');
break;
}
}

static getLightenID(showID) {
Live.getRoomID(showID, (roomID) => {
$.getJSON('//api.live.bilibili.com/activity/v1/NeedYou/getLiveInfo', {roomid: roomID}).done((result) => {
Expand All @@ -66,8 +51,10 @@ class ALPlugin_Lighten {
static getAward(roomID, lightenID) {
$.post('//api.live.bilibili.com/activity/v1/NeedYou/getLiveAward', {roomid: roomID, lightenId: lightenID}).done((result) => {
if(result.code === 0) {
this.event('award');
} else if(result.code == -400) {
ModuleStore.addTimes('lighten', 1);
ModuleNotify.lighten('award');
ModuleConsole.lighten('award');
} else if(result.code == -400) { //错误
} else {
console.log(result);
}
Expand Down
51 changes: 23 additions & 28 deletions src/bilibili_live/ALPlugin_SmallTV.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals ModuleStore,ModuleDom,ModuleNotify,ModuleConsole */
/* globals ModuleStore,ModuleNotify,ModuleConsole */
class ALPlugin_SmallTV {
static init() {
this.countdown = {};
Expand All @@ -11,10 +11,11 @@ class ALPlugin_SmallTV {
this.addEvent();
}
static getInfo() {
let info = {};
info.name = '小电视抽奖';
info.times = ModuleStore.getTimes('smallTV');
info.statinfo = [];
let info = {
name: '小电视抽奖',
times: ModuleStore.getTimes('smallTV'),
statinfo: []
};
let statinfos = ModuleStore.getStatinfo('smallTV');
for(let key in statinfos) {
info.statinfo[this.awardName[key]] = statinfos[key];
Expand All @@ -26,7 +27,7 @@ class ALPlugin_SmallTV {
$('.treasure-box-ctnr').remove();
this.stateIcon = $('<i>').addClass('bh-icon tv-init');
this.stateText = $('<a>').addClass('func-info v-top').text('初始化中...');
Live.DOM.funcInfoRow.prepend(this.stateText).prepend(this.stateIcon);
Live.DOM.funcInfoRow.prepend(this.stateIcon, this.stateText);
}
static addEvent() {
Live.sendMessage({command: 'getSmallTV'}, (result) => {
Expand All @@ -38,32 +39,23 @@ class ALPlugin_SmallTV {
this.join(request.real_roomid, request.tv_id);
}
});
this.event('enabled');
this.setStateIcon('enabled');
this.setStateText(Live.localize.enabled);
ModuleNotify.smallTV('enabled');
ModuleConsole.smallTV('enabled');
} else {
this.event('exist', result);
this.setStateIcon('exist');
this.setStateText(Live.format(Live.localize.smallTV.action.exist, result));
ModuleConsole.smallTV('exist', result);
}
});
}

static event(key, param) {
switch(key) {
case 'enabled':
this.stateIcon.attr('class', 'bh-icon tv-enabled');
this.stateText.text(Live.localize.enabled);
ModuleNotify.smallTV('enabled');
ModuleConsole.smallTV('enabled');
break;
case 'exist':
this.stateIcon.attr('class', 'bh-icon tv-exist');
this.stateText.text(Live.format(Live.localize.smallTV.action.exist, param));
ModuleConsole.smallTV('exist', param);
break;
case 'award':
ModuleStore.addTimes('smallTV', 1);
ModuleNotify.smallTV('award', param);
ModuleConsole.smallTV('award', param);
break;
}
static setStateText(text) {
this.stateText.text(text);
}
static setStateIcon(key) {
this.stateIcon.attr('class', 'bh-icon tv-' + key);
}

static join(roomID, TVID) {
Expand All @@ -82,8 +74,11 @@ class ALPlugin_SmallTV {
$.getJSON('/SmallTV/getReward', {id: TVID}).done((result) => {
result = result.data;
if(result.status === 0) {
let award = {awardNumber: result.reward.num, awardName: this.awardName[result.reward.id]};
ModuleStore.addStatinfo('smallTV', result.reward.id, result.reward.num);
this.event('award', {awardNumber: result.reward.num, awardName: this.awardName[result.reward.id]});
ModuleStore.addTimes('smallTV', 1);
ModuleNotify.smallTV('award', award);
ModuleConsole.smallTV('award', award);
} else if(result.status == 2) { //正在开奖
Live.countdown(10, () => this.getAward(TVID));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class FuncAutoLottery {
Live.DOM.info.before($('<div>').addClass('ctrl-item').append(this.statinfoButton)).parent().before(this.statinfoPanel);
}
static addEvent() {
this.statinfoButton.on('click', (e) => {this.openStatinfoPanel();e.stopPropagation();});
this.statinfoPanel.on('click', (e) => e.stopPropagation());
this.statinfoButton.on('click', () => this.openStatinfoPanel()).stopPropagation();
this.statinfoPanel.stopPropagation();
$(document).on('click', () => this.statinfoPanel.fadeOut(200));
}

Expand All @@ -41,8 +41,7 @@ class FuncAutoLottery {
for(let key in info.statinfo) {
statinfosContent.append($('<li>').text(key + 'x' + info.statinfo[key]));
}
this.statinfoPanel.append($('<h4>').addClass('bh-title').text(info.name))
.append($('<span>').addClass('f-right').text(info.times + ' 次')).append($('<hr>')).append(statinfosContent);
this.statinfoPanel.append($('<h4>').addClass('bh-title').text(info.name), $('<span>').addClass('f-right').text(info.times + ' 次'), $('<hr>'), statinfosContent);
}
this.statinfoPanel.fadeIn(200);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class FuncGiftPackage {
$('#gift-package-send-panel').after(this.sendPanel).remove();
}
static addEvent() {
this.packagePanel.on('click', (event) => event.stopPropagation());
this.sendPanel.on('click', (event) => event.stopPropagation());
this.packagePanel.stopPropagation();
this.sendPanel.stopPropagation();
$(document).on('click', () => this.packagePanel.fadeOut(200));

this.packageButton.on('click', () => this.openGiftPackage());
Expand All @@ -50,21 +50,32 @@ class FuncGiftPackage {
Live.getMessage((request) => {
if(request.command && request.command == 'sendGiftCallback') {
let result = request.result;
if(result.code === 0) {
if(result.data.remain === 0) {
this.currentGift.element.remove();
this.sendPanel.hide();
} else {
this.sendPanelInfo.text(`您的包裹中还剩 ${result.data.remain} 个可用`);
if(this.sendPanelCount.val() > result.data.remain) {
this.sendPanelCount.val(result.data.remain);
switch(result.code) {
case 0:
if(result.data.remain === 0) {
this.currentGift.element.remove();
this.sendPanel.hide();
} else {
this.sendPanelInfo.text(`您的包裹中还剩 ${result.data.remain} 个可用`);
if(this.sendPanelCount.val() > result.data.remain) {
this.sendPanelCount.val(result.data.remain);
}
this.currentGift.element.find('.gift-count').text('x' + result.data.remain);
this.currentGift.count = result.data.remain;
}
this.currentGift.element.find('.gift-count').text('x' + result.data.remain);
this.currentGift.count = result.data.remain;
}
} else if(result.code == 200005) { //无法给自己赠送道具
} else {
console.log(result);
break;
case -400: //应援棒提示
Live.liveToast('只有在入围偶像活动的主播房间才能赠送该道具!', this.sendPanelButton, 'caution');
break;
case 200005: //无法给自己赠送道具
Live.liveToast('无法给自己赠送道具!', this.sendPanelButton, 'caution');
break;
case 1024: //超时
Live.liveToast('赠送礼物超时, 请稍后再试!', this.sendPanelButton, 'error');
break;
default:
console.log(result);
break;
}
this.sendPanelCount.focus();
}
Expand Down
Loading

0 comments on commit c629eed

Please sign in to comment.