首页
课程
圈子
文章
交流群
文档
工具
vscode代码片段
字幕提取
图片切割
登录
首页
课程
圈子
文章
交流群
文档
工具
vscode代码片段
字幕提取
图片切割
案例代码:用油猴脚本统计b站课堂课程总时长
2024-11-12 09:56:14
985
0
1
0
登录后可以对文章进行评论
文章目录
开通会员
解锁全部文章权限
立即开通
小程序码
扫一扫在小程序看此文章
热门文章
php基础入门课程资料文档课件实战源码
5947
vscode里如果出现中文空格标出黄色突出显示,怎么去掉?
5552
wordpress主题开发文档资料下载
5294
2025新版fastadmin新手小白入门课 免费文档
5163
vscode插件code runner详细配置说明
4102
php进阶课程文档资料下载
3999
使用ffmpeg将mp4格式转为m3u8
2761
phpstudy怎么手动安装php8.3.0版本?
2532
推荐2款mac电脑里非常好用的php集成开发环境
2436
把php加入系统环境变量
2279
此脚本代码可以直接使用,测试地址可以使用这个: https://www.bilibili.com/cheese/play/ss25045 实际效果如图所示:  油猴脚本源码: ```js // ==UserScript== // @name 自动统计B站课堂总时长 // @namespace http://tampermonkey.net/ // @version 2024-11-11 // @description try to take over the world! // @author 猫叔 // @match https://www.bilibili.com/cheese/play/* // @require https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js // @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com // @grant none // ==/UserScript== (function() { 'use strict'; $(function(){ console.log('脚本已加载 B'); // 将时间字符串转换为秒数 function convertToSeconds(timeString) { const regex = /(\d+分)?(\d+秒)?/; const match = timeString.match(regex); if (!match) { throw new Error('Invalid time format'); } const minutes = match[1] ? parseInt(match[1].replace('分', ''), 10) : 0; const seconds = match[2] ? parseInt(match[2].replace('秒', ''), 10) : 0; return minutes * 60 + seconds; } // 将秒数转换为时:分:秒格式 function convertToTimeFormat(seconds) { const hours = Math.floor(seconds / 3600); const minutes = Math.floor((seconds % 3600) / 60); const remainingSeconds = seconds % 60; return [ hours.toString().padStart(2, '0'), minutes.toString().padStart(2, '0'), remainingSeconds.toString().padStart(2, '0') ].join(':'); } let maxNum = 10; let timer = setInterval(() => { maxNum -= 1; if ($('.section-item').length > 0 || maxNum <= 0) { clearInterval(timer); let secondTotal = 0; $('.section-item').each(function(index, element) { const $element = $(element); const times = $element.find('div.season-info.flex-align-center > div.info.subtitle.flex-align-center > p').text(); console.log(times); const seconds = convertToSeconds(times); secondTotal += seconds; }); console.log('总时长: ', convertToTimeFormat(secondTotal)); // 在 class 为 edu-play-right 的元素顶部插入一个 div 元素 const totalTimeDiv = `
总时长: ${convertToTimeFormat(secondTotal)}
`; $('.edu-play-right').prepend(totalTimeDiv); } }, 1000); }) })(); ```
1
0
铜牌 · 会员
解锁全部文章
全部课程8折购买
如果在b站充值了专属会员,可联系猫叔直接开通相同时间的此会员
¥
50
/年
立即购买
金牌 · 会员
解锁全部文章
全部课程5折购买
微信一对一答疑
优先解决问题
¥
1999
/年
立即购买