Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
用于在 B 站视频播放页显示点赞率、收藏率、P 名的用户脚本。
// ==UserScript==
// @name B站视频显示点赞率
// @namespace https://ipid.me
// @version 0.1
// @description 在视频播放页面显示点赞率(点赞数 / 总播放数)
// @author ipid
// @match *://www.bilibili.com/video/*
// ==/UserScript==
(function () {
'use strict';
const videoData = JSON.parse(JSON.stringify(unsafeWindow.__INITIAL_STATE__.videoData))
function injectInfo(parent) {
const myInfo = document.createElement('span')
myInfo.innerHTML = ` 点赞率${(videoData.stat.like / videoData.stat.view * 100).toFixed(1)}% 投币率${(videoData.stat.coin / videoData.stat.view * 100).toFixed(1)}% 收藏率${(videoData.stat.favorite / videoData.stat.view * 100).toFixed(1)}% P名:${videoData.pages[0].part}`
myInfo.style.color = '#999'
myInfo.style.overflow = 'hidden'
myInfo.style.textOverflow = 'ellipsis'
parent.appendChild(myInfo)
}
function doInject() {
const viewboxReport = document.querySelector('div.video-data')
if (viewboxReport && !viewboxReport.innerHTML.includes('点赞率')) {
injectInfo(viewboxReport)
}
}
let count = 0
function loopInject() {
doInject()
count++
if (count <= 15) {
setTimeout(loopInject, 1000)
}
}
loopInject()
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment