哔哩哔哩小助手

视频自动点赞,网页自动宽屏播放

目前为 2022-08-05 提交的版本。查看 最新版本

// ==UserScript==
// @name         哔哩哔哩小助手
// @namespace    https://gf.qytechs.cn/zh-CN/scripts/424638
// @homepage     https://gf.qytechs.cn/zh-CN/scripts/424638
// @version      0.8
// @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.8 适配新版播放界面,不兼容老版播放界面,添加根据观看时长定时点赞功能
// v0.7 修复按下enter键无法搜索的bug,增加视频窗口居中功能
// v0.6 增加按下enter键全屏功能
// v0.5 优化逻辑,新增点赞按钮
// v0.4 修复bug
// v0.3 增加番剧、综艺宽屏,优化逻辑
// v0.2 新增自动调节页面至合适位置
// v0.1 自动点击宽屏、点赞按钮,点赞默认为关闭


(function () {

    function tool_1() {
        // widescreenFunction = true 打开自动宽屏 widescreenFunction = false 关闭自动宽屏
        // likeFunction = true 打开自动点赞 likeFunction = false 关闭自动点赞
        const widescreenFunction = true
        const likeFunction = true

        if (widescreenFunction) {
            let widescreen_id = setInterval(function () {
                // bpx-player-ctrl-wide宽屏按钮className
                let widescreen = document.querySelector('.bpx-player-ctrl-wide')
                // let widescreen_two = document.querySelector('.squirtle-video-widescreen')


                // 自动点击宽屏按钮函数
                if (widescreen) {
                    // 宽屏状态存在bpx-state-entered
                    if (widescreen.className.includes('bpx-state-entered') === false) {
                        widescreen.click()
                        clearInterval(widescreen_id)
                    }
                }
            }, 3000)
        }

        // 延时计数
        let count = 0
        if (likeFunction) {

            let like_id = setInterval(function () {
                // 定位点赞按钮
                let toolbar_left = document.querySelector('.toolbar-left')
                let like = toolbar_left.querySelector(".like")
                if (like === null) {
                    console.log('未找到点赞button!')
                } else if (like.className.includes('on') === false && count == 0) {
                    // count==1 为20s count==2 为30s 以此类推
                    like.click()
                    like.className = 'like on'
                    // 同时修改屏幕右侧按钮
                    let like_button = document.querySelector('.diy_tool')
                    let img = like_button.children[0]
                    img.style.color = '#479fd1'
                    clearInterval(like_id)

                } else {
                    console.log('当前视频已经点赞')
                    // clearInterval(like_id)
                }
                count = count + 1
            }, 10000)
        }
    }

    // 点赞按钮
    function tool_2() {
        let body = document.getElementsByTagName('body')[0]
        let ops = document.querySelector('.toolbar-left')
        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()
            }
        }
    }

    // 按下enter键进出全屏
    function tool_3() {
        window.addEventListener('keydown', (e) => {

            get_focus = document.activeElement

            if (e.key == "Enter") {
                // 判断是否是在搜索框
                if (get_focus.className.includes('nav-search-input') == false) {
                    let fullscreen_btn = document.querySelector('.bpx-player-ctrl-full')
                    fullscreen_btn.click()
                }
            }


        })
    }
    // 指定位置按钮
    function tool_4() {
        let body = document.getElementsByTagName('body')[0]
        let ops = document.querySelector('.left-container')
        $(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, 65)

        }

    }
    tool_1() // 自动宽屏
    scrollTo(0, 90)
    tool_2() // 点赞按钮
    tool_3() // 按下enter键进出全屏
    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()
    })
})()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址