哔哩哔哩小助手
// ==UserScript==
// @name 哔哩哔哩小助手
// @namespace https://greasyfork.org/zh-CN/scripts/424638
// @homepage https://greasyfork.org/zh-CN/scripts/424638
// @version 0.7
// @description 视频自动点赞,网页自动宽屏播放
// @author 木羊羽
// @match https://www.bilibili.com/video/*
// @match https://www.bilibili.com/bangumi/play/*
// @run-at document-end
// @grant none
// @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js
// @license GPL-3.0 License
// ==/UserScript==
// 更新日志
// v0.7 修复按下enter键无法搜索的bug,增加视频窗口居中功能
// v0.6 增加按下enter键全屏功能
// v0.5 优化逻辑,新增点赞按钮
// v0.4 修复bug
// v0.3 增加番剧、综艺宽屏,优化逻辑
// v0.2 新增自动调节页面至合适位置
// v0.1 自动点击宽屏、点赞按钮,点赞默认为关闭
(function () {
function tool_1() {
const widescreenFunction = true
const likeFunction = false
let count = 0
if (widescreenFunction) {
let widescreen_id = setInterval(function () {
let widescreen_one = document.querySelector('.bilibili-player-video-btn-widescreen')
let widescreen_two = document.querySelector('.squirtle-video-widescreen')
if (widescreen_one) {
if (widescreen_one.className.includes('closed') === false) {
widescreen_one.click()
scrollTo(0, 90)
clearInterval(widescreen_id)
}
}
if (widescreen_two) {
if (widescreen_two.className.includes('active') === false) {
widescreen_two.click()
scrollTo(0, 50)
clearInterval(widescreen_id)
}
}
}, 3000)
}
if (likeFunction) {
let like_id = setInterval(function () {
let like = document.querySelector("#arc_toolbar_report > div.ops > span.like")
if (like === null) {
console.log('未找到点赞button!')
} else if (like.className.includes('on') === false) {
like.click()
clearInterval(like_id)
} else {
console.log('当前视频已经点赞')
clearInterval(like_id)
}
}, 3000)
}
}
function tool_2() {
let body = document.getElementsByTagName('body')[0]
let ops = document.querySelector('.ops')
var color = '#757575'
if ($(ops.children[0]).attr('class') == 'like on') {
color = '#479fd1'
}
$(body).after(
`
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="diy_tool">
<i class="fa fa-thumbs-up fa-3x" aria-hidden="true"></i>
</div>
<style>
.diy_tool{
position: fixed;
display: flex;
top: 200px;
left: -25px;
width: 40px;
height: 30px;
z-index: 99999;
font-size: 15px;
cursor: pointer;
align-items: center;
transition: .3s;
color: #757575;
}
.diy_tool i{
position: absolute;
margin-left: 10px;
right: 0;
}
.like_button{
margin-left: 5px;
}
.diy_tool:hover{
left: 0;
}
</style>
`
)
let like_button = document.querySelector('.diy_tool')
let img = like_button.children[0]
like_button.onclick = function () {
if ($(ops.children[0]).attr('class') === 'like on') {
img.style.color = '#757575'
$(ops.children[0]).click()
}
else {
img.style.color = '#479fd1'
$(ops.children[0]).click()
}
}
}
function tool_3() {
window.addEventListener('keydown', (e) => {
get_focus = document.activeElement
if (e.key == "Enter") {
if (get_focus.className.includes('player-mode-widescreen')) {
let fullscreen_btn = document.querySelector('.bilibili-player-video-btn-fullscreen')
fullscreen_btn.click()
}
}
})
}
function tool_4() {
let body = document.getElementsByTagName('body')[0]
let ops = document.querySelector('.ops')
$(body).after(
`
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="diy_tool_4">
<i class="fa fa-sort fa-3x" aria-hidden="true"></i>
</div>
<style>
.diy_tool_4{
position: fixed;
display: flex;
top: 150px;
left: -26px;
width: 40px;
height: 30px;
z-index: 99999;
font-size: 15px;
cursor: pointer;
align-items: center;
transition: .3s;
color: #757575;
}
.diy_tool_4 i{
position: absolute;
margin-left: 10px;
right: 0;
}
.diy_tool_4:hover{
left: 0;
}
</style>
`
)
let fixed_button = document.querySelector('.diy_tool_4')
fixed_button.onclick = function () {
scrollTo(0, 90)
}
}
tool_1()
tool_2()
tool_3()
tool_4()
var _wr = function (type) {
var orig = history[type]
return function () {
var rv = orig.apply(this, arguments)
var e = new Event(type)
e.arguments = arguments
window.dispatchEvent(e)
return rv
}
}
history.pushState = _wr('pushState')
window.addEventListener('pushState', function (e) {
tool_1()
})
})()