Skip to content

Instantly share code, notes, and snippets.

@ipid
Created January 23, 2022 12:44
Show Gist options
  • Save ipid/7baa51e4756bae8788f15b07b5a719f7 to your computer and use it in GitHub Desktop.
Save ipid/7baa51e4756bae8788f15b07b5a719f7 to your computer and use it in GitHub Desktop.
用于在 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