Created
January 4, 2023 07:03
-
-
Save tiantian1645/12970c976099d3202286bfb3b0729a33 to your computer and use it in GitHub Desktop.
我算出了三体动画的真实评分
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://wdhhh.cn/home?article=627 | |
// https://www.bilibili.com/video/BV1WG4y117mz/ | |
const scoreList = { | |
short: [], | |
long: [], | |
} | |
let totalCount = { | |
short: 0, | |
long: 0, | |
} | |
let render = null | |
let rmDialog = null | |
let mid | |
try { | |
mid = location.href.match(/media\/md(\d+)\//)[1] | |
} catch (_) { | |
_; | |
} | |
if (!mid) { throw new Error("未进入介绍详情页面") } | |
async function getScore(next, type) { | |
let url = `https://api.bilibili.com/pgc/review/${type}/list?media_id=${mid}&ps=12575&sort=0` | |
if (next) { | |
url += `&cursor=${next}` | |
} | |
const res = await fetch(url, { "method": "GET" }); | |
const { data } = await res.json() | |
if (totalCount[type] == 0) { | |
totalCount[type] = data.total | |
} | |
return data | |
} | |
async function scoreMain(type) { | |
let { list, next } = await getScore(undefined, type) | |
handlerList(list, type) | |
while (true) { | |
const data = await getScore(next, type) | |
handlerList(data.list, type) | |
render(type) | |
next = data.next | |
if (next == 0) { | |
return | |
} | |
} | |
} | |
function average() { | |
let a_short = scoreList['short'] | |
const total = a_short.reduce((p, v) => { | |
return p + v | |
}, 0) | |
console.log('短评总分:', total) | |
console.log('短评数量:', a_short.length) | |
console.log('短评平均分:', total / a_short.length) | |
let a_long = scoreList['long'] | |
const totalLong = a_long.reduce((p, v) => { | |
return p + v | |
}, 0) | |
console.log('长评总分:', totalLong) | |
console.log('长评数量:', a_long.length) | |
console.log('长评平均分:', totalLong / a_long.length) | |
const sf = ((total + totalLong) / (a_short.length + a_long.length)).toFixed(1) | |
document.getElementsByClassName("media-info-score-content")[0].innerText = sf | |
const starLc = parseInt(Math.round(sf / 2)) | |
const starHc = 5 - starLc | |
const starsDom = document.getElementsByClassName("review-stars")[0] | |
starsDom.innerHTML = '' | |
for (let i = 0; i < starLc; i++) { | |
const star = document.createElement('i') | |
star.className = "icon-star icon-star-light" | |
starsDom.appendChild(star) | |
} | |
for (let i = 0; i < starHc; i++) { | |
const star = document.createElement('i') | |
star.className = "icon-star icon-star-half" | |
starsDom.appendChild(star) | |
} | |
console.log('总平均分:', sf) | |
} | |
function handlerList(list, type) { | |
scoreList[type].push(...list.map(item => item.score)) | |
} | |
function beforeRender() { | |
const dialog = document.createElement('div') | |
document.body.appendChild(dialog) | |
dialog.style.position = 'fixed' | |
dialog.style.width = '100%' | |
dialog.style.height = '100%' | |
dialog.style.background = 'rgba(0,0,0,.8)' | |
dialog.style.top = '0' | |
dialog.style.left = '0' | |
dialog.style.zIndex = '999' | |
dialog.style.display = 'flex' | |
dialog.style.alignItems = 'center' | |
dialog.style.justifyContent = 'center' | |
const dialogContent = document.createElement('div') | |
dialog.appendChild(dialogContent) | |
dialogContent.style.width = '455px' | |
dialogContent.style.height = '200px' | |
dialogContent.style.background = '#fff' | |
dialogContent.style.borderRadius = '6px' | |
dialogContent.style.padding = '51px 0' | |
const shortWrap = document.createElement('div') | |
dialogContent.appendChild(shortWrap) | |
const longWrap = document.createElement('div') | |
dialogContent.appendChild(longWrap) | |
shortWrap.style.width = longWrap.style.width = '455px' | |
shortWrap.style.height = longWrap.style.height = '100px' | |
shortWrap.style.display = longWrap.style.display = 'flex' | |
shortWrap.style.alignItems = longWrap.style.alignItems = 'center' | |
shortWrap.style.justifyContent = longWrap.style.justifyContent = 'center' | |
// -------------- | |
const shortw1 = document.createElement('div') | |
const longw1 = document.createElement('div') | |
shortWrap.appendChild(shortw1) | |
longWrap.appendChild(longw1) | |
shortw1.innerText = '短评:' | |
longw1.innerText = '长评:' | |
longw1.style.fontSize = shortw1.style.fontSize = '14px' | |
longw1.style.color = shortw1.style.color = '#333' | |
longw1.style.marginRight = shortw1.style.marginRight = '16px' | |
const shortw2 = document.createElement('div') | |
const longw2 = document.createElement('div') | |
shortWrap.appendChild(shortw2) | |
longWrap.appendChild(longw2) | |
longw2.style.width = shortw2.style.width = '300px' | |
longw2.style.height = shortw2.style.height = '32px' | |
longw2.style.background = shortw2.style.background = '#eee' | |
longw2.style.position = shortw2.style.position = 'relative' | |
const shortPrg = document.createElement('div') | |
const longPrg = document.createElement('div') | |
shortw2.appendChild(shortPrg) | |
longw2.appendChild(longPrg) | |
longPrg.style.position = shortPrg.style.position = 'absolute' | |
longPrg.style.left = shortPrg.style.left = '0' | |
longPrg.style.top = shortPrg.style.top = '0' | |
longPrg.style.width = shortPrg.style.width = '0%' | |
longPrg.style.height = shortPrg.style.height = '100%' | |
longPrg.style.background = shortPrg.style.background = '#ff85ad' | |
render = function (type) { | |
const dom = type == 'long' ? longPrg : shortPrg | |
let width; | |
let a_short = scoreList['short'] | |
let a_long = scoreList['long'] | |
if (type == 'long') { | |
width = (a_short.length * 100 / totalCount.long) + '%' | |
} else { | |
width = (a_long.length * 100 / totalCount.short) + '%' | |
} | |
dom.style.width = width | |
} | |
rmDialog = function () { | |
document.body.removeChild(dialog) | |
} | |
} | |
async function main() { | |
beforeRender() | |
console.log("--统计短评"); | |
await scoreMain('short') | |
console.log("--统计长评"); | |
await scoreMain('long') | |
average() | |
rmDialog() | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment