Greasy Fork

Greasy Fork is available in English.

巴哈弹幕转 dplayer

提取巴哈的弹幕

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        巴哈弹幕转 dplayer
// @namespace   https://xmdhs.com
// @match       https://ani.gamer.com.tw/animeVideo.php?sn=*
// @version     0.0.1
// @author      xmdhs
// @description 提取巴哈的弹幕
// @grant       unsafeWindow
// @grant       GM_addStyle
// @grant       GM_setClipboard
// @license     MIT
// ==/UserScript==

(async () => {
    GM_addStyle(`.ahveuiw:after{content: "" !important;}`)

    const b = document.createElement("button")
    b.textContent = "复制 dplayer 格式弹幕"
    b.addEventListener('click', e => {
        e.preventDefault()
        const dm = getDm(animefun.danmu)
        const text = JSON.stringify(dm)
        GM_setClipboard(text);
    })
    b.className = "ahveuiw"

    document.querySelector(".anime_name").appendChild(b)

    function getDm(d) {
        let dm = {}
        dm.code = 0
        dm.data = []
        for (const v of d) {
            dm.data.push([
                v.time / 10,
                v.position ? v.position : 0,
                color2Number(v.color),
                "[Gamer]" + String(v.sn),
                v.text
            ])
        }
        return dm
    }


    function color2Number(color) {
        if (color[0] === '#') {
            color = color.substring(1)
        }
        if (color.length === 3) {
            color = `${color[0]}${color[0]}${color[1]}${color[1]}${color[2]}${color[2]}`;
        }
        return (parseInt(color, 16) + 0x000000) & 0xffffff;
    }
})()