// ==UserScript== // @name BiliBili播放页调整 // @license GPL-3.0 License // @namespace https://greasyfork.org/zh-CN/scripts/415804-bilibili%E6%92%AD%E6%94%BE%E9%A1%B5%E8%B0%83%E6%95%B4-%E8%87%AA%E7%94%A8 // @version 0.5.6 // @description 1.自动定位到播放器(进入播放页,可自动定位到播放器,可设置偏移量及是否在点击主播放器时定位);2.可设置是否自动选择最高画质;3.可设置播放器默认模式; // @author QIAN // @match *://*.bilibili.com/video/* // @match *://*.bilibili.com/bangumi/play/* // @require https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js // @require https://cdn.jsdelivr.net/npm/sweetalert2@11.3.6/dist/sweetalert2.all.min.js // @resource swalStyle https://cdn.jsdelivr.net/npm/sweetalert2@11.3.6/dist/sweetalert2.min.css // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @grant GM_getResourceText // @supportURL https://github.com/QIUZAIYOU/Bilibili-VideoPage-Adjustment // @homepageURL https://github.com/QIUZAIYOU/Bilibili-VideoPage-Adjustment // @downloadURL none // ==/UserScript== $(function () { const util = { getValue (name) { return GM_getValue(name) }, setValue (name, value) { GM_setValue(name, value) }, exist (selecter) { return $(selecter).length >= 1 }, addStyle (id, tag, css) { tag = tag || 'style' const doc = document const styleDom = doc.getElementById(id) if (styleDom) return const style = doc.createElement(tag) style.rel = 'stylesheet' style.id = id tag === 'style' ? (style.innerHTML = css) : (style.href = css) document.head.appendChild(style) }, sleep (time) { return new Promise((resolve) => setTimeout(resolve, time)); }, getScrollTop () { var scroll_top = 0 if (document.documentElement && document.documentElement.scrollTop) { scroll_top = document.documentElement.scrollTop } else if (document.body) { scroll_top = document.body.scrollTop } return scroll_top } } const main = { initValue () { const value = [ { name: 'offset_top', value: 7 }, { name: 'player_offset_top', value: 160 }, { name: 'is_vip', value: false }, { name: 'click_player_auto_locate', value: true }, { name: 'current_screen_mod', value: 'normal' }, { name: 'selected_screen_mod', value: 'widescreen' }, { name: 'auto_select_video_highest_quality', value: true } ] value.forEach((v) => { if (util.getValue(v.name) === undefined) { util.setValue(v.name, v.value) } }) }, autoLocation () { const offset_top = util.getValue('offset_top') const click_player_auto_locate = util.getValue( 'click_player_auto_locate' ) if (util.exist('#playerWrap #bilibiliPlayer')) { const player_offset_top = $('#bilibiliPlayer').offset().top util.setValue('player_offset_top', player_offset_top) $('html,body').scrollTop(player_offset_top - offset_top) if (click_player_auto_locate) { $('#bilibiliPlayer').on('click', function () { $('html,body').scrollTop(player_offset_top - offset_top) }) } } if (util.exist('#player_module #bilibili-player')) { const player_offset_top = $('#bilibili-player').offset().top util.setValue('player_offset_top', player_offset_top) $('html,body').scrollTop(player_offset_top - offset_top) if (click_player_auto_locate) { $('#bilibili-player').on('click', function () { $('html,body').scrollTop(player_offset_top - offset_top) }) } } }, getUserVipState () { if (util.exist('.bili-avatar-icon--big-vip')) { util.setValue('is_vip', true) } else { util.setValue('is_vip', false) } console.log(util.getValue('is_vip')) }, getCurrentScreenMod () { if (util.exist('#playerWrap #bilibiliPlayer')) { const playerClass = $('#bilibiliPlayer').attr('class') const mutationObserver = new MutationObserver(() => { if (playerClass.includes('mode-widescreen')) { util.setValue('current_screen_mod', 'widescreen') } if (playerClass.includes('mode-webfullscreen')) { util.setValue('current_screen_mod', 'webfullscreen') } }) mutationObserver.observe($('#bilibiliPlayer')[0], { attributes: true }) } if (util.exist('#player_module #bilibili-player')) { const mutationObserver = new MutationObserver(() => { const playerDataScreen = $( '#bilibili-player .bpx-player-container' ).attr('data-screen') if (playerDataScreen === 'normal') { util.setValue('current_screen_mod', 'normal') } if (playerDataScreen === 'wide') { util.setValue('current_screen_mod', 'widescreen') } if (playerDataScreen === 'web') { util.setValue('current_screen_mod', 'webfullscreen') } }) mutationObserver.observe($('#bilibili-player')[0], { attributes: true }) } }, autoSelectScreenMod () { const current_screen_mod = util.getValue('current_screen_mod') const selected_screen_mod = util.getValue('selected_screen_mod') if (util.exist('#playerWrap #bilibiliPlayer')) { // console.log('a', current_screen_mod, selected_screen_mod); const playerClass = $('#bilibiliPlayer').attr('class') if ( selected_screen_mod === 'normal' && current_screen_mod !== 'normal' ) { $('.bilibili-player-video-btn.closed').click() } if ( selected_screen_mod === 'widescreen' && current_screen_mod !== 'widescreen' && !playerClass.includes('mode-widescreen') ) { $('[data-text="宽屏模式"]').click() } if ( selected_screen_mod === 'webfullscreen' && current_screen_mod !== 'webfullscreen' && !playerClass.includes('mode-webfullscreen') ) { $('[data-text="网页全屏"]').click() } } if (util.exist('#player_module #bilibili-player')) { // console.log('b', current_screen_mod, selected_screen_mod); const playerDataScreen = $( '#bilibili-player .bpx-player-container' ).attr('data-screen') if ( selected_screen_mod === 'normal' && current_screen_mod !== 'normal' ) { $( '.squirtle-controller-wrap-right .squirtle-video-item.active' ).click() } if ( selected_screen_mod === 'widescreen' && current_screen_mod !== 'widescreen' && playerDataScreen !== 'wide' ) { $('.squirtle-widescreen-wrap .squirtle-video-widescreen').click() } if ( selected_screen_mod === 'webfullscreen' && current_screen_mod !== 'webfullscreen' && playerDataScreen !== 'web' ) { $( '.squirtle-pagefullscreen-wrap.squirtle-video-pagefullscreen' ).click() } } }, autoSelectVideoHightestQuality () { const is_vip = util.getValue('is_vip') const auto_select_video_highest_quality = util.getValue( 'auto_select_video_highest_quality' ) if (auto_select_video_highest_quality) { if (is_vip) { if (util.exist('#playerWrap #bilibiliPlayer')) { $('.bui-select-list-wrap > ul > li').eq(0).click() } if (util.exist('#player_module #bilibili-player')) { $('.squirtle-quality-wrap >.squirtle-video-quality > ul > li') .eq(0) .click() } } else { if (util.exist('#playerWrap #bilibiliPlayer')) { const selectVipItemLength = $( '.bui-select-list-wrap > ul > li' ).children('.bilibili-player-bigvip').length $('.bui-select-list-wrap > ul > li').eq(selectVipItemLength).click() } if (util.exist('#player_module #bilibili-player')) { const selectVipItemLength = $( '.squirtle-quality-wrap >.squirtle-video-quality > ul > li' ).children('.squirtle-bigvip').length $('.squirtle-quality-wrap >.squirtle-video-quality > ul > li') .eq(selectVipItemLength) .click() } } } }, registerMenuCommand () { GM_registerMenuCommand('设置', () => { const html = `