// ==UserScript== // @name b站首页推荐精简测试版 // @namespace kasw // @version 0.6 // @description 网页端首页推荐视频 // @author kaws // @match *://www.bilibili.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com // @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.4.1/dist/jquery.min.js // @require https://cdn.jsdelivr.net/npm/js-md5@0.7.3/src/md5.min.js // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 用于授权 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'); } let isWait = false; let options = { maxClientWidth: $(window).width(), sizes: null, accessKey: GM_getValue('biliAppHomeKey'), refresh: 1, itemHeight: 0 } let $list = null; function init(){ if(location.pathname != '/'){ return } setSize(options.maxClientWidth); initStyle(); intiHtml(); initEvent(); if(options.accessKey){ $('#JaccessKey').hide() } getRecommendList(); console.log(options) } // 样式 function initStyle(){ let style = ` `; $('head').append(style) } // 结构 function intiHtml(){ let $position = $('.bili-grid').eq(1); let html = `
`; $position.after(html); $list = $('#recommend-list'); } // 提示 function toast(msg, duration = 2000){ let $toast = $(`
${msg}
`); $toast.appendTo($('body')); setTimeout(() => { $toast.remove() }, duration) } // loading function showLoading(minHeight){ $list.prepend(`

正在加载...

`) } // 事件 function initEvent(){ $('#JaccessKey').on('click', function(){ let $this = $(this); let type = $this.text().trim(); if(isWait){ return } isWait = true if(type == '删除授权'){ $this.find('span').text('获取授权'); delAccessKey() } if(type == '获取授权'){ $this.find('span').text('获取中...'); getAccessKey($this) } return false }) $('#Jrefresh').on('click', function(){ let $this = $(this); let $svg = $this.find('svg'); var reg = /(rotate\([\-\+]?((\d+)(deg))\))/i; var css = $svg.attr('style'); var wts = css.match(reg); $svg.css('transform', `rotate(${parseFloat(wts[3]) + 360}deg)`); console.log(options); options.maxClientWidth = $(window).width(); setSize(options.maxClientWidth); getRecommendList(); }) $list.on('mouseenter', '.bili-video-card__image', function(e){ e.stopPropagation(); let rect = e.currentTarget.getBoundingClientRect(); let $this = $(this); if($this.data('go') == 'av'){ $this.find('.bili-watch-later').stop().fadeIn(); $this.find('.v-inline-player').addClass('mouse-in visible'); getPreviewImage($this, e.clientX - rect.left) } }).on('mouseleave', '.bili-video-card__image', function(e){ e.stopPropagation(); let $this = $(this); if($this.data('go') == 'av'){ $this.find('.bili-watch-later').stop().fadeOut(); $this.find('.v-inline-player').removeClass('mouse-in visible'); } }).on('mousemove', '.bili-video-card__image', function(e){ e.stopPropagation(); let rect = e.currentTarget.getBoundingClientRect(); let $this = $(this); if($this.data('go') == 'av'){ if($this[0].pvData){ // if(e.target.className == 'bili-watch-later'){ // return // } setPosition($this, e.clientX - rect.left, $this[0].pvData) } } }).on('mouseenter', '.bili-watch-later', function(e){ e.stopPropagation(); let $this = $(this); $this.find('span').stop().fadeIn() }).on('mouseleave', '.bili-watch-later', function(e){ e.stopPropagation(); let $this = $(this); $this.find('span').stop().fadeOut() }).on('click', '.bili-watch-later', function(){ let $this = $(this); watchlater($this); return false }).on('click', '.BBDown', function(){ let $this = $(this); let id = $this.data('id'); let isGo = /\//.test(id); if(isGo){ let arr = id.split('/'); id = arr[arr.length - 1] } GM_setClipboard(`BBDown -app -token ${options.accessKey} -mt -ia -p all "${id}"`); toast('复制命令成功') return }) } function setSize(width){ if(width < 1684){ options.sizes = 5 * 4 }else if(width >= 2183){ options.sizes = 7 * 4 }else{ options.sizes = 6 * 4 } } // 删除授权 function delAccessKey(){ isWait = false; options.accessKey = null; GM_deleteValue('biliAppHomeKey'); toast('获取删除成功'); } // 获取授权 async function getAccessKey(el){ let uri = null; let 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' }) let data = await res.json(); 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 { uri = data.data.confirm_uri } let $iframe = $(`