// ==UserScript== // @name Bilibili av/bv link preview // @name:zh-CN Bilibili av/bv 链接预览 // @namespace http://tampermonkey.net/ // @version 0.4 // @description 鼠标置于av/bv号上时弹出视频内容预览 // @author xdedss // @match https://www.bilibili.com/video/* // @grant none // @require https://code.jquery.com/jquery-2.2.4.min.js // @downloadURL none // ==/UserScript== (function() { //可更改的设定 var cover_width = 280; //窗口宽度 var cover_padding = 15; //窗口padding var face_width = 20; //up头像大小 var max_desc_length = 60; //视频描述长度 var active_element = null; //获取元素坐标 function getTop(e){ var offset=e.offsetTop; if(e.offsetParent!=null) offset+=getTop(e.offsetParent); return offset; } function getLeft(e){ var offset=e.offsetLeft; if(e.offsetParent!=null) offset+=getLeft(e.offsetParent); return offset; } function pad(num, n) { num = num.toString(); var len = num.length; while(len < n) { num = "0" + num; len++; } return num; } function trimDesc(desc){ if (desc.length < max_desc_length){ return desc; } return desc.substr(0, max_desc_length - 10) + '...'; } function formatDuration(seconds){ var sec = seconds % 60; seconds -= sec; var min = (seconds / 60) % 60; seconds -= 60 * min; var hr = seconds / 3600; var res = `${pad(min, 2)}:${pad(sec, 2)}`; if (hr != 0){ res = pad(hr, 2) + ':' + res; } return res; } function formatTime(timestamp) { var date = new Date(timestamp * 1000); var Y = pad(date.getFullYear(), 2); var M = pad(date.getMonth() + 1, 2); var D = pad(date.getDate(), 2); var h = pad(date.getHours(), 2); var m = pad(date.getMinutes(), 2); var s = pad(date.getSeconds(), 2); return `${Y}-${M}-${D} ${h}:${m}:${s}`; } function formatNumber(num){ if (num > 10000){ return (Math.round(num / 1000) / 10.0) + '万'; } return num + ''; } //重设框的位置 function initBox(e){ if ($('#avbvinfo').length == 0){ $('body').after(`
`); } $('#avbvinfo').css('left', Math.min($('body')[0].offsetWidth-cover_width-2*cover_padding, Math.floor(getLeft(e.target)+e.target.offsetWidth * 0.1))+'px') .css('top', Math.floor(getTop(e.target)+e.target.offsetHeight * 0.9)+'px').css('display','').html('...'); } //隐藏 function hideBox(){ $('#avbvinfo').css('display', 'none').html('...'); active_element = null; } //在框内显示内容 function showBox(data){ //console.log(data); if (data.code != 0) { $('#avbvinfo').html(`啊叻?视频不见了?${formatNumber(data.stat.like)} | ${formatNumber(data.stat.coin)} | ${formatNumber(data.stat.favorite)} | ${formatNumber(data.stat.reply)} |