bilibili auto triple

b站50%自动三连

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         bilibili auto triple
// @namespace    http://tampermonkey.net/
// @version      0.4
// @author       cjq
// @match        https://www.bilibili.com/video/*
// @grant        none
// @run-at       document-end
// @description  b站50%自动三连
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    let videoDom, timeLine
    const getInfo= () =>{
        const urlNormal = location.pathname.split("/")[2]
        //const videoAV = urlNormal.startsWith("av") && urlNormal.replace("av", "")
        const videoAV = window.aid;
        let value = "; " + document.cookie;
        let parts = value.split("; bili_jct=");
        if (parts.length === 2 && videoAV){
            return {userId:parts.pop().split(";").shift(), av:videoAV};
        } else{
            return false
        }
    }

    const autoFunc= e =>{
        const {currentTime} = e.target
        if(currentTime >= timeLine * 0.5){
            console.log("like")
            videoDom.removeEventListener("timeupdate", autoFunc)
            let xhr = new XMLHttpRequest();
            xhr.open("POST", 'https://api.bilibili.com/x/web-interface/archive/like/triple', true);
            xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
            xhr.withCredentials = true
            if(getInfo()){
                console.log(getInfo())
                xhr.send(`aid=${getInfo().av}&csrf=${getInfo().userId}`);
                let tripleBox = [...document.querySelector(".ops").children]
                tripleBox.map((res, index)=>{
                    if(index < 3){
                        res.classList.add("on")
                    }
                })
            }
        }
    }

    const startFunc= ()=>{
        console.log("begin listen", timeLine)
        if(addEventListener){
            videoDom.addEventListener("timeupdate", autoFunc)
        }

    }
    window.onload = ()=>{}

    console.log("auto triple on~")

    var timerId=setInterval(function(){
        videoDom=document.querySelector("video");
        console.log(videoDom);
        if(videoDom!=undefined && videoDom!=''){
            //setTimeout(startFunc, timeLine * 400)
            timeLine = videoDom.duration
            startFunc();
            clearInterval(timerId);
        }
    },500);


})();