');
for (let [key, {text, tempargs, keystr, keycount, display, delimiter}] of Object.entries(config.sets['keyBinding'].options)) {
if(delimiter === undefined) delimiter = '/'; //默认是'/'
// color: grey;
// text-shadow: 1px 1px #fff;
// background-color: silver;
let list_row;
if(display === 'none')
list_row = ret_list_row(-1, text, key, keystr, keycount, delimiter, -1*row_line_height);
else
list_row = ret_list_row(row_count++, text, key, keystr, keycount, delimiter, (row_count-1)*row_line_height);
let $list_row = $(list_row);
///////////////////////////////////////////
//创建一个 num input
function create_num_input(key, arg, arg_index){
//创建inputDOM
function create_num_input_$dom(key, arg){
let $container = $(`
`);
$container.append(`
`)
if(bb_type.indexOf(BILI_3_X_VIDEO) !== -1 && !!arg.opt)
tip_create_3_X({ target: $container, tip_target: $('#hhh_tip'), color: '#00ffff', title: arg.opt.tip[0], gap: 1 });
return $container;
}
//设置inputDOM event
function num_input_event_init($num_input_dom, arg_index){
$input = $num_input_dom.find('input')
//---change---
$input.off('change.hhh_num_input');
$input.on ('change.hhh_num_input', function(e){
let $this = $(this)
let key = $this.attr('key')
let args = config.getCheckboxSettingTempArgs(key)
let new_args = {}
args[arg_index]['value'] = $this.val()
config.setCheckboxSettingTempArgs(key, args);
config.storageCheckboxSetting();
});
//---focus---
$input.off('focus.hhh_num_input');
$input.on ('focus.hhh_num_input', function(e){
//---keydown stopPropagation on---
$('body').off('keydown.hhh_num_input');
$('body').on ('keydown.hhh_num_input', function(e){ e.stopPropagation() });
$(this).css({width: "36px"}).prop('type', 'number');
})
//---dblclick---
//* 双击 number input 会透过input节点产生blur事件 */ bug?
$input.off('dblclick.hhh_num_input');
$input.on ('dblclick.hhh_num_input', function(e){
e.stopImmediatePropagation()
e.preventDefault()
})
//---blur---
$input.off('blur.hhh_num_input');
$input.on ('blur.hhh_num_input', function(e){
//---keydown stopPropagation off---
$('body').off('keydown.hhh_num_input');
$(this).prop('type', 'tel');
this.style.width = "10px"; //让 scrollWidth 获取最小值,达到回缩的效果
this.style.width = (this.scrollWidth)+"px";
})
//---mouseenter、mouseleave---
$input.off('mouseenter.hhh_num_input');
$input.off('mouseleave.hhh_num_input');
$input.on ('mouseenter.hhh_num_input', function(e){
let $this = $(this);
$this.css({width: "36px"}).prop('type', 'number');
let rect = this.getBoundingClientRect();
document.onmousemove = function(e){
let x = e.clientX;
let y = e.clientY;
if(x < rect.left || x > rect.right || y < rect.top || y > rect.bottom ){
$this.mouseleave();
}
}
}).on('mouseleave.hhh_num_input', function(e){
document.onmousemove = null;
if(this !== document.activeElement){
$(this).prop('type', 'tel');
this.style.width = "10px"; //让 scrollWidth 获取最小值,达到回缩的效果
this.style.width = (this.scrollWidth)+"px";
}
})
}
let $num_input_dom = create_num_input_$dom(key, arg)
num_input_event_init($num_input_dom, arg_index)
return $num_input_dom
}
//插入到相应 list row
if(!!tempargs){
let $text = $(`
`)
let static_text = text.split(/\${.+?}/)
let i;
for(i = 0; i < tempargs.length; ++i){
$text[0].appendChild( document.createTextNode(static_text[i]) )
$text[0].appendChild( create_num_input(key, tempargs[i], i)[0] )
}
$text[0].appendChild( document.createTextNode(static_text[i]) )
$list_row.find(`:contains(${text}):last`).replaceWith($text)
}
$list_row.appendTo($div);
set_keybinding_key($list_row.find('.monaco-keybinding'), keystr, true);
if(display === 'none') $list_row.hide();
}
$div.find('.monaco-list-row').appendTo($('.monaco-list-rows'));
$('.monaco-list-rows').find('.hhh-bpx-player-dm-setting-number').mouseenter().mouseleave() //初始化input宽度
//滚动条半屏空屏
if($('.monaco-list').height() < row_count*row_line_height){
//初始化滚动条
scroll_updata($scroll_element, {top: 0})
//滚轮滚动条
$scroll_element.on('mousewheel',function(e){
var wheelDelta = e.originalEvent.wheelDelta;
let delta = wheelDelta >= 120 ? row_line_height*2 : wheelDelta <= -120 ? -row_line_height*2 : 0;
let newtop = parseInt($(this).find('.monaco-list-rows').css('top').split('px')[0]) + delta;
scroll_updata($(this), {top: newtop});
return false;
});
let track = 'mouseover';
//拖动滚动条
$scroll_element.find('.slider').mousedown(function(e){
let $this = $(this);
let doc = document;
$this.addClass('active');
let fixed_offsetY = e.clientY - parseInt($this.css('top').split('px')[0]); //点击时鼠标坐标Y相对滚动条top的偏移
doc.onmousemove = function(e){
scroll_updata($scroll_element, {slider: parseInt(fixed_offsetY - e.clientY)});
};
doc.onmouseup = function(e){
//清除事件
doc.onmousemove = null;
doc.onmouseup = null;
$this.removeClass('active');
track === 'mouseleave' && $scroll_element.mouseleave();
return false;
}
return false;
});
//点击滚动条轨道,滑块中点移到点击位置
$scroll_element.find('.vertical').mousedown(function(e){
let newslider = $(this).find('.slider').height()/2 - e.offsetY; //计算滑块中点相对于鼠标点击位置偏移
scroll_updata($scroll_element, {slider: newslider});
return false;
});
//over & leave
$scroll_element.mouseover(function(){
track = 'mouseover';
if($(this).find('.slider').hasClass('active') !== true){
$(this).find('.vertical').removeClass('invisible')
.removeClass('fade')
.addClass('visible');
}
}).mouseleave(function(){
track = 'mouseleave';
if($(this).find('.slider').hasClass('active') !== true){
$(this).find('.vertical').removeClass('visible')
.addClass('invisible')
.addClass('fade');
}
});
}
//焦点集中在第一项
$('.monaco-list-row').removeClass('focused');
$('.monaco-list-row:first').addClass('focused');
}
//=========事件==========//
//list-row Event
function set_listrow_event(open){
//input Event
function set_input_event(open){
//===========
//input Event
function set_widget(curr_keystr){
function set_input(keystr){
let delimiter = $('.defineKeybindingWidget .monaco-keybinding').attr('key-delimiter');
delimiter = delimiter === '/' ? ' / ' : delimiter;
$('.defineKeybindingWidget input').val(keystr.replace(/\s+/g, `${delimiter}`));
}
function set_existing(keystr){
let str = keystr.split(' ').slice(-1)[0];
let keyarr = config.findKeyBinding(str);
let len = keyarr.length;
let html = '';
if(len > 0){ //有重复
let len_html = '';
let sys_html = '';
let id_text = '';
//如果是系统快捷键
let i = 0;
for (; i < keyarr.length-1; i++) {
const o = keyarr[i];
if(o.is_system_key) id_text += `"${o.id}(系统命令)" / `;
else id_text += `"${o.id}" / `;
}
if(keyarr[i].is_system_key) id_text += `"${keyarr[i].text}(系统命令)"`;
else id_text += `"${keyarr[i].text}"`;
//如果多于一个
if(len > 1) len_html = `等
${len} 个命令`;
html = `
已有命令 ${id_text} ${len_html}绑定此按键
`
}
let $existing = $main.find($('.existingText'));
$existing.text('').append(html);
}
//设置 input keybinging existing
let keycount = Math.abs(+$('.defineKeybindingWidget .monaco-keybinding').attr('key-count'));
let keystr_temp = $('.defineKeybindingWidget .monaco-keybinding').attr('key-str-temp');
let keystr = curr_keystr;
if(keystr_temp !== '' && keystr_temp.split(' ').length < keycount){
keystr = keystr_temp + ' ' + keystr;
}
set_input(keystr);
set_keybinding_key($('.defineKeybindingWidget .monaco-keybinding'), keystr, true);
set_existing(keystr);
return keystr;
}
if (open !== ON){
$main.find('input').off('keydown.hhh_widget_input');
$main.find('input').off('keyup.hhh_widget_input');
$main.find('input').add('.defineKeybindingWidget').off('mousewheel.hhh_widget_input');
$main.find('input').off('blur.hhh_widget_input');
}else{
//----------------
//keydown && keyup
$main.find('input').off('keyup.hhh_widget_input');
$main.find('input').on ('keyup.hhh_widget_input',function(e){
oldkeystr = ''; oldwheelstr = '';
});
$main.find('input').off('keydown.hhh_widget_input');
$main.find('input').on ('keydown.hhh_widget_input',function(e){
let curr_keystr = kb.delSpace(kb.stringifyKeyCode(e));
if(curr_keystr === oldkeystr) return false;
if(curr_keystr === 'Enter'){ //确定keybinding
$('.overlay-container').hide();
//更新list-row
let index = $('.defineKeybindingWidget').attr('data-index');
let $keybinding = $('.monaco-list-rows .monaco-list-row').eq(index).find('.monaco-keybinding');
let keystr = $('.defineKeybindingWidget .monaco-keybinding').attr('key-str');
let keyid = $('.defineKeybindingWidget .monaco-keybinding').attr('key-id');
set_keybinding_key($keybinding, keystr, true);
//log('确认: '+keyid+' - '+keystr);
config.setKeySettingKeystr(keyid, keystr);
config.storageCheckboxSetting();
}else if(curr_keystr === 'Escape'){ //取消keybinding
$('.overlay-container').hide();
}else{ //储存keybinding
let keystr = set_widget(curr_keystr);
let curr_last_keystr = kb.getkeyCode(e.keyCode);
if(['ctrl', 'shift', 'alt'].indexOf(curr_last_keystr.toLowerCase()) === -1){ // 非控制键暂存
$('.defineKeybindingWidget .monaco-keybinding').attr('key-str-temp', keystr);
}
}
oldkeystr = curr_keystr;
return false;
});
//----------
//mousewheel
$main.find('input').add('.defineKeybindingWidget').off('mousewheel.hhh_widget_input');
$main.find('input').add('.defineKeybindingWidget').on ('mousewheel.hhh_widget_input',function(e){
e.keyCode = e.originalEvent.wheelDelta >= 120 ? '300' : '301';
let curr_keystr = kb.delSpace(kb.stringifyKeyCode(e));
//
// let id, index, key;
// //e.ctrlKey = true;
// let keybindings = config.findKeyBinding(kb.delSpace(kb.stringifyKeyCode(e)));
// if(keybindings.length){
// id = keybindings[0]['id'];
// index = keybindings[0]['index'];
// key = keybindings[0]['key'];
// };
// keybindings.forEach(element => {
// log(element)
// });
//
if(curr_keystr === oldwheelstr) return false;
let keystr = set_widget(curr_keystr);
$('.defineKeybindingWidget .monaco-keybinding').attr('key-str-temp', keystr);
oldwheelstr = curr_keystr;
return false;
});
//-----
//blur
$main.find('input').off('blur.hhh_widget_input');
$main.find('input').on ('blur.hhh_widget_input',function(){
$('.overlay-container').hide();
$main.find('input').off('keydown.hhh_widget_input');
$main.find('input').off('keyup.hhh_widget_input');
$main.find('input').add('.defineKeybindingWidget').off('mousewheel.hhh_widget_input');
})
}
}
function key_input_run(){
//log(+$('.monaco-list-row.focused .monaco-keybinding').attr('key-count'))
if(+$('.monaco-list-row.focused .monaco-keybinding').attr('key-count') <= 0) //不可设置
return false;
let bindWidth = $('.keybindings-editor').width();
let bindHeight = $('.keybindings-editor').height();
let inputWidth = $('.defineKeybindingWidget').outerWidth();
let inputHeight = $('.defineKeybindingWidget').outerHeight();
let index = $('.monaco-list-row.focused').attr('data-index');
$('.defineKeybindingWidget').css({left: `${(bindWidth-inputWidth)/2}px`, top: `${(bindHeight-inputHeight)/2}px`})
.attr({'data-index': index});
let key_id = $('.monaco-list-row.focused').find('.monaco-keybinding').attr('key-id');
let key_str = $('.monaco-list-row.focused').find('.monaco-keybinding').attr('key-str');
let key_count = $('.monaco-list-row.focused').find('.monaco-keybinding').attr('key-count');
let delimiter = $('.monaco-list-row.focused').find('.monaco-keybinding').attr('key-delimiter');
$('.defineKeybindingWidget .monaco-keybinding').attr({'key-id': key_id, 'key-str': key_str, 'key-count': key_count, 'key-delimiter': delimiter, 'key-str-temp': ''});
$('.defineKeybindingWidget .existingText').text('');
let key_count_str = +key_count===1 ? '' : `(${key_count}组)`;
$('.defineKeybindingWidget .message').text(`先按所需的组合键${key_count_str},再按 Enter 键。`);
$('.defineKeybindingWidget .monaco-keybinding').empty();
$('.overlay-container').show();
$('.defineKeybindingWidget input').val('').focus();
oldkeystr = '';
oldwheelstr = '';
set_input_event(ON);
//set_widget(key_str); //可以在显示时初始化
}
if (open !== ON){
$('body').off('keydown.hhh_widget_listrow');
$main.find('.monaco-list-rows').off('click.hhh_widget_listrow');
$main.find('.monaco-list-rows').off('dblclick.hhh_widget_listrow');
}else{
//--------
//keydown
$('body').off('keydown.hhh_widget_listrow');
$('body').on ('keydown.hhh_widget_listrow',function(e){
if(config.group !== 'keyBinding') return; //选择执行 key event
let kcode = kb.getkeyCode(e.keyCode);
if(kcode === 'Enter'){
key_input_run();
e.stopImmediatePropagation()
e.preventDefault()
}else if(kcode === '↑' || kcode === '↓' ){
let $next_prev = $('.monaco-list-row.focused').next();
if(kcode === '↑'){
$next_prev = $('.monaco-list-row.focused').prev();
}
if($next_prev.length !== 0 && $next_prev.css('display') !== 'none'){
$('.monaco-list-row.focused').removeClass('focused');
$next_prev.addClass('focused');
}else{
$next_prev = $('.monaco-list-row.focused');
}
let rows_top = +Math.abs($scroll_element.find('.monaco-list-rows').css('top').split('px')[0]);
let screen_height = $('.monaco-list').height();
let focus_row_top = +$next_prev.css('top').split('px')[0];
let focus_row_bottom = focus_row_top + $next_prev.height();
let focus_row_virtual_top = focus_row_bottom - screen_height;
if(rows_top > focus_row_top) {
scroll_updata($scroll_element, {top: -focus_row_top});
}else if(rows_top < focus_row_virtual_top) {
scroll_updata($scroll_element, {top: -focus_row_virtual_top});
}
e.stopImmediatePropagation()
e.preventDefault()
//log('curr_row_top: '+focus_row_bottom+' - rows_top: '+rows_top+' - focus_row_virtual_top: '+(focus_row_bottom-screen_height))
}
});
//------------------
//click && dblclick
$main.find('.monaco-list-rows').off('click.hhh_widget_listrow');
$main.find('.monaco-list-rows').off('dblclick.hhh_widget_listrow');
$main.find('.monaco-list-rows').on ('click.hhh_widget_listrow',function(e){
let $target = $(e.target);
$('.monaco-list-row').removeClass('focused');
$target.parents(".monaco-list-row").addClass('focused');
}).on('dblclick.hhh_widget_listrow',function(){
key_input_run();
});
}
}
init_list_row();
set_listrow_event(ON);
// $('.bpx-player-dm-setting').mouseenter()
// $('#hhh_custom').click()
// $('#keyBinding').click()
// $('#hhh_item>div:first').css({'height':'max-content','width':'max-content'})
// {
// "key": "ctrl+h",
// "command": "workbench.action.tasks.runTask",
// "args": {
// "task": "VS Code - Build",
// "type": "npm"
// }
// }
}
//自定义快捷键设置
//ON - 启用热键,OFF - 关闭热键
function set_hotkey(open){
if (open !== ON){
$(document).off('keyup.hhh_lightoff');
$(document).off('keydown.hhh_lightoff');
$(document).off('mousewheel.hhh_lightoff');
}else{
var parent = document;
var like_shake = false;
var prev_time = 0;
var old_index = app_page_parameters.player_setting_area;
is_show_hint = config.getCheckboxSettingStatus('hotKeyHint');
function hot_run(e){
let id, text, index, key;
let keybindings = config.findKeyBinding(kb.delSpace(kb.stringifyKeyCode(e)));
if(keybindings.length){
id = keybindings[0]['id'];
text = e.type === 'keyup' ? keybindings[0]['text'] + e.type : keybindings[0]['text'];
index = keybindings[0]['index'];
key = keybindings[0]['key'];
};
keybindings.forEach(element => {
//log(element)
//log(text)
});
//特例
if(keybindings.length && e.type === 'mousewheel' && text !== '非全屏音量调节${step}%'){
e.preventDefault();
e.stopPropagation();
}
// log(id)
// log(text)
// log(text+id)
// log('非全屏音量调节\${step}%'+id)
// log((text+id) === '非全屏音量调节\${step}%'+id)
if(text === '快进/快退时显示醒目进度条'){ //快进时显示醒目进度条 && 段落循环
//log( $('#hhh_loop_wrap')[0].hhh_loop_time_id );
// if(0&&$('#hhh_loop_wrap')[0].hhh_loop_time_id === true){
// return false;
// }else{
if(config.getCheckboxSettingStatus('reloadDanmuku') === ON) {
//恢复重载弹幕效果
e.stopPropagation();
h5Player.currentTime = index === 0 ? h5Player.currentTime - 5 : h5Player.currentTime + 5;
h5Player.play();
setTimeout(function(){
$(bb['danmakuSwitch']).last().find('input').click();
$(bb['danmakuSwitch']).last().find('input').click();
},0);
}
dynamicProgress(12, 2);
//}
} else if(text === '合理空格键') { //空格键2.X版本不合理,改成和3.X版本一样,3.X版也o了
if( config.getCheckboxSettingStatus('dynamicSpace') === ON && !is_fullscreen()){
if(is_in_biliplayer === false) e.stopPropagation()
}
} else if(text === '优先取消右键菜单等') { //优先取消右键菜单等 Esc
if($(bb['hotkeyPanel']).length === 1 && ($(bb['hotkeyPanel']).hasClass('active') === true || $(bb['hotkeyPanel']).css('display') !== 'none')){
//$(bb['hotkeyPanel']).removeClass('active').css('display', 'none');
$(bb['hotkeyPanel']).find(bb['hotkeyPanelClose']).click(); //慢
return false;
}
if($(bb['playerContextMenu']).hasClass('active') === true || $(bb['playerContextMenu']).hasClass('bpx-player-active') === true ){
let evt = new MouseEvent('contextmenu', { clientX:-9999, clientY:-9999 });
$(bb['videoWrap'])[0].dispatchEvent(evt);
return false;
}
if($('#hhh_img').length >= 1 && $('#hhh_img').css('display') !== 'none'){
$('#hhh_img').css('display', 'none');
return false;
}
} else if(text === '有投币框时回车投币') { //有投币框时回车投币 Enter
//log($(bb['coinDlgOkBtn']).length)
// if($(bb['coinDlgOkBtn']).length === 1){
// $(bb['coinDlgOkBtn']).click();
// }
} else if(text === '关灯/开灯') { //开关灯
$('#hhh_lightoff input').click();
} else if(text+id === '非全屏音量调节${step}%'+'onePerVolumeControl') { //非全屏音量调节 0~1 (b站默认"滚轮"(如果使用滚轮的话)操作某些情况会失效,一并处理全屏情况)
//两个参数指定屏幕范围(按百分比),第三个参数表示滚动一下增加的音量百分比,参数四表示暂停时是否调节
let tempargs = config.getCheckboxSettingTempArgs(key);
let delta = 1 //默认1%
for(v of config.getCheckboxSettingTempArgs(id)){
if(v?.name === 'step') { delta = parseInt(v.value); break }
}
let args = config.getCheckboxSettingArgs('volumeControlWhenNonFullScreen'),
isWheelVolume = config.getCheckboxSettingStatus('volumeControlWhenNonFullScreen'),
screen_left = args.screen_left,
screen_rght = args.screen_rght,
isPauseVolume = config.getCheckboxSettingStatus('volumeControlWhenPause');
if(isWheelVolume === OFF) return;
//缺省屏幕百分比参数,默认0.3~0.7
screen_left = (screen_left<0 || screen_left>1)? 0.3: screen_left;
screen_rght = (screen_rght<0 || screen_rght>1)? 0.7: screen_rght;
//缺省音量百分比,默认1
delta = (delta<1 || delta>100)? 1: delta;
//非暂停(可选) && 鼠标在屏幕指定位置时处理
let isPauseStillRun = isPauseVolume || h5Player.paused === false;
let Rect = $(bb['videoWrap'])[0].getBoundingClientRect();
let offsetX = e.originalEvent.x - Rect.x;
let inLimit = offsetX > Rect.width*screen_left && offsetX < Rect.width*screen_rght;
if(is_fullscreen() || (isPauseStillRun && (inLimit || e.type !== 'mousewheel'))) {
//阻止页面滚动 && 阻止冒泡
if(e.type === 'mousewheel'){
e.preventDefault();
e.stopPropagation();
}
let v = volume();
if(index === 0 || index === 2) { //向上滚动,减少音量
volume(+(v+(delta/100)).toFixed(3)); //+ string to number
} else if(index === 1 || index === 3) { //向下滚动,增大音量
volume(+(v-(delta/100)).toFixed(3));
}
}
} else if(text+id === '非全屏音量调节${step}%'+'fivePerVolumeControl') { //音量控制,替换系统默认 let tempargs = config.getCheckboxSettingTempArgs(key);
let delta = 0.05 //默认5%
for(v of config.getCheckboxSettingTempArgs(id)){
if(v?.name === 'step') { delta = parseInt(v.value)/100; break }
}
let diff = index === 0 ? delta : -delta;
window.setTimeout((function() { //长按时保持DOM更新
volume(volume()+diff);
}),10);
return false;
} else if(text === '全屏') { //全屏
fullscreen();
} else if(text === '网页全屏') { //网页全屏 B站改成点赞了
web_fullscreen();
e.stopPropagation();
} else if(text === '宽屏模式') { //宽屏模式 B站改成投币了
is_fullscreen() ? web_fullscreen() : wide_screen();
e.stopPropagation();
} else if(text === '开关顶部/底部弹幕') { //开关顶部弹幕
if(index === 0){
$(bb['danmukuTopClose']).length === 0 ? showHint(parent, '#hhh_wordsHint', '关闭顶部弹幕') : showHint(parent, '#hhh_wordsHint', '打开顶部弹幕');
dm_remember(function(){$(bb['danmukuTop']).click()});
}else{
$(bb['danmukuBottomClose']).length === 0 ? showHint(parent, '#hhh_wordsHint', '关闭底部弹幕') : showHint(parent, '#hhh_wordsHint', '打开底部弹幕');
dm_remember(function(){$(bb['danmukuBottom']).click()});
}
} else if(text === '开关弹幕') { //开关弹幕 bilibili增加了关弹幕的快捷键,也是D
$(bb['danmakuSwitch']).last().find('input').click();
is_show_hint && (is_danmaku_show() === true ? showHint(parent, '#hhh_wordsHint', '开弹幕') : showHint(parent, '#hhh_wordsHint', '关弹幕'));
e.stopPropagation();
} else if(text === '洗脑循环') { //开关洗脑循环 B站改成一键三连了
$(bb['playSettingRepeatInput'])[0].checked ? showHint(parent, '#hhh_wordsHint', '关洗脑循环') : showHint(parent, '#hhh_wordsHint', '开洗脑循环');
$(bb['playSettingRepeatInput']).click();
e.stopPropagation();
} else if(text === '弹幕随屏幕缩放') { //弹幕随屏幕缩放
$(bb['settingFs'])[0].checked === false ? showHint(parent, '#hhh_wordsHint', '弹幕随屏幕缩放') : showHint(parent, '#hhh_wordsHint', '弹幕不随屏幕缩放');
dm_remember(function(){$(bb['settingFs']).click()});
} else if(text === '增减弹幕透明度${step}%' ) { //滚轮调节弹幕透明度(ctrl+滚轮),参数表示滚动一下增加的透明度百分比
if(config.getCheckboxSettingStatus('danmuOpacityControl') === OFF) return;
//阻止页面滚动 && 阻止冒泡
//e.preventDefault();
//e.stopPropagation();
//缺省透明度百分比,默认5
let delta = 5 //默认5%
for(v of config.getCheckboxSettingTempArgs(id)){
if(v?.name === 'step') { delta = parseInt(v.value); break }
}
//let delta = parseInt(config.getCheckboxSettingArgs('danmuOpacityControl').delta);
delta = (delta<0 || delta>100)? 5: delta;
var opacity;
if(index === 0) { //向上滚动,增大透明度
opacity = adjust_progress(bb['settingOpacity'], delta, 10, 100);
} else if(index === 1) { //向下滚动,减少透明度
opacity = adjust_progress(bb['settingOpacity'], -delta, 10, 100);
}
if(opacity !== undefined) showHint(document, '#hhh_opacityHint', '透 '+opacity);
} else if(text === '减增弹幕透明度${step}%') { //+ -弹幕透明度
let inc_percent = 10 //默认10%
for(v of config.getCheckboxSettingTempArgs(id)){
if(v?.name === 'step') { inc_percent = parseInt(v.value); break }
}
inc_percent = index === 0 ? -inc_percent : inc_percent;
window.setTimeout((function() { //长按时保持DOM更新
dm_remember(function(){
let opacity = adjust_progress(bb['settingOpacity'], inc_percent, 10, 100);
showHint(parent, '#hhh_opacityHint', '透 ' + opacity);
});
}),10);
} else if(text === '减增弹幕字号${step}%') { //+ -弹幕字号
let inc_percent = 10 //默认10%
for(v of config.getCheckboxSettingTempArgs(id)){
if(v?.name === 'step') { inc_percent = parseInt(v.value); break }
}
inc_percent = index === 0 ? -inc_percent : inc_percent;
//let inc_percent = index === 0 ? -10 : 10;
window.setTimeout((function() { //长按时保持DOM更新
dm_remember(function(){
let opacity = adjust_progress(bb['settingFontsize'], inc_percent, 50, 170);
showHint(parent, '#hhh_opacityHint', '字 ' + opacity);
});
}),10);
} else if(text === '弹幕显示区域 1/4屏~不限') { //弹幕显示区域
dm_remember(function(){
var area_text = {0:'1/4屏',25:'半屏',50:'3/4屏',75:'不重叠',100:'不限'};
var percent = index * 25; //((0~4)*25)%
//弹幕显示区域大到小切换时清空弹幕
if(old_index > index){
setTimeout(function(){
$(bb['danmakuSwitch']).last().find('input').click();
$(bb['danmakuSwitch']).last().find('input').click();
},0);
}
old_index = index;
set_progress(bb['settingArea'], percent, 0, 100);
showHint(parent, '#hhh_wordsHint', area_text[percent]);
});
} else if(text === '快进/快退${second}s') { //+ -30s ctrl+ left/right
h5Player = geth5Player()
$(bb['danmakuSwitch']).last().find('input').click().click()
let second = 30 //默认30s
for(let v of config.getCheckboxSettingTempArgs(id)){
if(v?.name === 'second') { second = parseInt(v.value); break }
}
h5Player.currentTime = index === 0 ? +h5Player.currentTime - second : +h5Player.currentTime + second;
h5Player.play();
dynamicProgress(12, 2);
} else if(text === '逐帧操作') { //逐帧 shift+ left/right
h5Player.pause();
for(let move_frames = 1.01; move_frames>0.1;){
let move_frames_time = move_frames/fps;
h5Player.currentTime = index === 0 ? +(h5Player.currentTime - move_frames_time).toFixed(3) : +(h5Player.currentTime + move_frames_time).toFixed(3);
if(prev_time === h5Player.currentTime){ //如果未走帧
move_frames /= 2;
//log('2.1: h5currTime: '+h5Player.currentTime+' - prev_time: '+prev_time+' - '+move_frames_time+' - '+move_frames);
continue;
}
else{
//log('2.2: h5currTime: '+h5Player.currentTime+' - prev_time: '+prev_time+' - '+move_frames_time+' - '+move_frames);
let total_frame = +(h5Player.duration*fps).toFixed();
let current_frame = +(h5Player.currentTime*fps).toFixed();
showHint(parent, '#hhh_wordsHint', `${current_frame}/${total_frame}`);
prev_time = h5Player.currentTime;
break;
}
}
e.stopPropagation();
} else if(text === '调节视频播放速度') { //ctrl + ↑↓
if(config.getCheckboxSettingStatus('keyVideoSpeed') === OFF) return;
window.setTimeout((function() { //长按时保持DOM更新
index === 0 ? video_select_speed(1) : video_select_speed(-1);
}),10);
} else if(text === '调节自定义倍速速度') { //shift + ↑↓
if(config.getCheckboxSettingStatus('customPlayRate') === OFF) return
const args = config.getCheckboxSettingArgs('customPlayRate')
const newrate = Math.max(0, (index === 0 ? args.rate + 0.5 : args.rate - 0.5))
const new_args = {rate: newrate}
config.setCheckboxSettingArgs('customPlayRate', {...args, ...new_args})
showHint(parent, '#hhh_wordsHint', `→${newrate.toFixed(1)}x`)
customPlayRate(config.getCheckboxSettingStatus('customPlayRate'), config.getCheckboxSettingArgs('customPlayRate')['rate']);
} else if(text === '点赞、投币、收藏、长按一键三连') { //长按一键三连(keydown) - 对应系统快捷键 Q、R、W、E
if(index === 0 || index === 3){ //点赞、三连
$(bb['like'])[0].dispatchEvent( new MouseEvent('mousedown') );
if(like_shake === false) like_shake = !!$('.van-icon-videodetails_like.shake').length;
}else if(index === 1){ //投币
$(bb['coin']).click();
//set_dialog('coin');
}else if(index === 2){ //收藏
$(bb['collect']).click();
}
} else if(text === '点赞、投币、收藏、长按一键三连'+'keyup') { //点赞;长按一键三连(keyup)
if(index === 0 || index === 1){
$(bb['like'])[0].dispatchEvent(new MouseEvent('mouseup'));
if(index === 0 && like_shake === false) {
let like_text = $(bb['like']).text().match(/.+/)[0];
let like_num = like_text.match(/\d+$/)? (+like_text.match(/\d+$/)[0])+1: like_text;
if($(bb['likeon']).length === 1) showHint(parent, '#hhh_wordsHint', '取消点赞');
else showHint(parent, '#hhh_wordsHint', `点赞成功 ${like_num}`);
$(bb['like']).click();
}
like_shake = false;
}
//TEST
} else if(e.type === 'keydown' && (e.keyCode === 'X'.charCodeAt() || e.keyCode === keycode['/'])) { //TEST 显示、隐藏video-control
if(bb_type.indexOf(BILI_2_X) !== -1){
if($(bb['playArea']).hasClass('video-control-show') === true) $(bb['playVideoControlWrap']).mouseout();
else $(bb['playVideoControlWrap']).mousemove();
}else{
if($('.bpx-player-container').attr('data-ctrl-hidden') === "true"){
$('.bpx-player-container').attr('data-ctrl-hidden', "false");
$('.bpx-player-control-entity').attr('data-shadow-show','false');
}else{
$('.bpx-player-container').attr('data-ctrl-hidden', "true");
$('.bpx-player-control-entity').attr('data-shadow-show','true');
}
}
} else if(e.type === 'keydown' && (e.keyCode === 'H'.charCodeAt())) { //TEST
//if(bb_type===BILI_3_X_MOVIE) $('.bpx-player-dm-setting-wrap').css('display','block');
$('.bilibili-player-video-danmaku-setting-wrap').mouseover();
//$('.bilibili-player-area.video-state-blackside').attr('class', 'bilibili-player-area video-state-blackside video-state-pause video-control-show');
} else{
//console.dir(e.keyCode);
}
}
//key
function global_binding_key(){
$(document).off('keydown.hhh_lightoff keyup.hhh_lightoff');
$(document).on('keydown.hhh_lightoff keyup.hhh_lightoff',function(e){
//跳过输入框
if(!!e.target.type && e.target.type.toLowerCase().search(/text|textarea/) !== -1) return;
if(e.target.className === 'ql-editor') return;
//处理键盘及鼠标
return hot_run(e);
});
}
//wheel
function global_binding_wheel(){
$(bb['videoWrap']).off('mousewheel.hhh_lightoff');
$(bb['videoWrap']).on('mousewheel.hhh_lightoff',function(e){
//处理键盘及鼠标
e.keyCode = e.originalEvent.wheelDelta >= 120 ? '300' : '301'; //滚轮上滚和下滚
return hot_run(e);
});
}
global_binding_key();
global_binding_wheel();
}
}
//添加
`
)
//creat
for (let [key, {text, status, args}] of Object.entries(config.sets[group].options)) {
if(!args) continue
let name = 'checkbox_setting';
let $container = $(`
`);
if(key === 'customPlayRate'){ //自定义倍速
$container.append(`
`)
}else if(key === 'expandList'){ //订阅合集列表自动展开
$container.append(`
`)
}else if(key === 'danmuOpacityControl'){ //弹幕透明度控制
$container.append(`
`)
}else if(key === 'volumeControlWhenNonFullScreen'){ //鼠标在指定屏幕范围内音量调节
$container.append(`
`)
}
if($container.find(`input[name=${name}]`).length > 0){
$(`#${key}`).append($container);
checkbox_args_update(key, status);
if(bb_type.indexOf(BILI_3_X_VIDEO) !== -1) tip_create_3_X({ target: $container, tip_target: $('#hhh_tip'), color: '#00ffff', title: args.args_opt.tip[0], gap: 1 });
input_number_max_width = Math.max(input_number_max_width, $(`#${key}`).find('.hhh-bpx-player-dm-setting_container').outerWidth()); //记录最大宽度
//log(input_number_max_width);
}
}
//add event
checkbox_args_event();
}
//设置【checkbox】点击 click
function checkbox_event(){
$item_2.find('#hhh_input_div').off('click.hhh_checkbox');
$item_2.find('#hhh_input_div').on('click.hhh_checkbox', function(e){
let target = e.target;
if(target.type === 'checkbox'){ //一级选择框设置
let key = bb_type.indexOf(BILI_2_X) !== -1 ? target.parentNode.id : target.parentNode.parentNode.parentNode.id;
let status = target.checked;
//log('checked: '+e.target.checked)
config.setCheckboxSettingStatus(key, status);
config.storageCheckboxSetting();
let fn = config.getCheckboxSettingFn(key);
let args = config.getCheckboxSettingArgs(key);
//设定参数设置
checkbox_args_update(key, status);
checkbox_go(key, status, fn, args);
}
})
}
//生成checkbox
function checkbox_init(group){
let len = 0;
//按行添加
for (let [key, {text, status, tip}] of Object.entries(config.sets[group].options)) {
//log(text+' - '+tip)
++len;
let $key = $input.clone().appendTo($input_div).attr('id', key).css('width', 'auto')
.find('input').prop('checked', status).end()
.find('.bui-checkbox-name').text(text).end();
input_max_width = Math.max(input_max_width, $key.find('label').outerWidth()); //记录最大宽度
//log('--'+$key.find('label').width());
//log($key.find('input').width());
/////////////////////
//$key.find('input').width($key.find('label').width());
//set tips
if(bb_type.indexOf(BILI_2_X) !== -1){
!!tip && add_tip($tip, $key.find('.bpx-player-dm-setting-left-flag-title'), {'text':tip, 'millisec':200, 'top':9, 'left':0});
}else{
!!tip && tip_create_3_X({ target: $key.find('.bpx-player-dm-setting-left-flag-title'), tip_target: $('#hhh_tip'), title: tip, gap: 6 });
}
}
//填充空行
let one_input_height = +$input_div.children(':first').outerHeight() + (+$input_div.children(':first').css('margin-top').match(/\d+/)[0]);
for(; len<=18; len++){
$div.clone().appendTo($input_div).css({height: `${one_input_height}px`});
}
//add event
checkbox_event();
}
//初始化【group】和【checkbox】
function input_init(){
for(let [group, {options, btn, type}] of Object.entries(config.sets)){
$cover.clone().appendTo($group_div).attr('id', group) //复用封面DOM模板
.css({height: '22px'/*, border: '1px solid hsla(0,0%,100%,.2)'*/})
.find(bb['dmRightMoreText']).text(btn+'(点击)').end();
//$reset.clone().appendTo($group_div).attr('id', group) //复用封面DOM模板
// .css({height: '22px', display: 'flex'}).text(btn+'(点击)');
$(`#${group}`).click(function(){
config.group = group;
//
//if($('body')[0].hhh_body_key_event !== '快捷键设置') return;
//$('body')[0].hhh_body_key_event = group;
//取消激活
let $active = $group_div.find('.active');
let active_text = $active.find(bb['dmRightMoreText']).text();
$active.find(bb['dmRightMoreText']).text(active_text.split('***')[0]);
$active.removeClass('active');
//激活
let text = $(this).find(bb['dmRightMoreText']).text();
$(this).find(bb['dmRightMoreText']).text(text+'***');
$(this).addClass('active');
$input_div.empty();
if(type == 'checkbox') {
checkbox_init(group);
$input_div.css('width', `${all_checkbox_width}`);
$wrap.css({'height': $item_2.css('height'), 'width': $item_2.css('width')});
$move.css('transform', `translateX(-${old_width}px)`);
$('#hhh_item_2_more').parent().css({'justify-content': 'space-between'}); //设置"返回"位置
checkbox_args_init(group);
}
else if(1&&type == 'key') {
set_keybindings($input_div);
$input_div.css('width', 'auto');
$('#hhh_item>div:first').css({'height':'max-content','width':'max-content'})
$wrap.css({'height': $item_2.css('height'), 'width': $item_2.css('width')});
$move.css('transform', `translateX(-${old_width}px)`);
$('#hhh_item_2_more').parent().css({'justify-content': 'flex-end'}); //设置"返回"位置
}
})
}
}
input_init();
//添加恢复默认设置
$reset.appendTo($item_2_div);
//重设置【item_2 - 恢复默认设置】 click
$reset.click(function(){
config.defaultCheckboxSetting();
config.storageCheckboxSetting();
for(let [group, {options, type}] of Object.entries(config.checkboxes)){
if(type === 'checkbox'){
for (let [key, { status, fn, args }] of Object.entries(options)) {
//if(config.getCheckboxSettingStatus(key) === status) continue;
$(`#${key}`).find('input').prop('checked', status);
//设定参数设置
checkbox_args_update(key, status);
checkbox_go(key, status, fn, args);
}
}
}
$(`#${config.group}`).click(); //更新
})
/*-----------------------------------
* 下部div
*----------------------------------*/
//添加分割线
$separator.clone().appendTo($item_2_div);
//添加返回
//$reback.clone().appendTo($item_2_div);
//TEST
let $bottom_div = $div.clone();
$bottom_div.appendTo($item_2_div).css({display:'flex', 'justify-content':'space-between'});
$reback.clone().appendTo($bottom_div);
//总在最上
let $always_top = $input.clone().appendTo($bottom_div).attr('id', 'hhh_always_top').css('width', 'auto')
.css({'margin':'2px 0px 5px 20px'})
.find('input').prop('checked', false).end()
.find('.bui-checkbox-name').text('总在最上').end();
let boserver;
$always_top.click(function(e){
if(e.target.type === 'checkbox'){
let checkbox = e.target;
if(e.target.checked === ON){
//鼠标离开时panel保持在最上
boserver?.disconnect();
boserver = new MutationObserver((mutations, observer) => {
mutations.forEach(mutation => {
const target = mutation.target;
if(typeof target.className === 'string' && target.className !== ''){
//console.log(target.className +' | '+mutation.attributeName);
$(target).show();
}
});
});
boserver.observe($(bb['dmWrap'])[0], { attributes: true });
//鼠标是否在弹幕设置界面内
document.onmouseup = function(e){
let path = e.path;
//log(path)
let is_in_dm_setting_panel = false;
$(path).each(function(){
if(this.className === 'bui-panel-wrap') { is_in_dm_setting_panel = true; return; }
})
if(is_in_dm_setting_panel === false){
document.onmouseup = null;
checkbox.checked = OFF;
boserver?.disconnect();
$(bb['dm'])[0].dispatchEvent(new MouseEvent('mouseleave'));
}
}
}else{
document.onmouseup = null;
boserver?.disconnect();
}
}
})
/*-----------------------------------
* 添加事件等
*----------------------------------*/
//重设置【自定义设置按钮】
// $DSet.mouseenter(function(){
// $wrap.css('height', $DSet.find('.bui-panel-item-active').css('height'));
// })
//重设置【item_0 - 自定义设置】 click
$('#hhh_custom').click(function(){
$wrap.css({'height': $item_2.css('height'), 'width': $item_2.css('width')});
$move.css('transform', `translateX(-${old_width}px)`);
$DSet.find('.bui-panel-item-active').removeClass('bui-panel-item-active');
$item_2.addClass('bui-panel-item-active');
$(`#${Object.keys(config.sets)[0]}`).click(); //设置第一项
})
//重设置【item_1 - 更多弹幕设置】 click
$item_1.find(bb['dmRightMore']).click(function(){
$item_0.css('height', item_0_height); //会改变item_0长度
$wrap.css({'height': $item_0.css('height'), 'width': $item_0.css('width')});
})
//重设置【item_2 - 返回】 click
$item_2.find('#hhh_item_2_more').click(function(){
$wrap.css({'height': $item_0.css('height'), 'width': $item_0.css('width')});
$move.css('transform', 'translateX(0px)');
$DSet.find('.bui-panel-item-active').removeClass('bui-panel-item-active');
$item_0.addClass('bui-panel-item-active');
})
//重设置【item_2 - 封面】 click
$item_2.find('#hhh_item_2_cover').click(function(){
if($('#hhh_img').length === 1){
let $hhh_img = $('#hhh_img');
//let width = $(bb['video']).width()*0.9;
//$('#hhh_img').css('width', width);
$hhh_img.css('display') === 'none'? $hhh_img.css('display', 'flex'): $hhh_img.css('display', 'none');
} else {
let $img = $(`
.attr('content').replace('http:','https:')})
`);
let $d = $div.clone().attr('id', 'hhh_img')
.css({position: 'absolute', top:'50%', left:'50%', transform: 'translate(-50%,-50%)'})
.css({'z-index':`${$(bb['playTipWrap']).css('z-index')}`})
.css({'display':'flex'})
//.css('width',width)
.css({'align-items':'center','justify-content':'center'})
.appendTo($(bb['videoWrap']));
$img.css({width:'100%', height:'auto'}).appendTo($d);
//重设置【item_2 - 封面 - IMG】
$('#hhh_img').click(function(){
$(this).css('display','none');
window.open($(bb['coverImg']).attr('content').replace('http:','https:'));
})
}
})
//重设置【item_2 - 快捷键说明】 click
let set_hotkey_panel_close = false;
$item_2.find('#hhh_item_2_hotkey').click(function(){
let is_active = bb_type.indexOf(BILI_2_X) !== -1 ? $(bb['hotkeyPanel']).hasClass('active') : $(bb['hotkeyPanel']).css('display') !== 'none';
//2.X和3.X不一样?我来让你一样!
if(is_active === false){
let evt = new MouseEvent('contextmenu', { clientX:-9999, clientY:-9999 });
$(bb['videoWrap'])[0].dispatchEvent(evt);
evt = bb_type.indexOf(BILI_2_X) !== -1? new MouseEvent('click', { bubbles:true }): new MouseEvent('mousedown', { bubbles:true });
let node = bb_type.indexOf(BILI_2_X) !== -1? 'a': 'li';
$(bb['playerContextMenu']).find(`${node}:contains("快捷键说明(bilibili关灯)")`)[0].dispatchEvent(evt);
let $last_system_itme = $('#hhh_last_system_hotkey_panel_item');
$last_system_itme.prevAll().css('display','none');
$last_system_itme.css('display','none');
$last_system_itme.nextAll().css('display','block');
//$(bb['playerContextMenu']).find(`li:contains("快捷键说明(bilibili关灯)")`).mousedown();
let $hotkey = $(bb['hotkeyPanel']);
//let $hotkey = $(bb['hotkeyPanel']).css('z-index', $(bb['playVideoControlWrap']).css('z-index')-1);
//同步显示
// let wrap_left = $(bb['dmWrap']).position().left;
// let box_left = $(bb['dmBox']).position().left;
// $(bb['dmWrap']).css('left', wrap_left + $item_0.width());
// $(bb['dmBox']).css('left', box_left - $item_0.width());
// $(bb['dmWrap']).css('height', $hotkey.innerHeight());
// $(bb['dmWrap']).css('width', $hotkey.innerWidth()-50);
// $(bb['dmBox']).css('width', item_2_width);
//$(bb['dmWrap']).css('background', 'blue').css('opacity', 0.8); //test
//同步隐藏
// waitForTrue(()=> ($(bb['hotkeyPanel']).hasClass('active') === false && $(bb['hotkeyPanel']).css('display') === 'none') || $(bb['dmWrap']).css('display') === 'none', () => {
// //$(bb['hotkeyPanel']).removeClass('active').css('display', 'none');
// $(bb['hotkeyPanelClose']).click();
// });
let new_left = $item_2.offset().left + $item_2.width();
let new_top = $hotkey.offset().top + ($item_2.offset().top + $item_2.height()) - ($hotkey.offset().top + $hotkey.innerHeight());
$hotkey.offset({left:new_left, top:new_top});
//$hotkey.offset({left:new_left, top:new_top}).find(bb['hotkeyPanelClose']).css('display', 'none');
if(set_hotkey_panel_close === false){ //
set_hotkey_panel_close = true;
$(bb['hotkeyPanelClose']).click(function(){
$(bb['hotkeyPanel']).css({left: '50%', top:'50%'});
})
}
}else{
$(bb['hotkeyPanel']).css({left: '50%', top:'50%'});
$(bb['hotkeyPanelClose']).click();
// $(bb['dmWrap'])[0].style.cssText = '';
// $(bb['dmBox'])[0].style.cssText = '';
// $(bb['dmWrap']).css('display', 'block');
}
})
let id = 0;
//重设置弹幕设置触发按钮
$DSet.on('mouseenter', function(){
clearInterval(id);
if ($(bb['dmWrap']).css('display') !== 'none') return;
$item_0.css('height', $item_0[0].hhh_new_height);
$wrap.css({'height': $item_0.css('height'), 'width': $item_0.css('width')});
$move.css('transform', 'translateX(0px)');
$move.css('width', '10000px'); //留出足够空间,省事
$DSet.find('.bui-panel-item-active').removeClass('bui-panel-item-active');
$item_0.addClass('bui-panel-item-active');
$(bb['dmWrap'])[0].style.cssText = '';
$(bb['dmBox'])[0].style.cssText = '';
}).on('mouseleave', function(){ //解决mouseleave和bb['dmWrap']).css('display')不同步的问题
clearInterval(id);
id = setInterval(() => {
if ($(bb['dmWrap']).css('display') !== 'none') return;
clearInterval(id);
let $main = $('.keybindings-editor');
$main.find('.monaco-list-rows').off('click.hhh_widget_listrow');
$main.find('.monaco-list-rows').off('dblclick.hhh_widget_listrow');
$main.find('input').off('keydown.hhh_widget_input');
$main.find('input').off('keyup.hhh_widget_input');
$main.find('input').add('.defineKeybindingWidget').off('mousewheel.hhh_widget_input');
$main.find('input').off('blur.hhh_widget_input');
$('body').off('keydown.hhh_widget_listrow');
$('body').off('keydown.hhh_checkbox_args');
}, 200);
});
// $DSet.on('mouseleave', function(){
// return false;
// })
//执行所有默认设置
if(run_default_setting_flag === 'run_default_setting') $reset.click();
//初始化【checkbox】
$(bb['dm'])[0].dispatchEvent(new MouseEvent('mouseenter'));
$(bb['dm'])[0].dispatchEvent(new MouseEvent('mouseover'));
$(bb['dmWrap']).css('visibility', 'hidden');
Object.keys(config.sets).forEach((kname)=>{ if(config.sets[kname].type === 'checkbox') $(`#${kname}`).click() }); //点击所有checkbox,得到最大宽度
$(bb['dm'])[0].dispatchEvent(new MouseEvent('mouseout'));
$(bb['dm'])[0].dispatchEvent(new MouseEvent('mouseleave'));
//$(bb['dmWrap']).css('visibility', 'visible');
all_checkbox_width = input_max_width + input_number_max_width + 'px';
}
//记忆弹幕操作
function dm_remember(setting_func){
// if(bb_type.indexOf(BILI_3_X_VIDEO) !== -1) $('.squirtle-controller-wrap').css({"display":"flex"});
// $(bb['dmWrap']).css({"display":"block"});
$(bb['dm'])[0].dispatchEvent(new MouseEvent('mouseenter'));
//$(bb['dm'])[0].dispatchEvent(new MouseEvent('mouseover'));
setting_func();
//$(bb['dm'])[0].dispatchEvent(new MouseEvent('mouseout'));
$(bb['dm'])[0].dispatchEvent(new MouseEvent('mouseleave'));
// $(bb['dmWrap']).css({"display":"none"});
// if(bb_type.indexOf(BILI_3_X_VIDEO) !== -1) $('.squirtle-controller-wrap').css({"display":"none"});
}
//因为遮挡弹幕,去掉全屏时鼠标悬停时产生的顶端mask
function removeVideoTopMask(is_remove){
let top_mask_class = bb['videoTopMask'].substr(1);
if(is_remove === ON) $(bb['videoTopMask']).attr('id', top_mask_class).removeClass();
else $(`#${top_mask_class}`).addClass(top_mask_class);
}
//播放关灯,暂停开灯,跳过充电
function lightOffWhenPlaying(status){
$(h5Player).off('play.hhh'); if(status === OFF) return;
$(h5Player).on('play.hhh', ()=> !is_lightoff() && lightoff_btn());
}
function lightOnWhenPause(status){
$(h5Player).off('pause.hhh'); if(status === OFF) return;
$(h5Player).on('pause.hhh', ()=> is_lightoff() && lightoff_btn());
}
function jumpElectric(status){
$(h5Player).off('ended.hhh'); if(status === OFF) return;
$(h5Player).on('ended.hhh', ()=> $(bb['playJumpElectric']).click());
}
//自动打开弹幕
function autoOpenDanmu(){
$('body')[0].addEventListener('DOMSubtreeModified', function fn_(e) {
//typeof e.target.className === 'string' && e.target.className !== '' && log(e.target.className);
//log($(bb['danmakuSwitch']).last().find('input')[0].checked)
let $target = $(e.target);
if($target.hasClass('bilibili-player-video-info-people-number') || bb_type.indexOf(BILI_3_X_VIDEO) !== -1) {
this.removeEventListener('DOMSubtreeModified', fn_);
//this.removeEventListener('DOMSubtreeModified', arguments.callee);
let $danmaku = $(bb['danmakuSwitch']).last().find('input');
if($danmaku[0].checked === false) $danmaku.click();
let t = setInterval(() => {
if($danmaku[0].checked === false) $danmaku.click();
}, 200);
setTimeout(() => { clearInterval(t) }, 2000);
}
});
}
//隐藏屏幕三连弹窗
function hideThreePopup(status){
let $popup = $('.bpx-player-popup-show');
if($popup.find('.bpx-player-popup-three').length === 0) return;
if(status === ON) $('.bpx-player-popup-show').hide();
else $('.bpx-player-popup-show').show();
}
//隐藏屏幕打分弹窗
function hideScorePopup(status){
let $popup = $('.bpx-player-popup-show');
if($popup.find('.bpx-player-popup-vote').length === 0) return;
if(status === ON) $('.bpx-player-popup-show').hide();
else $('.bpx-player-popup-show').show();
}
//双击或中键全屏
function dblclickFullScreen(status){
$(bb['videoWrap']).off('mousedown.hhh'); if(status === OFF) return;
$(bb['videoWrap']).on('mousedown.hhh', function(e){
if(e.button === 1 || e.button === 4 || e.button === 3) { // 1中键
if(e.button === 1) web_fullscreen();
else fullscreen();
e.preventDefault(); e.stopPropagation();
}
});
//$(bb['playTipWrap']).dblclick(function(){ fullscreen() }); //2.66自带双击全屏
}
//扩展播放倍速范围
function extend_video_speed(){
let $speedul = $(bb['videoSpeedActive']).parent();
let ratios = ['0.1x','0.5x','0.75x','1.0x','1.25x','1.5x','1.75x','2.0x','2.5x','3.0x','3.5x','4.0x','4.5x','5.0x'];
let $li = $speedul.find('li:first').clone(true, true);
$speedul.empty();
ratios.forEach(ratio => {
$this = $li.clone().prependTo($speedul).text(ratio);
$this.attr('data-value', `${$this.text().split('x')[0]}`);
});
let speed_active = (bb_type === BILI_3_X_MOVIE)? 'active': (bb_type.indexOf(BILI_3_X_VIDEO) !== -1)? 'bpx-state-active': 'bilibili-player-active';
$speedul.find('li:contains("1.0x")').addClass(speed_active);
$speedul.on('click', function(e){
let $li = $(e.target);
let speed = $li.attr('data-value');
if(speed !== undefined){
h5Player.playbackRate = +speed;
setTimeout(function(){
let speed_active = (bb_type === BILI_3_X_MOVIE)? 'active': (bb_type.indexOf(BILI_3_X_VIDEO) !== -1)? 'bpx-state-active': 'bilibili-player-active';
$(bb['videoSpeedActive']).removeClass(speed_active);
$li.addClass(speed_active);
$(bb['videoSpeedName']).text($li.text());
},0)
}
})
}
//调节视频倍速
function video_select_speed(level) {
let $speedul = $(bb['videoSpeedActive']).parent();
let data_x = [];
$speedul.find('li').each(function(){ data_x.unshift($(this).text()) }); //类似['0.5x', '0.75x', '1.0x', '1.25x', '1.5x', '2.0x'];
let curr_x = $(bb['videoSpeedActive']).text();
let x = data_x[data_x.indexOf(curr_x) + level];
//log(curr_x+' - '+x+' - '+data_x.indexOf(curr_x));
if(x === undefined) { x = curr_x; }
$(`${bb["videoSpeed"]}:contains("${x}")`).click();
showHint(parent, '#hhh_wordsHint', x);
}
//计算坐标
function tip_calc_xy_3_X(t){
let crects = t.target[0].getBoundingClientRect(),
trects = t.tip_target[0].getBoundingClientRect(),
tip_height = trects.height,
tip_width = trects.width,
width = crects.width,
top = crects.top - tip_height,
left = crects.left + (width - tip_width) / 2;
return {x:left, y:top};
}
//创建tip
function tip_create_3_X(et){
function show_tip(t){
//显示及渐隐效果(抄bilibili^^)
let o = t.tip_target,
tip = t.target.data('tip'),
color = t.color || 'white',
text = (typeof tip === 'function' && tip()) || tip;
o.find('div').css({color: color}).text(text);
let xy = tip_calc_xy_3_X(t),
target = t.target[0];
clearTimeout(target.showHintTimer),
target.showHintTimer = window.setTimeout((function() {
//log(target);
o.stop();
o.css({visibility: 'visible'});
o.css({left: xy.x, top: xy.y});
o.animate({
opacity: 1,
top: xy.y - t.gap,
}, t.duration)
}
), t.delay)
}
let $target = et.target,
$tip = et.tip_target;
$target.data('tip', et.title);
$target.mouseenter(function(e){
show_tip({
name: 'hhh_tip',
target: $target,
tip_target: $tip,
color: et.color,
position: 2,
delay: 200,
duration: 300,
gap: et.gap,
type:'show',
});
}).mouseleave(function(e){
clearTimeout($target[0].showHintTimer);
$tip.stop().css({visibility: 'hidden', opacity: 0});
})
}
//更新tip
function tip_update_3_X(t){
if(t.title !== undefined) t.target.data('tip', t.title);
tip = t.target.data('tip'),
text = (typeof tip === 'function' && tip()) || tip;
t.tip_target.find('div').text(text);
let xy = tip_calc_xy_3_X(t);
t.tip_target.css({left: xy.x, top: xy.y - t.gap});
}
//初始化tip
function tip_init() {
if(bb_type.indexOf(BILI_2_X) !== -1){
$('.bilibili-player-video-danmaku-setting-left-ps').mouseover();
waitForTrue(()=> $('.player-tooltips.tip.top-center.animation').length === 1, () => {
$tip = $('.player-tooltips.tip.top-center.animation').clone().removeClass('active');
$tip.find('.tooltip').css('background-color', 'rgba(0,0,0,0.9)');
$('.bilibili-player-video-danmaku-setting-left-ps').mouseout();
});
} else {
$(bb['playTooltipArea']).append(`
`);
}
}
//自定义倍速播放
function customPlayRate(open=OFF, rate=2){
if(open === !ON){
$(document).off('keydown.hhh_rate');
$(document).off('keyup.hhh_rate');
let $three_rate = $('.bpx-player-three-playrate-hint');
if($three_rate.length > 0) $three_rate.contents()[1].nodeValue = `倍速播放中`;
return false;
}else{
let go_id = null;
let keystrokes = 0;
let old_rate;
function kup(e){
if(e.keyCode === keycode['right']){ //right arrow down
$('.bpx-player-three-playrate-hint').css('display','none');
clearTimeout(go_id);
go_id = null;
keystrokes = 0;
h5Player.playbackRate = old_rate || h5Player.playbackRate;
}
}
function kdown(e){
if(e.keyCode === keycode['right']){ //right arrow down
if(e.ctrlKey || e.shiftKey || e.altKey) return;
if(++keystrokes === 1) old_rate = h5Player.playbackRate; //记录第一次按键时播放速度
let $three_rate = $('.bpx-player-three-playrate-hint');
if($three_rate.length > 0){
function go(op){
function g(op, i){
op.now[i] += op.steps[i];
if(op.now[i] > op.end || op.now[i] < op.start){
op.steps[i] = -op.steps[i];
}
let $r = $three_rate.find('g:first');
let $g = $r.children(`g:eq(${i})`);
$g.attr('opacity', op.now[i]);
}
g(op,0); g(op,1); g(op,2);
//恢复初始状态
if(1&&op.now[0] < op.start){
op.now[0] = op.now_init[0], op.now[1] = op.now_init[1], op.now[2] = op.now_init[2];
op.steps[0] = op.step, op.steps[1] = op.step, op.steps[2] = op.step;
//console.table(op)
}
}
//rate=倍速
function loop(rate=2){ //键盘连按大约1秒30次,间隔33毫秒
let op = (function(rate){
let start = 0.15;
let now = [0.15, 0.35, 0.55];
let end = 0.75;
let millisec = 33;
let frame = 1000 / millisec;
let cycle = end - start;
let step = cycle / (frame/rate/1.33);
return {
start: start,
now_init: JSON.parse(JSON.stringify(now)),
now: JSON.parse(JSON.stringify(now)),
end: end,
millisec: millisec,
step: step,
steps: [step, step, step],
}
})(rate);
go_id = setInterval(()=>{
go(op);
}, op.millisec);
}
if(keystrokes === 2){ //第二次按键开始倍速播放
$three_rate.css('display','');
Hanzi_digit = ['〇','一','二','三','四','五','六','七','八','九','十'][rate] || rate;
$three_rate.contents()[1].nodeValue = `${Hanzi_digit}倍速播放中`;
h5Player.play();
h5Player.playbackRate = rate;
//loop(rate); //...
}
if(keystrokes !== 1) return false; //第一次按键正常返回,执行默认操作(快进5秒)
}
}
}
$(document).off('keydown.hhh_rate');
$(document).off('keyup.hhh_rate');
$(document).on('keydown.hhh_rate',kdown);
$(document).on('keyup.hhh_rate',kup);
}
}
//抬头显示tags(视频属于哪个区)
function add_tags_to_video_title(){
let tags = [];
$('.tag-area.clearfix .tag>a').each(function(){
tags.push($(this).text())
})
$('.video-data').append(`
( ${tags.join(' | ')} )`)
}
//主程序
function run(){
//防止重复加载
if ($('#hhh_lightoff').length === 1) { log('重复加载'); return }
//bpx test
function bpx_test(){
log('-------------------');
log('ver: '+ver);
log('fps: '+fps);
log('------h5Player-----');
dir(h5Player);
log('currentTime : '+h5Player.currentTime);
log('duration : '+h5Player.duration);
log('playbackRate : '+h5Player.playbackRate);
log('volume : '+h5Player.volume);
log('paused : '+h5Player.paused);
log('pause() : '+'h5Player.pause()');
log('videoHeight : '+h5Player.videoHeight);
log('videoWidth : '+h5Player.videoWidth);
log('-------------------');
}
/*-----------------------------------
*初始化等
*----------------------------------*/
//保存设置信息 && 快捷键信息
//config.getCheckboxSetting();
//取得h5 video & window.player
h5Player = geth5Player()
//保存一些视频参数初始值
app_page_parameters.player_setting_area = $(`.bpx-player-dm-setting-left-area ${bb['progressBar']}`).width()/25;
//初始化tip
tip_init();
//初始化关灯按钮
lightoff_init();
//激活系统弹幕设置,以此调用系统网页全屏等
$(bb['dm']).mouseenter().mouseleave();
//激活系统播放设置,以此调用系统关灯等
//去掉mouseleave(),否则如果太快执行mouseleave()无法激活关灯class,应该是mouseenter()未执行完就被mouseleave打断了
$(`${bb['playVideo']}${bb['playSetting']}`).mouseenter();
//避免显示设置页面
// waitForNode(() => document.querySelector(bb['playSettingWrap']), (node) => {;
// $(node).css({"visibility":"hidden"}); //visible
// })
//解决因为激活关灯class,导致全屏时滚轮操作(系统自带)无法调节音量的问题
// waitForTrue(()=> $(bb['playSettingWrap']).css('display') === 'block', () => {
// $(bb['playSettingWrap']).css('display', 'none').css('visibility', 'visible');
// });
//取得视频fps
get_video_fps_ver();
//取得版本号
//get_ver();
//激活系统提示添加音量等自定义提示DOM
pick_volume_hint();
//添加自定义快捷键说明到右键菜单
//add_custom_hotkey_menu(config.hotKeyMenu);
add_custom_hotkey_menu(config.sets.keyBinding.options);
//初始化自定义设置
init_setting();
/*-----------------------------------
*事件等
*----------------------------------*/
//点击关灯
$(`#hhh_lightoff ${bb['switchInput']}:first`).click(function(){ lightoff_btn() });
//判断当前鼠标点击焦点
$(document).mouseup(function(e){
if(e.originalEvent === undefined) return;
let path = e.originalEvent.path;
curr_focus = path[0];
is_in_biliplayer = false;
//鼠标是否在播放界面内
$(path).each(function(){
if(this.id === 'bilibili-player') { is_in_biliplayer = true; return; }
})
//隐藏封面 2.x && 3.x
if(is_in_biliplayer == false || e.target.className === 'bilibili-player-dm-tip-wrap' || e.target.tagName.toLowerCase() === 'video'){
$('#hhh_img').css('display', 'none');
}
})
//扩展播放倍速范围
extend_video_speed();
//修复选择历史弹幕时弹幕填装信息丢失问题
fix_danmaku_info();
//自动运行
if(config.getCheckboxSettingStatus('autoPlay') === ON && $(bb['playSettingAutoplay'])[0].checked === false) $(bb['playSettingAutoplay']).click();//开启自动播放
if(config.getCheckboxSettingStatus('lightOff') === ON) lightoff_btn(); //自动关灯
if(config.getCheckboxSettingStatus('autoFullScreen') === ON) fullscreen(); //自动全屏
if(config.getCheckboxSettingStatus('autoWebFullScreen') === ON) web_fullscreen(); //自动网页全屏
if(config.getCheckboxSettingStatus('autoWideScreen') === ON) wide_screen(); //自动宽屏
if(config.getCheckboxSettingStatus('videoRepeat') === ON) $(bb['playSettingRepeatInput']).click(); //开启洗脑循环
if(config.getCheckboxSettingStatus('autoOpenDanmu') === ON) autoOpenDanmu(); //自动显示弹幕
//双击或中键全屏
dblclickFullScreen(config.getCheckboxSettingStatus('dblclickFullScreen'));
//非全屏滚轮音量调节
//两个参数指定屏幕范围(按百分比),第三个参数表示滚动一下增加的音量百分比,参数四表示暂停时是否调节
//let args = config.getCheckboxSettingArgs('volumeControlWhenNonFullScreen');
//wheel_volumeHint(config.getCheckboxSettingStatus('volumeControlWhenNonFullScreen'), args.screen_left,args.screen_rght,args.delta, config.getCheckboxSettingStatus('volumeControlWhenPause'));
//滚轮调节弹幕透明度(ctrl),参数表示滚动一下增加的透明度百分比,默认5
//wheel_opacity(config.getCheckboxSettingStatus('danmuOpacityControl'), 5);
//因为遮挡弹幕,去掉全屏时鼠标悬停时产生的顶端mask
removeVideoTopMask(config.getCheckboxSettingStatus('removeVideoTopMask'));
//播放关灯,暂停开灯,跳过充电鸣谢
lightOffWhenPlaying(config.getCheckboxSettingStatus('lightOffWhenPlaying'));
lightOnWhenPause(config.getCheckboxSettingStatus('lightOnWhenPause'));
jumpElectric(config.getCheckboxSettingStatus('jumpElectric'));
//记忆洗脑循环
if(config.getCheckboxSettingStatus('rememberVideoRepeat') === ON && config.getCheckboxSettingStatus('videoRepeat') !== ON) {
//if(JSON.parse(get_value('hhh-rememberVideoRepeat', $(bb['playSettingRepeatInput'])[0].checked)) === true) $(bb['playSettingRepeatInput']).click(); //localStorage只能保存字符串
if(get_value('hhh-rememberVideoRepeat', $(bb['playSettingRepeatInput'])[0].checked) === true) $(bb['playSettingRepeatInput']).click(); //localStorage只能保存字符串
$(bb['playSettingRepeatInput']).click(function() {
set_value('hhh-rememberVideoRepeat', $(bb['playSettingRepeatInput'])[0].checked);
});
};
/*-----------------------------------
*键盘控制
*----------------------------------*/
set_hotkey(config.getCheckboxSettingStatus('openHotKey'));
/*设置界面
//viewBox="10 8.5 10 12"
$('.bilibili-player-video-danmaku-setting').clone(false,false).insertBefore($('#hhh_lightoff')).attr('id', 'hhh_setting')
$('#hhh_setting>span>svg')[0].attributes[1].value = '10 8.5 10 12'
$('#hhh_setting>span>svg>path:first').remove()
*/
//段落循环
loopPlayback(config.getCheckboxSettingStatus('loopPlayback'));
//自定义倍速播放
customPlayRate(config.getCheckboxSettingStatus('customPlayRate'), config.getCheckboxSettingArgs('customPlayRate')['rate']);
//抬头显示tags(视频属于哪个区)
add_tags_to_video_title();
//TEST
bpx_test();
}
//段落循环
function loopPlayback(open){
/*
bpx-player-progress-wrap
hhh_loop_wrap
bpx-player-progress
bpx-player-progress-schedule-wrap //进度条
bpx-player-progress-schedule
bpx-player-progress-schedule-buffer
bpx-player-progress-schedule-current
bpx-player-progress-point-wrap
bpx-player-progress-thumb
bpx-player-progress-move-indicator //移动指示器
bpx-player-progress-popup //预览
bpx-player-progress-preview
bpx-player-progress-preview-image
bpx-player-progress-preview-time //进度时间框
bpx-player-progress-pull-indicator
bpx-player-progress-cursor
bpx-player-progress-scaleplate
hhh_loop_arrow_1
hhh_loop_arrow_2
hhh_loop_time_1
hhh_loop_time_2
*/
let $progress_area = $('.bpx-player-progress-area');
let $progress_wrap = $('.bpx-player-progress-wrap');
let $progress = $('.bpx-player-progress');
let $indeicator = $('.bpx-player-progress-move-indicator');
let $popup = $('.bpx-player-progress-popup');
let $down = $('.bpx-player-progress-move-indicator-down');
let $up = $('.bpx-player-progress-move-indicator-up');
let $ctrl_time_current = $('.bpx-player-ctrl-time-current');
//监听视频窗口大小变化
let ro = new ResizeObserver( entries => {
for (let entry of entries) {
//更新loop位置
resize_updata();
}
});
if(open !== ON) {
$('#hhh_loop_wrap').off('mousedown.hhh_loop_wrap');
$('#hhh_loop_wrap').off('mouseup.hhh_loop_wrap');
$(document).off('keydown.hhh_document');
$(document).off('keyup.hhh_document');
$(document).off('mouseup.hhh_document');
$('#hhh_loop_time_1, #hhh_loop_time_2').off('mouseenter.hhh_loop_time');
$('#hhh_loop_time_1, #hhh_loop_time_2').off('mousedown.hhh_loop_time');
ro.unobserve($(bb['video'])[0]);
if($('#hhh_loop_wrap').length > 0) {
loop_state_switch(0);
ctrl_play_time();
$('#hhh_loop_wrap')[0].hhh_loop_state_switch = false;
$('#hhh_loop_time_1')[0].hhh_seconds = undefined;
$('#hhh_loop_time_2')[0].hhh_seconds = undefined;
}
return false;
}
//if($('#hhh_loop_wrap').length > 0) return true;
if(bb_type.indexOf(BILI_3_X_VIDEO) === -1) return false;
//保存arrow原color
if(!$progress_area.attr('old_arrow_color')) $progress_area.attr('old_arrow_color', $down.css('border-top-color'));
let old_arrow_color = $progress_area.attr('old_arrow_color');
let new_arrow_color = '#FFA500';
let is_begin = true;
// Observe one or multiple elements
//squirtle-video-time-now 2.X bilibili-player-video-time-now 3.X
ro.unobserve($(bb['video'])[0]);
ro.observe($(bb['video'])[0]);
//css
$('#hhh_head_style').remove(); //test
if($('#hhh_head_style').length<1){
$progress_area.append(``);
}
//更新位置
function resize_updata(){
let $p1 = $('#hhh_loop_time_1');
let $p2 = $('#hhh_loop_time_2');
let $bar = $('#hhh_loop_bar');
if($p1.length !== 1 || $p2.length !== 1 && $bar.length !== 1) return;
let t1 = $p1[0].hhh_seconds;
let t2 = $p2[0].hhh_seconds;
let id1 = $p1.attr('hhh_loop_arrow_id');
let id2 = $p2.attr('hhh_loop_arrow_id');
let rect = $progress[0].getBoundingClientRect();
//let rect = $('.bilibili-player-video-progress')[0].getBoundingClientRect();
let newleft = t1/h5Player.duration*rect.width;
$p1.add($('#'+id1)).css('left', newleft);
newleft = t2/h5Player.duration*rect.width;
$p2.add($('#'+id2)).css('left', newleft);
//log($p1.css('left'),$p2.css('left'));
//log('------'+newleft);
t1 = $p1.css('left').slice(0,-2);
t2 = $p2.css('left').slice(0,-2);
let begin = Math.min(t1,t2);
let end = Math.max(t1,t2);
$bar.css({left:begin, width:end-begin});
}
function show_loop_time(sign_show){
//$popup.find('.bpx-player-progress-preview-image').hide();
}
function hide_loop_time(){
//$popup.find('.bpx-player-progress-preview-image').show();
}
//更新
function loop_update($hhh_loop_time, o){
//function PrefixZero(num, n) { return (Array(n).join(0) + num).slice(-n) }
//time = PrefixZero(Math.floor(time/60),2) + ':' + PrefixZero(time%60,2);
let left = 0,
seconds = 0,
rect = $progress[0].getBoundingClientRect();
//rect2 = $progress_wrap[0].getBoundingClientRect();
//log(`rect_width: ${rect.width} - $progress.width(): ${$progress.width()}`);
//log(`rect2_width: ${rect2.width} - $progress_wrap.width(): ${$progress_wrap.width()}`);
//get second
if(o.left !== undefined){
left = o.left - rect.x;
if(left < 0 || left > rect.width) return $hhh_loop_time[0].hhh_seconds;
//Position To Time
seconds = Math.floor(left/rect.width*h5Player.duration);
}else if(o.seconds !== undefined){
//Time To Position
left = o.seconds/h5Player.duration*rect.width;
if(left < 0 || left > rect.width) return $hhh_loop_time[0].hhh_seconds;
seconds = o.seconds;
}else{ log('参数错误',o); return;}
//updata left
$hhh_loop_time.css({left:left, display:'block'});
$("#"+$hhh_loop_time.attr('hhh_loop_arrow_id')).css({left:left, display:'block'});
//updata time
$hhh_loop_time[0].hhh_seconds = seconds;
let time = sec2str(seconds);
$hhh_loop_time.find('.hhh-bpx-player-progress-preview-time').text(time);
//updata (width + margin-left)
//log($('.bpx-player-progress-preview-time')[0].getBoundingClientRect())
let width = $hhh_loop_time.find('.hhh-bpx-player-progress-preview-time')[0].getBoundingClientRect().width;
$hhh_loop_time.find('.hhh-bpx-player-progress-preview').width(width);
$hhh_loop_time.css('margin-left', `${-width/2}px`);
//updata bar
let s1 = $('#hhh_loop_time_1')[0].hhh_seconds;
let s2 = $('#hhh_loop_time_2')[0].hhh_seconds;
if(s1!==undefined && s2!==undefined){
let t1 = $('#hhh_loop_time_1').css('left').slice(0,-2);
let t2 = $('#hhh_loop_time_2').css('left').slice(0,-2);
let begin = Math.min(t1,t2);
let end = Math.max(t1,t2);
$('#hhh_loop_bar').css({display:'block', left:`${begin}px`, width:`${end-begin}px`});
}
return seconds;
}
function ctrl_play_time(){
//time now
function set_time(e) {
//log('time-current')
if($('#hhh_loop_wrap')[0].hhh_loop_state_switch && $('#hhh_loop_wrap')[0].hhh_loop_state_switch !== 0){
let t1 = $('#hhh_loop_time_1')[0].hhh_seconds;
let t2 = $('#hhh_loop_time_2')[0].hhh_seconds;
let begin = Math.min(t1,t2);
let end = Math.max(t1,t2);
//log(t1+' - '+t2);
if(h5Player.currentTime > end){
//log(t1+' - '+t2);
h5Player.currentTime = begin;
}
}
}
let s1 = $('#hhh_loop_time_1')[0].hhh_seconds;
let s2 = $('#hhh_loop_time_2')[0].hhh_seconds;
let is_bar = $('#hhh_loop_bar').css('display') !== 'none';
//log(s1+' - '+s2+' - '+is_bar)
if(s1!==undefined && s2!==undefined && is_bar){
$ctrl_time_current[0].removeEventListener('DOMNodeInserted', set_time);
$ctrl_time_current[0].addEventListener('DOMNodeInserted', set_time);
}else{
$ctrl_time_current[0].removeEventListener('DOMNodeInserted', set_time);
}
}
//loop显示状态切换
function loop_state_switch(state){
$('#hhh_loop_wrap')[0].hhh_loop_state_switch = state;
let $p1 = $('#hhh_loop_time_1').add($('#hhh_loop_arrow_1')), $p2 = $('#hhh_loop_time_2').add($('#hhh_loop_arrow_2')), $bar = $('#hhh_loop_bar');
if(state === 0){ //no loop
$p1.hide(), $p2.hide(), $bar.hide();
}else if(state === 1){ //loop 1
if($p1[0].hhh_seconds) $p1.show();
if($p2[0].hhh_seconds) $p2.show();
if($p1[0].hhh_seconds && $p2[0].hhh_seconds) $bar.show();
}else{ //loop 2
$p1.hide(), $p2.hide();
if($p1[0].hhh_seconds && $p2[0].hhh_seconds) $bar.show();
}
}
/*---------------------------
* 插入节点
*--------------------------*/
if($('#hhh_loop_wrap').length === 0){
let progwrapclass = $progress_wrap.attr('class');
//wrap append
let $hhh_loop_wrap = $progress.wrap(`
`).parent();
//arrow append * 2
$indeicator.clone(true,true).prependTo($progress).attr('id','hhh_loop_arrow_1').hide()
.css({visibility:'visible', opacity:1})
.find('.bpx-player-progress-move-indicator-up').remove().end()
.find('.bpx-player-progress-move-indicator-down').css({'border-top-color':new_arrow_color}).end();
$('#hhh_loop_arrow_1').clone(true,true).prependTo($progress).attr('id','hhh_loop_arrow_2');
//preview-time append * 2
$popup.clone(true,true).prependTo($progress_area).attr({'id':'hhh_loop_time_1', 'hhh_loop_arrow_id':'hhh_loop_arrow_1'})
.addClass('hhh-bpx-player-progress-popup').removeClass('bpx-player-progress-popup').hide()
.find('.bpx-player-progress-preview-image').remove().end()
.find('.bpx-player-progress-hotspot').remove().end()
.find('.bpx-player-progress-preview').addClass('hhh-bpx-player-progress-preview').removeClass('bpx-player-progress-preview').end()
.find('.bpx-player-progress-preview-time').addClass('hhh-bpx-player-progress-preview-time').removeClass('bpx-player-progress-preview-time').end();
$('#hhh_loop_time_1').clone(true,true).prependTo($progress_area).attr({'id':'hhh_loop_time_2', 'hhh_loop_arrow_id':'hhh_loop_arrow_2'});
//schedule append
$('.bpx-player-control-top').find('.bpx-player-progress-schedule-buffer:first').clone(true,true).appendTo($progress).css({transform:'scaleX(0.999999)'}) //配合其他transform,否则height不同,scaleX会改变height,bug?
.css({background:'rgba(255,165,0,0.5)', display:'none'})
.attr('id','hhh_loop_bar');
}
/*---------------------------
* 事件
*--------------------------*/
//设置起点和终点
$('#hhh_loop_wrap')[0].hhh_loop_time_id = false;
$('#hhh_loop_wrap').off('mousedown.hhh_loop_wrap');
$('#hhh_loop_wrap').off('mouseup.hhh_loop_wrap');
$('#hhh_loop_wrap').on('mousedown.hhh_loop_wrap', function(e){
if(e.ctrlKey === true){
return false
}
}).on('mouseup.hhh_loop_wrap', function(e){
if(e.ctrlKey === true){
let $hhh_loop_time = is_begin? $('#hhh_loop_time_1'): $('#hhh_loop_time_2');
is_begin = !is_begin;
loop_update($hhh_loop_time, {left:e.pageX});
//$('.bilibili-player-video-toast-wrp').css('z-index', 0);
this.hhh_loop_time_id = $hhh_loop_time[0].id;
loop_state_switch(1);
ctrl_play_time();
return false;
}else{
this.hhh_loop_time_id = false;
}
});
//键盘 down
$(document).off('keydown.hhh_document');
$(document).on('keydown.hhh_document',function(e){
if(e.keyCode === keycode['Ctrl']) { //Ctrl
if($progress_wrap.hasClass('bpx-state-active') === true){ //隐藏(img + up)
$down.css('border-top-color', new_arrow_color);
$up.hide();
show_loop_time();
}
$('#hhh_loop_time_1, #hhh_loop_time_2').css({cursor: 'pointer'}) //代表可以点击time标签
}else if(e.keyCode === keycode['left'] || e.keyCode === keycode['right']){ //键盘调整开始结束时间
if($('#hhh_loop_wrap')[0].hhh_loop_time_id !== false && $('#hhh_loop_time_1').css('display') !== 'none'){
toggle_control_top('show');
let $hhh_loop_time = $('#'+$('#hhh_loop_wrap')[0].hhh_loop_time_id);
let seconds = $hhh_loop_time[0].hhh_seconds;
e.keyCode === keycode['right'] ? ++seconds : --seconds;
loop_update($hhh_loop_time, {seconds:seconds});
return false;
}
}else if(e.keyCode === 'L'.charCodeAt()){ //切换
if($('#hhh_loop_time_1')[0].hhh_seconds !== undefined){
toggle_control_top('show');
$('#hhh_loop_wrap')[0].hhh_loop_state_switch = ++$('#hhh_loop_wrap')[0].hhh_loop_state_switch % 3;
loop_state_switch($('#hhh_loop_wrap')[0].hhh_loop_state_switch);
ctrl_play_time();
}
}
});
//键盘 up
$(document).off('keyup.hhh_document');
$(document).on('keyup.hhh_document',function(e){
if(e.keyCode === 17) { //Ctrl
$down.css('border-top-color', old_arrow_color);
$up.show();
hide_loop_time();
$('#hhh_loop_time_1, #hhh_loop_time_2').css({cursor: 'w-resize'})
} else if(e.keyCode === keycode['left'] || e.keyCode === keycode['right']){ //段落循环
if($('#hhh_loop_wrap')[0].hhh_loop_time_id !== false){
//hide_loop_time();
return false;
}
}
});
//判断当前鼠标点击焦点
$(document).off('mouseup.hhh_document');
$(document).on('mouseup.hhh_document', function(e){
if(!e.ctrlKey && $('#hhh_loop_wrap').length > 0 && $('#hhh_loop_wrap')[0].hhh_loop_time_id) $('#hhh_loop_wrap')[0].hhh_loop_time_id = false;
});
//拖动确定范围
$('#hhh_loop_time_1, #hhh_loop_time_2').off('mouseenter.hhh_loop_time');
$('#hhh_loop_time_1, #hhh_loop_time_2').off('mousedown.hhh_loop_time');
$('#hhh_loop_time_1, #hhh_loop_time_2').on('mouseenter.hhh_loop_time', function(e){
$(this).attr('in_dom', true);
}).on('mouseleave.hhh_loop_time', function(e){
$(this).attr('in_dom', false);
}).on('mousedown.hhh_loop_time', function(e){
var $this = $(this);
var doc = document;
$this.css('z-index', 10000); //当前的在上面
if(e.ctrlKey){
loop_state_switch(0);
ctrl_play_time();
}else{
loop_update($this, {left:e.clientX});
doc.onmousemove = function(e){
//log(e.clientX)
loop_update($this, {left:e.clientX});
return false;
};
doc.onmouseup = function(e){
//清除事件
doc.onmousemove = null;
doc.onmouseup = null;
//hide_loop_time();
//$this.find('.bilibili-player-video-progress-detail-container').show();
$this.css('z-index', 'auto');
$('#hhh_loop_wrap')[0].hhh_loop_time_id = $this[0].id;
return false;
}
}
});
}
//增加当前在线视频预览
function run_online_preview(open=ON){
if(open !== ON) return false;
if($('#hhh_online_list_style').length === 1) return true;
function hide(parent, selector, show_or_hide){
var o = $();
if($.isArray(selector) === true){
$.each(selector, function(i,v){
o = o.add(v);
})
}else{
o = $(selector);
}
//显示及渐隐效果(抄bilibili^^)
clearTimeout(parent.showHintTimer),
o.stop().show(),
parent.showHintTimer = window.setTimeout((function() {
o.animate({
opacity: 0
}, 600, (function() {
$(this).hide()
}))
}
), 0)
}
function show(parent, selector, show_or_hide){
var o = $();
if($.isArray(selector) === true){
$.each(selector, function(i,v){
o = o.add(v);
})
}else{
o = $(selector);
}
//显示及渐隐效果(抄bilibili^^)
clearTimeout(parent.showHintTimer),
parent.showHintTimer = window.setTimeout((function() {
o.stop().show(),
o.animate({
opacity: 1
}, 600, (function() {
$(this).show()
}))
}
), 300)
}
if($('#hhh_online_list_style').length<1){
$('.online-list').append(``);
}
var bvs = {},
box_width = 0,
bg_img_row = 0,
bg_y_block_len = 0,
bg_img_totle = 0;
$('.online-list>.ebox>a>div').mouseenter(function(e){
this.state = 'enter';
let $lazy_img = $(this);
let bvid = $lazy_img.parent().attr('href').match(/BV\w+$/);
bvid = bvid && bvid[0];
this.bvid = bvid;
if(bvs[bvid] === undefined){
bvs[bvid] = $lazy_img.parent().attr('title');
$.getJSON("https://api.bilibili.com/x/player/videoshot", { bvid: bvid, index: "1" },
function(json){
let bg_img = json.data.image[0];
box_width = $lazy_img.width();
bg_img_totle = json.data.index.length > (json.data.img_x_len*json.data.img_x_len)? (json.data.img_x_len*json.data.img_x_len): json.data.index.length;
bg_img_row = bg_img_totle < json.data.img_x_len? bg_img_totle: json.data.img_x_len;
bg_y_block_len = json.data.img_y_size/json.data.img_x_size*box_width;
bvs[bvid] = {box_width:box_width, bg_img_totle:bg_img_totle, bg_img_row:bg_img_row, bg_y_block_len:bg_y_block_len};
//log(bg_img_row+' - '+bg_img_totle+' - '+bg_y_block_len);
//log(bvs[bvid]);
$lazy_img.css({'overflow':'hidden', 'position':'relative'});
$lazy_img.append(`
`); /*硬编码,随时调整*/
if($lazy_img[0].state === 'enter') show($lazy_img[0], [$lazy_img.find('.hhh-preview-bg'), $lazy_img.find('.hhh-preview-wrapper')], 'show');
});
}else{
show($lazy_img[0], [$lazy_img.find('.hhh-preview-bg'), $lazy_img.find('.hhh-preview-wrapper')], 'show');
}
}).mouseleave(function(){
this.state = 'leave';
hide(this, [$(this).find('.hhh-preview-bg'), $(this).find('.hhh-preview-wrapper')], 'hide');
}).mousemove(function(e){
//log(this.bvid);
let obv = bvs[this.bvid];
let amounts = Math.floor(e.offsetX/(obv.box_width/obv.bg_img_totle));
let x = Math.floor(amounts % obv.bg_img_row) * -obv.box_width;
x = Math.min(Math.max(x,-obv.box_width*(obv.bg_img_totle-1)),0);
let y = Math.floor(amounts/obv.bg_img_row) * -obv.bg_y_block_len;
//log('---'+box_width+' - '+bg_img_totle);
//log(e.offsetX+' - '+amounts+' - '+x+' - '+y+' - '+bg_y_block_len+' - '+Math.floor(amounts/bg_img_row));
$(this).find('.hhh-preview-bg').css({'background-position':`${x}px ${y}px`});
let w = Math.round(e.offsetX/obv.box_width*100);
$(this).find('.hhh-preview-progress-bar').css({'width':`${w}%`});
})
}
//动态首页直接显示隐藏content
function run_content(open=ON){
if(open !== ON){
return false;
//Test
if($('[hhh_has_content]').length){
let $major = $('.bili-dyn-content__orig__major');
let $content = $major.find('.bili-dyn-card-video__desc');
let $expand = $major.find('.bili-dyn-card-video_expand___hhh');
$content.removeClass('bili-dyn-card-video__desc___new_expand')
.removeClass('bili-dyn-card-video__desc___new_collapse');
$expand.add($content).off('click.hhh_content');
$expand.remove('.bili-dyn-card-video_expand___hhh');
$major.find('.bili-dyn-card-video').removeClass('bili-dyn-card-video___new');
$major.find('.bili-dyn-card-video__header').removeClass('bili-dyn-card-video__header___new');
$major.find('.bili-dyn-card-video__body').removeClass('bili-dyn-card-video__body___new');
$('[hhh_has_content]').removeAttr('hhh_has_content');
}
return false;
}
if($('[hhh_has_content]').length < $('.bili-dyn-content__orig__major').length){
$('.bili-dyn-content__orig__major').each(function(){
let $major = $(this);
let $hhh_has_content = $major.find('[hhh_has_content]');
if($hhh_has_content.length >= 1) return true;
//$major.attr('hhh_has_content', true);
log($hhh_has_content.length)
//显示隐藏标题
let $title = $major.find('.bili-dyn-card-video__title');
let padding_bottom = '24px'; //根据标题行数确定 .bili-dyn-card-video__stat 位置
if($title.length >= 1){
let font_size = $title.css('font-size');
let line_height = +font_size.match(/\d+/)[0] + 5; //估算
let h = $title.removeClass('bili-dyn-card-video__title').css({'font-size':font_size}).height();
$title[0].style = "";
//log($title.text()+': '+line_height+' - '+h)
$title.addClass('bili-dyn-card-video__title');
if(h > line_height*2){
$title.attr('title', $title.text())
}
if(h > line_height){
padding_bottom = '10px';
}
}
//显示隐藏content
let $content = $major.find('.bili-dyn-card-video__desc');
if($content.length >= 1){
//console.log($content.text().slice(0,10)+ ' : ' +$content.height());
let line_height = $content.css('line-height');
//log($content.height());
let font_size = $content.css('font-size');
let h = $content.removeClass('bili-dyn-card-video__desc').css({'line-height':line_height, 'font-size':font_size}).height();
$content[0].style = "";
line_height = line_height.match(/\d+/)[0];
console.log('---line_h:'+line_height+' h: '+h+' title: '+$major.find('.title').text());
$content.addClass('bili-dyn-card-video__desc');
$content.attr('hhh_has_content', true);
if(h > line_height*2){
// $major.find('.bili-dyn-card-video').height('auto');
// $major.find('.bili-dyn-card-video__body').css('display', 'block');
// $major.find('.bili-dyn-card-video__header').height(127);
if($('#hhh_content_style').length<1){
$major.append(``);
}
$major.find('.bili-dyn-card-video').addClass('bili-dyn-card-video___new');
$major.find('.bili-dyn-card-video__header').addClass('bili-dyn-card-video__header___new');
$major.find('.bili-dyn-card-video__body').addClass('bili-dyn-card-video__body___new');
$content.addClass('bili-dyn-card-video__desc___new_collapse');
// $content.css({'padding-top':'8px'});
// console.log(line_height);
// $content.css({'height': `${line_height}px`});
//let $expand = $(`
展开
`).insertAfter($content);
let $expand = $(`
展开
`).insertAfter($content);
$expand.add($content).off('click.hhh_content');
$expand.add($content).on('click.hhh_content', function(){
//$expand.add($content).click(function(){
if($expand.text() === '展开'){
//console.log('=='+$content.height()+'==='+$content.css('line-height').match(/\d+/)[0]);
//$content.css({height:'auto', '-webkit-box-orient':'inline-axis'});
$content.removeClass('bili-dyn-card-video__desc___new_collapse').addClass('bili-dyn-card-video__desc___new_expand');
$expand.css({'padding-bottom': '0px'});
$expand.text('收起');
}else{
//$content.height(line_height);
//$content.css({'-webkit-box-orient':'vertical'});
$content.removeClass('bili-dyn-card-video__desc___new_expand').addClass('bili-dyn-card-video__desc___new_collapse');
$expand.css({'padding-bottom': $expand.attr('padding-bottom')});
$expand.text('展开');
}
return false
});
}
}
})
}
}
//添加首页轮播 prev next slide (抄网易)
function run_add_carousel_slide(){
waitForTrue(()=> $('.rcmd-box-wrap').length === 1, () => {
if($('.focus-carousel_hhh').length > 0) return false;
let style = ``;
let $carousel = $('.focus-carousel');
$carousel.append(style);
$carousel.addClass('focus-carousel_hhh');
let $prev = $(`
`).appendTo($carousel);
let $next = $(`
`).appendTo($carousel);
//轮播效果
$prev.on('click', function(){
if($carousel.find('.trigger span.on').index() === $carousel.find('.trigger span:first').index())
$carousel.find('.trigger span:last').click();
else
$carousel.find('.trigger span.on').prev().click();
});
$next.on('click', function(){
if($carousel.find('.trigger span.on').index() === $carousel.find('.trigger span:last').index())
$carousel.find('.trigger span:first').click();
else
$carousel.find('.trigger span.on').next().click();
});
});
}
//新版首页添加观看列表
function run_add_online(){
let $box = $('.recommend-container__2-line');
if($box.length !== 1) return;
let $last_card = $box.children('.bili-video-card:last');
let left = $last_card.position().left;
let width = $last_card.outerWidth();
let $online_wrap = $('.bili-grid.short-margin.grid-anchor:last');
$online_wrap.append(`
`);
$('#hhh_online').append($('#hhh_btn_num>button').clone().empty().css({width:`${width}px`, 'border-radius':'4px', background:'#f4f4f4', display:'flex', border:'1px solid #e7e7e7'})
.append(`
观看列表`));
$('#hhh_online a').hover(function(){$(this).css('color','#00a1d6')}, function(){$(this).css('color','#212121')});
}
//记忆首页推荐列表
function run_save_recommend_list(open=ON){
if(open !== ON) return false;
if($('#hhh_btn_num').length !== 0) return true;
if ($('.rcmd-box-wrap').length === 1) save_recommend_list_2X_V2();
else if($('.bili-grid.short-margin.grid-anchor:first').length === 1) save_recommend_list_2X_V3();
//else err('记忆首页推荐列表错误 - 找不到dom');
}
function save_recommend_list_2X_V2(){
let $box_wrap = $('.rcmd-box-wrap');
let $box = $('.rcmd-box');
let box_data = [$box.clone()];
let $cbtn = $('.change-btn');
let h = $cbtn.outerHeight();
let w = $cbtn.outerWidth();
let is_change_break = null;
let curr_box_num = 0;
//list-box left
$('#elevator').css({left:`calc(50% + ${w+3+20}px)`}); //calc(50% + 3px);
let $empty_cbtn = $cbtn.clone().empty();
//num
$box_wrap.append($empty_cbtn.clone().attr('id','hhh_btn_num')
.css({height:'21px', 'line-height':'21px', top:`${h+2}px`})
.css({cursor:'default'})
.css({padding:'0px', background:'#e2e2e2'}).append('1/1'));
//left
let cbtn_h = $('#hhh_btn_num').outerHeight() + 3;
$box_wrap.append($empty_cbtn.clone().attr('id','hhh_btn_zuo').css({height:'auto', top:`${h+1+cbtn_h}px`})
.css({'border-bottom':'0px', 'border-bottom-left-radius':'0px', 'border-bottom-right-radius':'0px'})
.append('
'));
//right
cbtn_h += $('#hhh_btn_zuo').outerHeight() - 1;
$box_wrap.append($empty_cbtn.clone().attr('id','hhh_btn_you').css({height:'auto', top:`${h+1+cbtn_h}px`})
.css({'border-top':'0px', 'border-top-left-radius':'0px', 'border-top-right-radius':'0px'})
.append('
'));
function cbtn_event($cbtn){
$cbtn.click(function(){
//激活动画
let $i = $(this).find('i');
$i.addClass('active');
setTimeout(function(){ $i.removeClass('active') },500);
//恢复前一个list
curr_box_num = this.id === 'hhh_btn_zuo'? Math.max(curr_box_num-1, 0): Math.min(curr_box_num+1, box_data.length-1);
$('#hhh_btn_num').text(`${curr_box_num+1}/${box_data.length}`);
$box.find('.video-card-reco').each(function(i){
$(this).empty().append($(box_data[curr_box_num]).find('.video-card-reco:eq('+i+')>div').clone());
})
})
}
cbtn_event($('#hhh_btn_zuo')); //left
cbtn_event($('#hhh_btn_you')); //right
//refresh
$cbtn.click(()=>{
$box_wrap[0].addEventListener('DOMSubtreeModified', function fn_(e) {
let eve_this = this;
if(typeof e.target.className === 'string' && e.target.className === $box.attr('class')){
clearTimeout(is_change_break);
is_change_break = setTimeout(function() {
//log("推荐页面刷新完毕");
eve_this.removeEventListener('DOMSubtreeModified', fn_);
//eve_this.removeEventListener('DOMSubtreeModified', arguments.callee);
box_data.push($box.clone());
curr_box_num = box_data.length - 1;
$('#hhh_btn_num').text(`${box_data.length}/${box_data.length}`);
if(box_data.length >= 10){ $('#hhh_btn_num').css({width:'37px', right:'-41px'}) }
//log(rcmd_box_data.length)
}, 50);
}
})
});
}
function save_recommend_list_2X_V3(){
let $box_wrap = $('.bili-grid.short-margin.grid-anchor:first');
let $box = $('.recommend-container__2-line');
let box_data = [$box.clone()];
let $rbtn = $('.roll-btn-wrap');
let $empty_rbtn = $rbtn.clone().empty();
let h = $rbtn.outerHeight();
let w = $rbtn.outerWidth();
let $left = $('.buttons.not-gray').find('button:first');
let $right = $('.buttons.not-gray').find('button:last');
let is_change_break = null;
let curr_box_num = 0;
//palette-button left
waitForTrue(()=> $('.palette-button-wrap').length === 1, () => {
$('.palette-button-wrap').css({left:`calc(100% + ${w+10}px)`}); //calc(100% + 0px);
});
//num
$box_wrap.append($rbtn.clone().attr('id','hhh_btn_num').css({top:`${h+2}px`})
.find('svg').remove().end()
.find('span').remove().end()
.find('button').css({cursor:'default', background:'#e2e2e2', 'align-items':'center', 'border-radius':'8px'}).removeClass('primary-btn').append('1/1').end());
//left
let cbtn_h = $('#hhh_btn_num').outerHeight() + 3;
$box_wrap.append($empty_rbtn.clone().attr('id','hhh_btn_zuo').css({top:`${h+1+cbtn_h}px`}).append($left)
.find('button').addClass('primary-btn roll-btn').css({'border-bottom':'0px', 'border-bottom-left-radius':'0px', 'border-bottom-right-radius':'0px'}).end()
.find('svg').css({'margin-bottom':'1px'}).end());
//right
cbtn_h += $('#hhh_btn_zuo').outerHeight() - 1;
$box_wrap.append($empty_rbtn.clone().attr('id','hhh_btn_you').css({top:`${h+1+cbtn_h}px`}).append($right)
.find('button').addClass('primary-btn roll-btn').css({'border-top':'0px', 'border-top-left-radius':'0px', 'border-top-right-radius':'0px'}).end()
.find('svg').css({'margin-bottom':'1px'}).end());
//left right - event
function rbtn_event($rbtn){
$rbtn.click(function(){
//恢复前一个list
curr_box_num = this.id === 'hhh_btn_zuo'? Math.max(curr_box_num-1, 0): Math.min(curr_box_num+1, box_data.length-1);
$('#hhh_btn_num>button').text(`${curr_box_num+1}/${box_data.length}`);
$box.children('.bili-video-card').each(function(i){
//log($(box_data[curr_box_num]).children(`.bili-video-card:eq(${i})`).attr('data-report'));
$(this).empty().append($(box_data[curr_box_num]).children(`.bili-video-card:eq(${i})`).clone());
})
})
}
rbtn_event($('#hhh_btn_zuo')); //left
rbtn_event($('#hhh_btn_you')); //right
//refresh - event
$rbtn.click(()=>{
$box_wrap[0].addEventListener('DOMSubtreeModified', function fn_(e) {
let eve_this = this;
if(typeof e.target.className === 'string' && e.target.className === 'bili-video-card__image--wrap'){
clearTimeout(is_change_break);
is_change_break = setTimeout(function() {
//log("推荐页面刷新完毕");
eve_this.removeEventListener('DOMSubtreeModified', fn_);
//eve_this.removeEventListener('DOMSubtreeModified', arguments.callee);
box_data.push($box.clone());
curr_box_num = box_data.length - 1;
$('#hhh_btn_num>button').text(`${box_data.length}/${box_data.length}`);
//log(box_data.length)
}, 50);
}
})
});
}
//订阅合集列表展开
function expand_list(open=ON, columns=15){
if(open !== ON) return false;
if ($('.first-line-right').length !== 1) { /*log('不是订阅合集');*/ return false }
//第一次执行
let old_height = '152px';
let old_max_height = '152px';
if($('#hhh_expand_list').length !== 1) {
$('
').appendTo($('.first-line-right').parent()).append($('.first-line-right'));
$('.first-line-right').clone().appendTo($('.first-line-right').parent())
.attr('id', 'hhh_expand_list')
.css({'margin-top': '5px'})
.find('.txt').text('展开列表');
old_height = $('.video-sections-content-list').css('height');
old_max_height = $('.video-sections-content-list').css('max-height');
}
//点击列表展开
let $vcard = $('.video-episode-card:last');
let vcard_height = $vcard.outerHeight() + parseInt($vcard.css('margin-top')) + parseInt($vcard.css('margin-bottom'));
let $switch_button = $('#hhh_expand_list .switch-button');
if($switch_button.hasClass('on') === true) $switch_button.toggleClass('on'); //初始不展开状况
$('#hhh_expand_list .next-button').off('click.hhh_expand_list');
$('#hhh_expand_list .next-button').on('click.hhh_expand_list', function(){
$switch_button.toggleClass('on');
if($switch_button.hasClass('on') === true){
let expand_height = 0; $('.video-sections-item').each(function(){ expand_height += $(this).height() }); //当前展开高度
let limit_height = vcard_height * columns; //限高
expand_height = expand_height > limit_height ? limit_height : 'auto';
$('.video-sections-content-list').css({'height': expand_height, 'max-height': 'none'}); //展开columns个的高度
} else {
$('.video-sections-content-list').css({'height': old_height, 'max-height': old_max_height});
}
});
$('#hhh_expand_list .next-button').click(); //默认展开
}
//全屏时显示投币、收藏对话框
function set_dialog(type) {
if(type === 'coin'){ //投币对话框
if($(bb['coinDlgCoin']).length === 1){
//log('--set_dialog 1--');
// TODO: 全屏时显示
// $('.bili-dialog-m').appendTo('.bpx-player-container');
// $('.bili-dialog-m').find('.coin-bottom').css('line-height', 1.5);
//网页全屏时显示
let z_index = +$('#bilibili-player').css('z-index');
!isNaN(z_index) && $(bb['biliDlgM']).css('z-index', z_index+1);
!isNaN(z_index) && $('.bili-msg').css('z-index', z_index+1); //硬币不足 提示
//键盘事件
$(document).off('keydown.hhh_coin');
$(document).on('keydown.hhh_coin', function(e){
if(e.keyCode === keycode['left']){
$('.left-con').click();
}else if(e.keyCode === keycode['right']){
$('.right-con').click();
}else if(e.keyCode === keycode['Enter']){
let c_num = $('.mc-box.on').text();
$(bb['coinDlgOkBtn']).click();
//XXX:
bb_type === BILI_3_X_VIDEO &&is_fullscreen() && showHint(document, '#hhh_wordsHint', `投币成功 ${$('.coin').text().trim()} +${c_num}`, 1.5e3);
}else if(e.keyCode === keycode['Esc']){
$(bb['coinDlgCloseBtn']).click();
}
return false;
})
}else{
//log('--set_dialog 2--');
$(document).off('keydown.hhh_coin');
if($(bb['coin']).filter('[title="对本稿件的投币枚数已用完"]').length > 0 && $('.van-message').length > 0){
is_fullscreen() && showHint(document, '#hhh_wordsHint', '对本稿件的投币枚数已用完');
}
}
}else if(type === 'collection'){
if($('.collection-m').length === 1){
let z_index = +$('#bilibili-player').css('z-index');
!isNaN(z_index) && $(bb['biliDlgM']).css('z-index', z_index+1);
}
}
}
//添加到收藏夹关键字过滤
function collection_filter(open=ON){
if(open !== ON){
$('.collection-m .title')[0].style['padding-left'] = '';
$('#hhh_collection_input').off('input.hhh_collection');
$('#hhh_collection_input').parent().remove();
return false;
}
let collection_div = `
`;
if($('#hhh_collection_input').length === 0){
$(collection_div).prependTo($('.collection-m .title').css('padding-left', '150px'));
$('#hhh_collection_input').on('input.hhh_collection',function(){
let val = $(this).val();
$('.content li').each(function(i){
if(!val) {
$(this).css('display','block');
return;
}
if($(this).find('.fav-title').text().toUpperCase().indexOf(val.toUpperCase()) !== -1) {
$(this).css('display','block');
}else{
$(this).css('display','none');
}
})
})
}
}
//新窗口打开自动连播列表视频
function run_rec_list_newtab(open){
$('.rec-list .video-page-card').each(function(e){
if(open === ON){
let $a = $(this).find('.info a:first').attr('target',"_blank");
let $span = $(this).find('.info span');
$span.clone().prependTo($a).attr('hhh_new', true);
$span.hide();
}else{
let $a = $(this).find('.info a:first').attr('target',"");
$(this).find('.info span[hhh_new]').remove();
$(this).find('.info span').show();
}
})
}
//调整收藏夹长度
function run_fav(open){
log(open)
if(open === ON){
let max_height = parseInt($('#fav-createdList-container').css('max-height'));
$('#fav-createdList-container').css('max-height', `${max_height*2}px`);
}else{
//let max_height = parseInt($('#fav-createdList-container').css('max-height'));
//$('#fav-createdList-container').css('max-height', `${max_height/2}px`);
}
}
//未使用
function run_history(){
$.get("https://api.bilibili.com/x/web-goblin/history/search", { pn:"1", keyword: "12", business: "all" },
function(json){
console.log(json)
});
}
// let $r_con = $('.r-con')
// let progress_card_width = $('.video-episode-card__info-title:eq(57)').outerWidth()
// let div = ``
// function append_css($container, id, csshtml){
// $(`#${id}`).remove();
// if($(`#${id}`).length<1){
// $container.append($(csshtml).attr('id', id));
// }
// }
// append_css($r_con, 'hhh_style_progress_card',
// `
//
// `
// )
//12-08 12:13观看 | 看到 45p 14:42
//video.addEventListener('timeupdate',function(e){console.log(e)})
//log($('.cur-page').text())
// video.addEventListener('timeupdate',function(e){
// let obj = {}
// obj.last_part = $('.cur-page').text().match(/(\d+)\/\d+/)?.[1]+'p'
// obj.currentTime = this.currentTime
// let date = new Date()
// obj.watch_date = date.Format("MM-dd");
// obj.watch_time = date.Format("hh:mm");
// console.log(obj)
// })
//
function memory_multipart_progress($wrap){
const id = 'hhh_memory_multipart_progress'
if($(`#${id}`).length <= 0){
let text = ''
$(`${text}
`).appendTo($wrap)
const timeupdate_ = function(e){
let fn = timeupdate_
if(fn.time === undefined) {
fn.time = Date.now()
fn.interval = 0
}
fn.interval += Date.now() - fn.time
fn.time = Date.now()
if(fn.interval === 0 || fn.interval > fn.limit){
//console.log(fn.interval, fn.limit)
// let watch_date = '12-08'
// let watch_time = '12:13'
// let last_part = '45p'
// let last_part_time = '14:42'
// last_part_time = h5Player.currentTime
// let text = `${watch_date} ${watch_time}观看 | 看到${last_part} ${last_part_time}`
//$multipart_progress.text(`${text}`)
const bv = $('meta[itemprop=url]').attr('content').match(/BV\w+/)?.[0]
const date = new Date()
let obj = {
last_part: $('.cur-page').text().match(/(\d+)\/\d+/)?.[1]+'p',
currentTime: h5Player.currentTime,
watch_date: date.Format("MM-dd"),
watch_time: date.Format("hh:mm"),
}
//log(bv)
//log(obj)
//log('--------')
// log(JSON.stringify(obj))
// log('========')
set_value(bv, obj)
log((bv))
// log('********')
// set_value(bv, 1)
fn.interval = 0
}
}
timeupdate_.limit = 1000 //ms
h5Player.addEventListener('timeupdate', timeupdate_)
}
const $multipart_progress = $(`#${id}`)
const bv = $('meta[itemprop=url]').attr('content').match(/BV\w+/)?.[0]
const obj = get_value(bv)
log(obj)
log($('.cur-page').text())
if(!!obj){
let text = `${obj.watch_date} ${obj.watch_time}观看 | 看到${obj.last_part} ${sec2str(obj.currentTime)}`
$multipart_progress.text(`${text}`)
}else{
const date = new Date()
let obj = {
last_part: $('.cur-page').text().match(/(\d+)\/\d+/)?.[1]+'p',
currentTime: h5Player.currentTime,
watch_date: date.Format("MM-dd"),
watch_time: date.Format("hh:mm"),
}
}
set_value(bv, obj)
}
//给列表添加总时长
function add_to_video_sections_head(){
//统计list秒数
function get_list_second($items){
let second = 0
$items.each(function(){
let d1 = $(this).text().trim().split(/:/).reverse()
for(let i=0; i 0){
const id = 'hhh_mysectionns_head'
if($(`#${id}`).length <= 0){
$left.wrap(``).parent()
}
add_total_time($(`#${id}`), get_list_second($items))
//memory_multipart_progress($(`#${id}`))
}
}
function add_total_time($wrap, second){
const id = 'hhh_total_time'
if($(`#${id}`).length <= 0){
$(`
`).appendTo($wrap)
}
$(`#${id}`).text(`总时长: ${sec2str(second)}`)
}
function add_total_time2(){
//统计list秒数
function get_list_second($items){
let tt = 0
$items.each(function(){
let d1 = $(this).text().trim().split(/:/).reverse()
for(let i=0; i
0){
let tt = get_list_second($items)
if($('#hhh_total_time').length <= 0){
let $wrap = $left.wrap('').parent()
$(`
总时长: ${sec2str(tt)}
`).appendTo($wrap)
let watch_date = '12-08'
let watch_time = '12:13'
let last_part = '45p'
let last_part_time = '14:42'
let curr_part_text = `${watch_date} ${watch_time}观看 | 看到${last_part} ${last_part_time}`
$(`
${curr_part_text}
`).appendTo($wrap)
}else{
$('#hhh_total_time').text(`总时长: ${sec2str(tt)}`)
}
}
}
//https://api.bilibili.com/x/web-interface/archive/relation?aid=896486345&bvid=BV1CA4y1S7fS //得到投币数量
//初始化
function init() {
// var box = document.getElementById("hhh");
// //配置选项
// var config = { childList: true, subtree: true };
// var observer = new MutationObserver(function (mutationsList, observer) {
// for (var mutation of mutationsList) {
// const target = mutation.target;
// //typeof target.className === 'string' && target.className !== '' && log(target.className);
// if (mutation.type == 'childList') {
// //console.log('子元素被修改');
// }
// else if (mutation.type == 'attributes') {
// //console.log(mutation.attributeName + '属性被修改');
// }
// }
// });
// //开始观测
// observer.observe(document.body, config);
//console.clear();
//保存设置信息 && 快捷键信息
config.getCheckboxSetting();
// var a = {
// 'name': '大象笔记'
// };
// GM_setValue('zw_test', a);
// console.log(GM_getValue('zw_test'));
// console.log(GM_getValue('zw_test').name);
let is_card_load = true;
let is_content_load = null;
let is_rec_list_load = null;
let is_homepage_load = true;
let is_fav_list_load = true;
let is_history_break = null;
let is_run_3X_break = true;
let run_load = true;
let run_done = false;
let dm_t;
new MutationObserver((mutations, observer) => {
mutations.forEach(mutation => {
function get_ver_3x_(){
let ver = null;
let a = 0;
setTimeout(()=>a=1, 1000);
let r = waitForTrue(()=> $('.bpx-player-loading-panel-text').length>0 && a===1, ()=>{
ver = $('.bpx-player-loading-panel-text').text().match(/(\d+).(\d+).(\d+)-(\w+)/);
return true;
});
//log(r);
return ver;
}
function get_ver_3x(){
let ver_reg = $('.bpx-player-loading-panel-text').length > 0? $('.bpx-player-loading-panel-text').text().match(/(\d+).(\d+).(\d+)-(\w+)/): null;
let ver;
if(ver_reg === null) ver = null;
else if(ver_reg[1] === '3' && ver_reg[2] === '13') ver = BILI_3_X_VIDEO;
else ver = BILI_3_X_MOVIE;
return ver_reg;
}
function get_ver_(){
let ver_reg = $('.bpx-player-loading-panel-text').length > 0? $('.bpx-player-loading-panel-text').text().match(/(\d+).(\d+).(\d+)-(\w+)/): null;
let ver;
if(ver_reg === null) ver = null;
else if(ver_reg[1] === '3' && ver_reg[2] === '13') ver = BILI_3_X_VIDEO;
else ver = BILI_3_X_MOVIE;
return ver;
}
const target = mutation.target;
//typeof target.className === 'string' && target.className !== '' && log(target.className);
//typeof target.className === 'string' && target.className !== '' && log($('.rec-list .video-page-card').length);
//typeof target.className === 'string' && target.className.match(/switch/) && log(target.className);
//log(window.location.href)
const stage = mutation.previousSibling && target.getAttribute('stage');
if(stage === '1' && $('.bilibili-player-video-wrap').length === 1){ //2.X
if($('#app').hasClass('app-v1')){
log("2.X“V3版”加载完毕");
bb_config.set_bb(BILI_3_X_VIDEO_V1);
run();
}else{
log("2.X“V2版”加载完毕");
bb_config.set_bb(BILI_2_X_V2);
run();
}
} else if(1&&typeof target.className === 'string' && (target.className === 'bui-select-list-wrap#####' || target.className === 'rec-list####') ) {
//bug?? bpx-player-control-top 会激活重新加载视频
clearTimeout(is_rec_list_load)
is_rec_list_load = setTimeout(function() {
log('订阅合集列表加载完毕'); expand_list(config.getCheckboxSettingStatus('expandList'), config.getCheckboxSettingArgs('expandList', 'columns'));
log("连播列表加载"); run_rec_list_newtab(config.getCheckboxSettingStatus('openVideoInNewTab'));
//列表加入总时长
add_total_time()
}, 200);
} else if(1&&typeof target.className === 'string' && (target.className === 'bpx-player-control-top###' || target.className === 'rec-list###')) {
} else if(1&&typeof target.className === 'string' && (target.className === 'v-wrap' || target.className.includes('header-v2 win webscreen-fix') === true
|| target.className.includes('main-container') === true)) {
log("投币快捷设置或添加到收藏夹关键字过滤");
collection_filter(config.getCheckboxSettingStatus('collectionFilter'));
set_dialog('coin');
set_dialog('collection');
//} else if(!bb_type && typeof target.className === 'string' && target.className === 'bpx-player-loading-panel-text') { //3.X pbp-tip bpx-player-loading-panel-text
} else if(run_load === true && typeof target.className === 'string' && (target.className === 'bui-select-list-wrap' || target.className === 'rec-list')) { //3.X pbp-tip bpx-player-loading-panel-text
function get_ver_____(){
let ver_reg = $('.bpx-player-loading-panel-text').length > 0? $('.bpx-player-loading-panel-text').text().match(/(\d+).(\d+).(\d+)-(\w+)/): null;
let ver;
if(ver_reg === null) { ver = null; ver_reg = []}
else if($('#app').find('.l-con').length > 0) ver = BILI_3_X_VIDEO;
else if($('#app').find('.plp-l').length > 0) ver = BILI_3_X_MOVIE; //todo plp-l
else if($('#app.app-v1').length > 0) ver = BILI_3_X_VIDEO_V1; //todo plp-l
else ver = BILI_2_X;
//log(ver_reg[0]+' | '+ver)
//log($('#app').find('.l-con').length+' | '+$('#app').find('.plp-l').length)
return [ver, ver_reg[0]];
}
function get_ver(){
let ver_reg = $('.bpx-player-loading-panel-text').length > 0? $('.bpx-player-loading-panel-text').text().match(/(\d+).(\d+).(\d+)-(\w+)/): null
//log(ver_reg)
ver_reg ??= $('.bpx-player-info-log .info-title').text().match(/[\d.]+/)
//log(ver_reg)
let ver
if(ver_reg === null) { ver = null; ver_reg = [] }
if($('#app').find('.l-con').length > 0) ver = BILI_3_X_VIDEO;
else if($('#app').find('.plp-l').length > 0) ver = BILI_3_X_MOVIE; //todo plp-l
else if($('#app.app-v1').length > 0) ver = BILI_3_X_VIDEO_V1; //todo plp-l
else ver = BILI_2_X;
//log(ver_reg[0]+' | '+ver)
//log($('#app').find('.l-con').length+' | '+$('#app').find('.plp-l').length)
return [ver, ver_reg[0]];
}
function show_bb_config(ver){ //显示查找 className DOM个数
//for (let [k, v] of Object.entries(bb)) { !!v && v[0] === '.' && $(v).length !== length && log(v+' - '+$(v).length); }
if(!!ver) { bb = {}; bb_config.set_bb(ver) }
let arr=[];
for (let [k, v] of Object.entries(bb)) { !!v && v[0] === '.' && $(v).length !== -1 && arr.push(v+' - '+$(v).length) && 0 && log(v+' - '+$(v).length); }
for(let i=0; i<=10; i++){
if(i<10){
log(`--------------[${i}]----------------`);
arr.forEach(function(v){
+v.slice(-1) === i && v.slice(-2,-1) === ' ' && log(v);
})
} else if(i===10){
log(`--------------[${i}+]----------------`);
arr.forEach(function(v){
$.isNumeric(parseInt(v.slice(-2,-1))) && log(v);
})
}
}
log('--------------End----------------')
//log(arr)
}
function isrun_3_x_movie() {
let exclude_k = ['danmukuTop', 'danmukuTopClose', 'danmukuBottom', 'danmukuBottomClose', 'biliDlgM', 'coinDlgCoin', 'coinDlgCloseBtn', 'coinDlgOkBtn',
'playTipWrap2',];
let exclude_v = ['.like-info.active', '.coin-info.active', '.collect-info.active', '.coin-dialog-mask .coin-btn', '.bpx-player-volume-hint', '.bili-dialog-m',
'.bpx-player-volume-hint-text', '.bpx-player-volume-hint-icon', '.bpx-player-hotkey-panel', '.coin-dialog-mask', '.bpx-player-electric-jump',
'.bpx-player-hotkey-panel-close', '.bpx-player-info-close', '.bpx-player-info-container', '.info-line','.bpx-player-top-mask'];
for(let [k, v] of Object.entries(bb)){
//if(!!k && exclude_k.indexOf(k) !== -1) log(exclude_k.indexOf(k) +' - '+k+' - '+v);
if(!!k && exclude_k.indexOf(k) !== -1) continue;
//if(!!v && exclude_v.indexOf(v) === -1 && $(v).length === 0) log(exclude_v.indexOf(v) +' - '+$(v).length+' - '+v);
if(!!v && exclude_v.indexOf(v) === -1 && $(v).length === 0) return false;
}
return true;
}
function isrun_3_x_video() {
let exclude_k = ['danmukuTop', 'danmukuTopClose', 'danmukuBottom', 'danmukuBottomClose', 'biliDlgM', 'coinDlgCoin', 'coinDlgCloseBtn', 'coinDlgOkBtn',
'playTipWrap2'];
let exclude_v = ['.ops .like.on', '.ops .coin.on', '.ops .collect.on', '.coin-dialog-mask .coin-btn', '.bpx-player-volume-hint', '.bpx-player-electric-jump',
'.bpx-player-volume-hint-text', '.bpx-player-volume-hint-icon', '.bpx-player-hotkey-panel', '.bili-dialog-m', '.coin-dialog-mask',
'.bpx-player-hotkey-panel-close', '.bpx-player-info-close', '.bpx-player-info-container', '.info-line','.bpx-player-top-mask',
'.bili-dialog-m .bi-btn'];
for(let [k, v] of Object.entries(bb)){
//if(!!k && exclude_k.indexOf(k) !== -1) log(exclude_k.indexOf(k) +' - '+k+' - '+v);
if(!!k && exclude_k.indexOf(k) !== -1) continue;
if(!!v && exclude_v.indexOf(v) === -1 && $(v).length === 0) log(exclude_v.indexOf(v) +' - '+$(v).length+' - '+v);
if(!!v && exclude_v.indexOf(v) === -1 && $(v).length === 0) return false;
}
return true;
}
function isrun_3_x_video_v1() {
let exclude_k = ['danmukuTop', 'danmukuTopClose', 'danmukuBottom', 'danmukuBottomClose', 'biliDlgM', 'coinDlgCoin', 'coinDlgCloseBtn', 'coinDlgOkBtn',
'playTipWrap2'];
let exclude_v = ['.toolbar-left .like.on', '.toolbar-left .coin.on', '.toolbar-left .collect.on', '.coin-dialog-mask .coin-btn', '.bpx-player-volume-hint', '.bpx-player-electric-jump',
'.bpx-player-volume-hint-text', '.bpx-player-volume-hint-icon', '.bpx-player-hotkey-panel', '.bili-dialog-m', '.coin-dialog-mask',
'.bpx-player-hotkey-panel-close', '.bpx-player-info-close', '.bpx-player-info-container', '.info-line','.bpx-player-top-mask',
'.bili-dialog-m .bi-btn'];
for(let [k, v] of Object.entries(bb)){
//if(!!k && exclude_k.indexOf(k) !== -1) log(exclude_k.indexOf(k) +' - '+k+' - '+v);
if(!!k && exclude_k.indexOf(k) !== -1) continue;
if(!!v && exclude_v.indexOf(v) === -1 && $(v).length === 0) log(exclude_v.indexOf(v) +' - '+$(v).length+' - '+v);
if(!!v && exclude_v.indexOf(v) === -1 && $(v).length === 0) return false;
}
return true;
}
//clearTimeout(run_load);
//log('-------run_load----------')
//log(target.className)
run_load = false
//log($('.bpx-player-loading-panel-text').length)
setTimeout(function() {
//log(`-------run_load2----------`)
//log($('.bpx-player-loading-panel-text').text())
let [ver, ver_string] = get_ver();
log(`[${ver_string}][${ver}]加载完毕`);
//if(!ver || !ver_string) {
if(!ver) {
clearTimeout(run_load); return true;
}
bb_config.set_bb(ver);
////////////////////////
////////////////////////
//show_bb_config()
//setTimeout(()=>show_bb_config(),2000)
//return;
////////////////////////
////////////////////////
function run_(){
run()
log('订阅合集列表加载完毕'); expand_list(config.getCheckboxSettingStatus('expandList'), config.getCheckboxSettingArgs('expandList', 'columns'));
log("连播列表加载"); run_rec_list_newtab(config.getCheckboxSettingStatus('openVideoInNewTab'));
add_to_video_sections_head() //列表加入总时长等
setTimeout(()=>run_load = true, 500)
}
if(ver === BILI_3_X_VIDEO) waitForTrue(isrun_3_x_video, run_);
else if(ver === BILI_3_X_VIDEO_V1) waitForTrue(isrun_3_x_video_v1, run_);
else waitForTrue(isrun_3_x_movie, run_);
// log('订阅合集列表加载完毕'); expand_list(config.getCheckboxSettingStatus('expandList'), config.getCheckboxSettingArgs('expandList', 'columns'));
// log("连播列表加载"); run_rec_list_newtab(config.getCheckboxSettingStatus('openVideoInNewTab'));
// add_to_video_sections_head() //列表加入总时长等
}, 500);
} else if(typeof target.className === 'string' && target.className==='bili-dyn-list__items'){
clearTimeout(is_content_load);log(!!config.getCheckboxSettingStatus('showDynListContent') || 1)
is_content_load = setTimeout(function() { log("动态首页加载完毕"); run_content(!!config.getCheckboxSettingStatus('showDynListContent') || true); }, 200);
} else if(typeof target.className === 'string' && target.className === 'avatar' && target.baseURI.indexOf('www.bilibili.com/video/online.html') !== -1){
log("当前在线加载完毕");
run_online_preview(config.getCheckboxSettingStatus('onlinePreview'));
} else if(typeof target.className === 'string' && window.location.href.match(/https?:\/\/www.bilibili.com\/?$/) && is_homepage_load){
waitForTrue(()=> $('.rcmd-box-wrap').length === 1 || $('.bili-grid.short-margin.grid-anchor:first').length === 1, () => {
log("推荐列表加载完毕");
is_homepage_load = false;
run_save_recommend_list(config.getCheckboxSettingStatus('saveRecommendList'));
run_add_carousel_slide();
run_add_online();
});
} else if(typeof target.className === 'string' && target.className==='be-scrollbar fav-list-container ps'){
log(config.getCheckboxSettingStatus('favSetting'))
log(config.sets)
clearTimeout(is_fav_list_load)
is_fav_list_load = setTimeout(function() { log("收藏夹设置完毕"); run_fav(config.getCheckboxSettingStatus('favSetting')); }, 200);
//三连和选择弹窗
} else if(typeof target.className === 'string' && target.className.indexOf('bpx-player-popup-show') !== -1){
hideThreePopup(config.getCheckboxSettingStatus('hideThreePopup'));
//打分弹窗
} else if(typeof target.className === 'string' && target.className.indexOf('bpx-player-score-area') !== -1){
hideScorePopup(config.getCheckboxSettingStatus('hideScorePopup'));
//全屏时视频左上角显示弹幕数
} else if(typeof target.className === 'string' && target.className.indexOf('bpx-player-video-info-dm2') !== -1){
log('==='+$('.bpx-player-top-left-title').text()+' - '+ $('.bpx-player-video-info-dm').text())
if($('.bpx-player-top-left-title').text() !== ''){
clearTimeout(dm_t)
let title = $('.bpx-player-top-left-title').text().match(/(.+?)\s*\|\s*已装填.+条弹幕/)?.[1] || $('.bpx-player-top-left-title').text()
$('.bpx-player-top-left-title').text(title+' | '+$('.bpx-player-video-info-dm').text())
$('.bpx-player-top-wrap').css({visibility: 'visible', opacity: 1})
dm_t = setTimeout(()=>{$('.bpx-player-top-wrap').css({visibility: '', opacity: ''})}, 3000)
}
//全屏时视频左上角显示弹幕数(弹幕数为0时,不会激活‘bpx-player-video-info-dm’,但始终会激活)
} else if(typeof target.className === 'string' && target.className.indexOf('bpx-player-video-info-online2') !== -1){
waitForTrue(()=>$('.bpx-player-top-left-title').text() !== '', ()=>{
setTimeout(()=>{
if($('.bpx-player-video-info-dm').text().match(/\d+/)?.[0] === '0') $('.bpx-player-video-info-dm').text($('.bpx-player-video-info-dm').text())
}, 200) //激活dm
})
// } else if(typeof target.className === 'string' && target.className==='history-list'){
// clearTimeout(is_history_break);
// is_history_break = setTimeout(function() { log("历史记录加载完毕"); run_history()}, 200);
//clearTimeout(is_rcmd_box_break);
//is_rcmd_box_break = setTimeout(function() { log("推荐列表加载完毕"); run_recommend_box()}, 50);
// } else if(is_card_load === false && typeof target.className === 'string' && target.className === 'card' && $(target).find('.video-container .content').length){
// is_card_load = true;
// log("2.X动态首页加载完毕");
// run_card(); //搞笑,刚写完,2.70.7就有了
// removeMostViewedListener(config.getCheckboxSettingStatus('removeMostViewedListener'));
}
});
}).observe(document, {
childList: true,
subtree: true,
//attributes: true,
});
}
init();
}
}
hhh_lightoff_main.init();