每日一个b站热词
// ==UserScript==
// @name 每日一个b站热词
// @namespace https://bbs.tampermonkey.net.cn/
// @version 1.0.2
// @description 每天了解一个b站热词,防止自己与时代脱节(数据来源b站官方的热词解释)
// @author Vikrant
// @crontab * 7-21 once * *
// @icon https://www.bilibili.com/favicon.ico
// @grant GM_xmlhttpRequest
// @grant GM_log
// @grant GM_notification
// @grant GM_openInTab
// @grant GM_closeNotification
// @connect api.bilibili.com
// @license GNU GPLv3
// ==/UserScript==
return new Promise((resolve, reject) => {
getWord()
.then((word) => {
GM_notification({
title: word.name,
text: word.description,
onclick: (id) => {
GM_openInTab(
"https://www.bilibili.com/blackboard/activity-WroMZNunfa.html?id=" + word.id
)
GM_closeNotification(id)
resolve()
},
timeout: 10000,
ondone: resolve
})
})
.catch((err) => {
reject(err)
})
let scanTime = setTimeout(() => {
reject("运行超时")
}, 15000);
})
function checkId(id = 1) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: "http://api.bilibili.com/x/v2/dm/buzzword/detail?id=" + id,
method: "get",
timeout: 1000,
onload: (xhr) => {
let json = JSON.parse(xhr.responseText)
let code = JSON.stringify(json.code)
if (code == 0) {
resolve()
} else {
reject()
}
},
onerror: () => {
reject("error")
},
ontimeout: () => {
reject("timeout")
}
})
})
}
function getWord() {
return new Promise((resolve, reject) => {
let id = Math.floor(Math.random() * 999 + 1)
checkId(id)
.then(() => {
GM_xmlhttpRequest({
url: "http://api.bilibili.com/x/v2/dm/buzzword/detail?id=" + id,
method: "get",
timeout: 1000,
onload: (xhr) => {
let json = JSON.parse(xhr.responseText)
let name = JSON.stringify(json.data.name)
let description = JSON.stringify(json.data.description)
resolve({ name, description, id })
}
})
})
.catch((err) => {
//GM_log("fali")
if (err == "error") {
reject("请求出错!")
} else if (err == "timeout") {
reject("请求超时!")
} else {
resolve(getWord())
}
})
})
}
/*
.o8
"888
888oooo. oooo ooo
d88' `88b `88. .8'
888 888 `88..8'
888 888 `888'
`Y8bod8P' .8'
.o..P'
`Y8P'
oooooo oooo o8o oooo .
`888. .8' `"' `888 .o8
`888. .8' oooo 888 oooo oooo d8b .oooo. ooo. .oo. .o888oo
`888. .8' `888 888 .8P' `888""8P `P )88b `888P"Y88b 888
`888.8' 888 888888. 888 .oP"888 888 888 888
`888' 888 888 `88b. 888 d8( 888 888 888 888 .
`8' o888o o888o o888o d888b `Y888""8o o888o o888o "888"
*/