B站播放器显示时间

B站播放器右上角显示系统时间

目前為 2023-08-30 提交的版本,檢視 最新版本

// ==UserScript==
// @name         B站播放器显示时间
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  B站播放器右上角显示系统时间
// @author       echo
// @match           *://*.bilibili.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant        none
// @require      https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @license      CC-BY-NC-SA-4.0
// ==/UserScript==

(function() {
    'use strict';

    $(function(){
    const fontSize=21;//时间字体大小,支持修改,默认21
    let time=$(`<div class="sys-time toolbar-left-item-wrap" style="
    position: absolute;
    color: #ffffffee;
    right: 5px;
    top: 0.6px;
    font-size: ${fontSize}px;
    text-shadow: 0.3px 0.3px 3px #00000088;
    font-family: Calibri;
">00:00</div>`);
        let switcher=$(`<div class="time-switcher" style="
        text-align: center;
        font-weight: bold;
        user-select: none;
    cursor: pointer;
">Time Off</div>`);
        //播放器
       let player=$('.bpx-player-video-wrap');
        let ro=new ResizeObserver(function(r){
            updateRatio();
        });
        //初始化
        time.text(getTime());
        player.prepend(time);
        //设置时间开关
        let getBar=setInterval(()=>{
         let bar=$('.bpx-player-dm-setting');
            if(bar.length==0)return;
            clearInterval(getBar);
            bar.after(switcher);
            switcher.click(()=>{
                time.toggle(0,'swing',()=>{
                if(time.is(':hidden'))switcher.text('Time On');
                else switcher.text('Time Off');
                });

            });
        },1000);
        //设置时钟
        setTimeout(()=>{
         time.text(getTime());
        setInterval(()=>{
            time.text(getTime());
        },1000*60);},(60-new Date().getSeconds())*1000);
        //获取时间
        function getTime(){
         let date=new Date();
         let h=('0'+date.getHours()).slice(-2);
         let m=('0'+date.getMinutes()).slice(-2);
         let time=h+':'+m;
            return time;
        }
    });
})();

QingJ © 2025

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