Greasy Fork

Greasy Fork is available in English.

哔哩哔哩小助手

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

当前为 2022-02-10 提交的版本,查看 最新版本

// ==UserScript==
// @name         哔哩哔哩小助手
// @namespace    http://greasyfork.icu/zh-CN/scripts/424638
// @version      0.5
// @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.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: ${color}
    }
    .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()
            }
        }
    }
    tool_1()
    tool_2()
    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()
        tool_2()
    })



})()