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.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
MoeHero committed Nov 8, 2017
2 parents e366aee + f715825 commit 32ca536
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 295 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +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 @@ -29,7 +28,7 @@

## 开发进度
- 重构设置页面 60%
- 优化程序结构 50%
- 优化程序结构 70%

## License
※ 本项目使用 [Mozilla Public License 2.0](https://github.com/MoeHero/BilibiliHelper/blob/master/LICENSE) 许可协议
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 Helper",
"version": "0.1.0",
"version": "0.1.1",
"author": "MoeHero",
"license": "MPL-2.0",
"homepage": "https://github.com/MoeHero/BilibiliHelper#readme",
Expand Down
34 changes: 20 additions & 14 deletions src/live/ALPlugin_Activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ class ALPlugin_Activity {
if(!Helper.option.live || !Helper.option.live_autoActivity) {
return;
}

//this.initDOM();
if(Helper.userInfo.noLogin) {
ModuleNotify.activity('noLogin');
ModuleConsole.activity('noLogin');
return;
}
this.addEvent();
}
// static getInfo() {
Expand All @@ -21,8 +24,6 @@ class ALPlugin_Activity {
// return info;
// }

static initDOM() {
}
static addEvent() {
var $this = this;
Helper.sendMessage({cmd: 'get', type: 'Activity'}, result => {
Expand All @@ -45,26 +46,31 @@ class ALPlugin_Activity {
}

static join(roomID) {
$.getJSON('https://api.live.bilibili.com/activity/v1/Raffle/check', {roomid: roomID}).done(result => {
if(result.code === 0) {
for(let data of result.data) {
$.getJSON('//api.live.bilibili.com/activity/v1/Raffle/check', {roomid: roomID}).done(r1 => {
if(r1.code === 0) {
for(let data of r1.data) {
if(this.list[data.raffleId] === undefined) {
$.getJSON('https://api.live.bilibili.com/activity/v1/Raffle/join', {roomid: roomID, raffleId: data.raffleId}).done(r => {
if(r.code === 0) {
this.list[data.raffleId] = new Helper.countdown(r.data.time + 30, () => this.getAward(roomID, data.raffleId));
} else {
console.log(r);
$.getJSON('//api.live.bilibili.com/activity/v1/Raffle/join', {roomid: roomID, raffleId: data.raffleId}).done(r2 => {
switch(r2.code) {
case 0:
this.list[data.raffleId] = new Helper.countdown(r2.data.time + 30, () => this.getAward(roomID, data.raffleId));
break;
case -400: //已参加抽奖
break;
default:
console.log(r2);
break;
}
}).fail(() => Helper.countdown(2, () => this.join(roomID)));
}
}
} else {
console.log(result);
console.log(r1);
}
}).fail(() => Helper.countdown(2, () => this.join(roomID)));
}
static getAward(roomID, raffleID) {
$.getJSON('https://api.live.bilibili.com/activity/v1/Raffle/notice', {roomid: roomID, raffleId: raffleID}).done(result => {
$.getJSON('//api.live.bilibili.com/activity/v1/Raffle/notice', {roomid: roomID, raffleId: raffleID}).done(result => {
switch(result.code) {
case 0:
delete this.list[raffleID];
Expand Down
81 changes: 42 additions & 39 deletions src/live/ALPlugin_SmallTV.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
/* globals ModuleStore,ModuleNotify,ModuleConsole */
class ALPlugin_SmallTV {
static init() {
this.list = {};
this.awardName = {1: '小电视抱枕', 2: '蓝白胖次', 3: 'B坷垃', 4: '喵娘', 5: '爱心便当', 6: '银瓜子', 7: '辣条'};
this.list = [];
if(!Helper.option.live || !Helper.option.live_autoSmallTV) {
return;
}

if(Helper.userInfo.noLogin) {
ModuleNotify.smallTV('noLogin');
ModuleConsole.smallTV('noLogin');
return;
}
//this.initDOM();
this.addEvent();
}
static getInfo() {
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];
}
return info;
}

static initDOM() {
$('.treasure-box-ctnr').remove();
this.stateIcon = $('<i>').addClass('bh-icon tv-init');
this.stateText = $('<a>').addClass('func-info v-top bili-link').text('初始化中...');
this.statePanel = $('<div>').addClass('live-hover-panel arrow-top show bh-tvstate').hide();
this.statePanelContent = $('<ul>');
this.statePanelNumber = $('<span>').addClass('f-right').text('0 个');

this.statePanel.append($('<h4>').addClass('bh-title').text('正在抽取的小电视'), this.statePanelNumber, $('<hr>'), this.statePanelContent);
// static getInfo() {
// 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];
// }
// return info;
// }

Helper.DOM.funcInfoRow.prepend(this.stateIcon, ' ', this.stateText, this.statePanel);
}
// static initDOM() {
// $('.treasure-box-ctnr').remove();
// this.stateIcon = $('<i>').addClass('bh-icon tv-init');
// this.stateText = $('<a>').addClass('func-info v-top bili-link').text('初始化中...');
// this.statePanel = $('<div>').addClass('live-hover-panel arrow-top show bh-tvstate').hide();
// this.statePanelContent = $('<ul>');
// this.statePanelNumber = $('<span>').addClass('f-right').text('0 个');
//
// this.statePanel.append($('<h4>').addClass('bh-title').text('正在抽取的小电视'), this.statePanelNumber, $('<hr>'), this.statePanelContent);
//
// Helper.DOM.funcInfoRow.prepend(this.stateIcon, ' ', this.stateText, this.statePanel);
// }
static addEvent() {
var $this = this;
//this.stateText.on('click', () => this.openStatePanel()).stopPropagation();
Expand All @@ -50,11 +53,6 @@ class ALPlugin_SmallTV {
$this.join(roomID);
});
});
// Helper.getMessage(request => {
// if(request.cmd && request.cmd == 'SYS_MSG' && request.tv_id && request.real_roomid) {
//
// }
// });
// this.setStateIcon('enabled');
// this.setStateText(Helper.localize.enabled);
ModuleNotify.smallTV('enabled');
Expand Down Expand Up @@ -89,15 +87,20 @@ class ALPlugin_SmallTV {
// }

static join(roomID) {
$.getJSON('https://api.live.bilibili.com/gift/v2/smalltv/check', {roomid: roomID}).done(r1 => {
$.getJSON('//api.live.bilibili.com/gift/v2/smalltv/check', {roomid: roomID}).done(r1 => {
if(r1.code === 0) {
for(let data of r1.data) {
if(this.list[data.raffleId] === undefined) {
$.getJSON('https://api.live.bilibili.com/gift/v2/smalltv/join', {roomid: roomID, raffleId: data.raffleId}).done(r2 => {
if(r2.code === 0) {
this.list[data.raffleId] = new Helper.countdown(r2.data.time + 30, () => this.getAward(roomID, data.raffleId));
} else {
console.log(r2);
$.getJSON('//api.live.bilibili.com/gift/v2/smalltv/join', {roomid: roomID, raffleId: data.raffleId}).done(r2 => {
switch(r2.code) {
case 0:
this.list[data.raffleId] = new Helper.countdown(r2.data.time + 30, () => this.getAward(roomID, data.raffleId));
break;
case -400: //已参加抽奖
break;
default:
console.log(r2);
break;
}
}).fail(() => Helper.countdown(2, () => this.join(roomID)));
}
Expand All @@ -118,7 +121,7 @@ class ALPlugin_SmallTV {
// }).fail(() => Helper.countdown(2, () => this.join(roomID, TVID)));
}
static getAward(roomID, raffleID) {
$.getJSON('https://api.live.bilibili.com/gift/v2/smalltv/notice', {roomid: roomID, raffleId: raffleID}).done(result => {
$.getJSON('//api.live.bilibili.com/gift/v2/smalltv/notice', {roomid: roomID, raffleId: raffleID}).done(result => {
switch(result.code) {
case 0:
delete this.list[raffleID];
Expand Down
44 changes: 31 additions & 13 deletions src/live/Core.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
/* jshint undef:false */
Helper.sendMessage({cmd: 'getInfo'}, result => {
Helper.info = result;

ModuleConsole.info('BilibiliHelper V' + Helper.info.version);
if(!Helper.showID || Number.isNaN(Helper.showID)) {
ModuleConsole.info('非直播间, 插件不加载');
return;
}

// Helper.addScriptByText(`var extensionID='${Helper.info.extensionID}';`);
// Helper.addScriptByFile('live_inject.min.js');
// Helper.addStylesheetByFile('live_inject.min.css');
Helper.init(() => {
Helper.countdown(0.5, () => {
Promise.all([
new Promise(resolve => Helper.sendMessage({cmd: 'getInfo'}, info => resolve(info))),
new Promise(resolve => Helper.sendMessage({cmd: 'getOptions'}, option => resolve(option))),
Helper.getRoomID(Helper.showID),
Helper.getUserInfo(),
]).then(r => {
Helper.info = r[0];
Helper.option = r[1];
Helper.roomID = r[2];
ModuleConsole.info('BilibiliHelper V' + Helper.info.version);
if(!Helper.roomID || Number.isNaN(Helper.roomID)) {
ModuleConsole.info('非直播间, 插件不加载');
return;
}
ModuleStore.init();
$.post('https://bh.moehero.com/api/helper/userinfo', {uid: Helper.userInfo.uid, version: Helper.info.version, option: JSON.stringify(Helper.option)});
$.post('https://bh.moehero.com/api/helper/statinfo', {uid: Helper.userInfo.uid, smalltv_times: store.get('BH_SmallTVTimes'), school_times: store.get('BH_SchoolTimes') || 0, summer_times: store.get('BH_SummerTimes') || 0, lighten_times: store.get('BH_LightenTimes') || 0});
{
Helper.DOM.info = $('.seeds-wrap .btn').clone().removeClass('btn').html(`${Helper.localize.helper} V${Helper.info.version} <a class="bili-link" target="_blank" href="//jq.qq.com/?k=47vw4s3">加入QQ群</a>`);
$('.seeds-wrap').prepend(Helper.DOM.info);
} //瓜子数量 左
// if(Helper.option.live && (Helper.option.live_autoTreasure || Helper.option.live_autoSmallTV)) {
// Helper.DOM.funcInfoRow = $('<div>').addClass('bh-func-info-row').append($('<div>').addClass('func-info v-top').html('<span>分区: </span>' + $('.room-info-row a')[0].outerHTML));
// $('.anchor-info-row').css('margin-top', 0).after(Helper.DOM.funcInfoRow);
// $('.room-info-row').remove();
// } //主播信息 下
//自动扩大关注列表
// Helper.sidebarHeight = $('.colorful').css('display') == 'none' ? 499 : 550;
// $('.my-attention-body').height($(window).height() - Helper.sidebarHeight);
// $(window).resize(() => $('.my-attention-body').height($(window).height() - Helper.sidebarHeight));

// Helper.addScriptByText(`var extensionID='${Helper.info.extensionID}';`);
// Helper.addScriptByFile('live_inject.min.js');
// Helper.addStylesheetByFile('live_inject.min.css');
FuncSign.init();
FuncTreasure.init();
FuncAutoLottery.init();
Expand Down
10 changes: 6 additions & 4 deletions src/live/FuncSign.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ class FuncSign {
if(!Helper.option.live || !Helper.option.live_autoSign) {
return;
}
if(Helper.userInfo.noLogin) {
ModuleNotify.sign('noLogin');
ModuleConsole.sign('noLogin');
return;
}
this.addEvent();
}

Expand All @@ -27,7 +32,7 @@ class FuncSign {
// }

static doSign() {
$.getJSON('https://api.live.bilibili.com/sign/doSign').done(result => {
$.getJSON('//api.live.bilibili.com/sign/doSign').done(result => {
switch(result.code) {
case 0:
let award = {award: result.data.text};
Expand All @@ -41,9 +46,6 @@ class FuncSign {
ModuleNotify.sign('signed');
ModuleConsole.sign('signed');
break;
case -101: //未登录
ModuleConsole.sign('noLogin');
break;
default:
console.log(result);
break;
Expand Down

0 comments on commit 32ca536

Please sign in to comment.