// ==UserScript== // @name b站首页推荐 // @namespace kasw // @version 5.9 // @description 网页端app首页推荐视频 // @author kaws // @match *://www.bilibili.com/* // @icon https://www.bilibili.com/favicon.ico // @compatible chrome // @compatible edge // @compatible firefox // @compatible safari // @source https://github.com/kawS/bilibili-recommend-app // @include https://www.mcbbs.net/template/mcbbs/image/special_photo_bg.png?* // @connect app.bilibili.com // @connect api.bilibili.com // @connect passport.bilibili.com // @connect www.mcbbs.net // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_setClipboard // @run-at document-idle // @require https://cdn.jsdelivr.net/npm/jquery@3.6.1/dist/jquery.min.js // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; const isNewTest = $('#i_cecream').find('.bili-feed4').length > 0 ? true : false; const itemHeight = isNewTest ? $('.recommended-swipe').next('.feed-card').height() : $('.bili-grid').eq(0).find('.bili-video-card').height(); let $list = null; let isWait = false; let isLoading = true; let options = { clientWidth: $(window).width(), sizes: null, timeoutKey: 1900800000, refresh: 1, oneItemHeight: itemHeight, listHeight: itemHeight * 4 + 20 * 3, accessKey: GM_getValue('biliAppHomeKey'), dateKey: GM_getValue('biliAppHomeKeyDate'), isShowDanmaku: typeof GM_getValue('biliAppDanmaku') == 'undefined' ? false : GM_getValue('biliAppDanmaku'), isAppType: typeof GM_getValue('biliAppType') == 'undefined' ? true : GM_getValue('biliAppType') // true:app;false:pc } function init(){ if(location.href.startsWith('https://www.mcbbs.net/template/mcbbs/image/special_photo_bg.png?')){ window.stop(); return window.top.postMessage(location.href, 'https://www.bilibili.com') } localStorage.setItem('bilibili_player_force_DolbyAtmos&8K&HDR', 1); Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15' }); if(location.pathname != '/') return; setSize(options.clientWidth); initStyle(); intiHtml(); initEvent(); checkAccessKey(); getRecommendList(); } function setSize(width){ let row = 5; if(isNewTest){ if(width <=1400){ options.sizes = 4 * row }else{ options.sizes = 5 * row } }else{ if(width <= 1100){ options.sizes = 4 * row } if(width > 1100 && width <= 1700){ options.sizes = 5 * row } if(width > 1700 && width < 2200){ options.sizes = 6 * row } if(width >= 2200){ options.sizes = 7 * row } } } function initStyle(){ const style = ` `; $('head').append(style) } function intiHtml(){ const $fullpage = $('#i_cecream'); let html = null; let emptyHtml = ''; if($fullpage.length <= 0) return; for(let i=0;i

` } html = `
是否使用app推荐接口
是否预览弹幕
${emptyHtml}
`; if(isNewTest){ $fullpage.find('.recommended-container_floor-aside').before(`
${html}
`) }else{ $fullpage.find('.bili-header').after(`
${html}
`); } $('#scrollwrap').next().hide(); $list = $('#recommend-list'); } function initEvent(){ $('#JaccessKey').on('click', function(){ const $this = $(this); let type = $this.text().trim(); if(isWait) return; isWait = true if(type == '删除授权'){ $this.find('span').text('获取授权'); delAccessKey() } if(type == '获取授权' || type == '重新获取授权'){ $this.find('span').text('获取中...'); getAccessKey($this) } return false }) $list.on('mouseenter', '.bili-video-card__image', function(e){ e.stopPropagation(); const $this = $(this); let rect = e.currentTarget.getBoundingClientRect(); if($this.data('go') == 'av'){ // $this.find('.bili-watch-later').show(); $this.find('.v-inline-player').addClass('mouse-in visible'); getPreviewImage($this, e.clientX - rect.left); if(options.isShowDanmaku){ $this.find('.v-inline-danmaku').addClass('mouse-in visible'); getPreviewDanmaku($this) } } }).on('mouseleave', '.bili-video-card__image', function(e){ e.stopPropagation(); const $this = $(this); if($this.data('go') == 'av'){ // $this.find('.bili-watch-later').hide(); $this.find('.v-inline-player, .v-inline-danmaku').removeClass('mouse-in visible'); } }).on('mousemove', '.bili-video-card__image', function(e){ e.stopPropagation(); const $this = $(this); let rect = e.currentTarget.getBoundingClientRect(); if($this.data('go') == 'av'){ if($this[0].pvData){ setPosition($this, e.clientX - rect.left, $this[0].pvData) } } }).on('click', '#Jwatch', function(){ const $this = $(this); if(isWait) return; isWait = true; watchlater($this); return false }).on('click', '.dislike .dl', function(){ const $this = $(this); if(isWait) return; isWait = true; dislike($this); return false }).on('click', '#Jreturn', function(){ const $this = $(this); if(isWait) return; isWait = true; dislike($this, true); return false }).on('click', '#Jbbdown', function(){ const $this = $(this); let id = $this.data('id'); if(options.isAppType){ GM_setClipboard(`BBDown -app -token ${options.accessKey} -mt -ia -p ALL "${id}"`); }else{ GM_setClipboard(`BBDown -app -mt -ia -p ALL "${id}"`); } toast('复制BBDown命令行成功') return false }).on('click', '.more', function(){ const $this = $(this); const $wp = $this.closest('.bili-video-card__wrap'); $wp.find('.ctrl').css({ 'height': $wp.height() }).fadeIn(); return false }).on('mouseleave', '.ctrl', function(){ const $this = $(this); if($this.find('.dlike').length > 0){ return } $this.fadeOut() }) $('#JShowDanmaku').on('click', function(){ const $this = $(this); const $inp = $this.find('input'); let val = JSON.parse($inp.val()); options.isShowDanmaku = !val; GM_setValue('biliAppDanmaku', options.isShowDanmaku); $inp.val(options.isShowDanmaku); if(options.isShowDanmaku){ $this.addClass('is-checked') }else{ $this.removeClass('is-checked') } return false }) $('#JUseApp').on('click', function(){ const $this = $(this); const $inp = $this.find('input'); let val = JSON.parse($inp.val()); options.isAppType = !val; GM_setValue('biliAppType', options.isAppType); $inp.val(options.isAppType); if(options.isAppType){ $this.addClass('is-checked') }else{ $this.removeClass('is-checked') } setTimeout(() => { location.reload() }, 500) return false }) $(window).on('scroll', function(){ if(options.refresh == 1) return; const $this = $(this); if(($this.scrollTop() + $(window).height()) > ($('#empty-list').offset().top - options.oneItemHeight)){ if(isLoading) return; isLoading = true; options.clientWidth = $(window).width(); setSize(options.clientWidth); getRecommendList() } }) } function toast(msg, cb, duration = 2000){ const $toast = $(`
${msg}
`); $toast.appendTo($('body')); setTimeout(() => { $toast.remove(); typeof cb == 'function' && cb() }, duration) } function delAccessKey(){ isWait = false; options.accessKey = null; options.dateKey = null; GM_deleteValue('biliAppHomeKey'); GM_deleteValue('biliAppHomeKeyDate'); toast('删除授权成功'); } async function getAccessKey($el){ let url = null; let res = null; let data = null; try { res = await fetch('https://passport.bilibili.com/login/app/third?appkey=27eb53fc9058f8c3&api=https%3A%2F%2Fwww.mcbbs.net%2Ftemplate%2Fmcbbs%2Fimage%2Fspecial_photo_bg.png&sign=04224646d1fea004e79606d3b038c84a', { method: 'GET', credentials: 'include' }) } catch (error) { toast(error) } try { data = await res.json(); } catch (error) { toast(error) } if (data.code || !data.data) { $el.find('span').text('获取授权'); toast(data.msg || data.message || data.code) } else if (!data.data.has_login) { $el.find('span').text('获取授权'); toast('你必须登录B站之后才能使用授权') } else if (!data.data.confirm_uri) { $el.find('span').text('获取授权'); toast('无法获得授权网址') } else { url = data.data.confirm_uri } if(url == null){ isWait = false; return } const $iframe = $(`