// ==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.4.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() { let util = { getValue(name) { return GM_getValue(name); }, setValue(name, value) { GM_setValue(name, value); }, exist(selecter) { return Boolean($(selecter).length >= 1) }, addStyle(id, tag, css) { tag = tag || 'style'; let doc = document, styleDom = doc.getElementById(id); if (styleDom) return; let style = doc.createElement(tag); style.rel = 'stylesheet'; style.id = id; tag === 'style' ? style.innerHTML = css : style.href = css; document.head.appendChild(style); }, }; let main = { initValue() { let value = [{ name: 'top_offset', value: 7 }, { name: 'click_player_auto_location', 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() { let top_offset = util.getValue('top_offset') let click_player_auto_location = util.getValue('click_player_auto_location') if (util.exist('#playerWrap #bilibiliPlayer')) { $('html,body').scrollTop($('#bilibiliPlayer').offset().top - top_offset); if (click_player_auto_location) { $('#bilibiliPlayer').on('click', function() { $('html,body').scrollTop($('#bilibiliPlayer').offset().top - top_offset); }); } } if (util.exist('#player_module #bilibili-player')) { $('html,body').scrollTop($('#bilibili-player').offset().top - top_offset); if (click_player_auto_location) { $('#bilibili-player').on('click', function() { $('html,body').scrollTop($('#bilibili-player').offset().top - top_offset); }); } } }, getCurrentScreenMod() { if (util.exist('#playerWrap #bilibiliPlayer')) { const playerClass = $('#bilibiliPlayer').attr('class'); let 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')) { let 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() { let current_screen_mod = util.getValue('current_screen_mod') let 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() { let auto_select_video_highest_quality = util.getValue('auto_select_video_highest_quality') if (auto_select_video_highest_quality) { 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(); } } }, registerMenuCommand() { GM_registerMenuCommand('设置', () => { let html = `