// ==UserScript== // @name BiliBili播放页调整(自用) // @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.2 // @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 // @downloadURL none // ==/UserScript== $(function() { let util = { getValue(name) { return GM_getValue(name); }, setValue(name, value) { GM_setValue(name, value); }, exist(id){ return Boolean($(id).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 }, { name: 'delay', value: 3800 }]; 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('#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('#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('#bilibiliPlayer')){ const playerClass = $('#bilibiliPlayer').attr('class'); let mutationObserver = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { 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('#bilibili-player')){ const playerDataScreen = $('#bilibili-player .bpx-player-container').attr('data-screen'); let mutationObserver = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { 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') console.log(current_screen_mod, selected_screen_mod); if (util.exist('#bilibili-player')){ if (selected_screen_mod === 'normal') { if (current_screen_mod !== 'normal') { $('.bilibili-player-video-btn.closed').click(); } } if (selected_screen_mod === 'widescreen') { if (current_screen_mod !== 'widescreen') { $('.bilibili-player-video-btn.bilibili-player-video-btn-widescreen').click(); } } if (selected_screen_mod === 'webfullscreen') { if (current_screen_mod !== 'webfullscreen') { $('.bilibili-player-video-btn.bilibili-player-video-web-fullscreen').click(); } } } if (util.exist('#bilibili-player')){ if (selected_screen_mod === 'normal') { if (current_screen_mod !== 'normal') { $('.squirtle-controller-wrap-right .squirtle-video-item.active').click(); } } if (selected_screen_mod === 'widescreen') { if (current_screen_mod !== 'widescreen') { $('.squirtle-widescreen-wrap .squirtle-video-widescreen').click(); } } if (selected_screen_mod === 'webfullscreen') { if (current_screen_mod !== 'webfullscreen') { $('.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('#bilibiliPlayer')){ $('.bui-select-list-wrap > ul > li').eq(0).click(); } if (util.exist('#bilibili-player')){ $('.squirtle-quality-wrap >.squirtle-video-quality > ul > li').eq(0).click(); } } }, registerMenuCommand() { GM_registerMenuCommand('设置', () => { let html = `