b站多P视频进度计算

计算多P视频已观看部分总进度

  1. // ==UserScript==
  2. // @name b站多P视频进度计算
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description 计算多P视频已观看部分总进度
  6. // @author ElZhao
  7. // @match https://www.bilibili.com/video/*
  8. // @icon https://www.google.com/s2/favicons?domain=bilibili.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. function hmsToSecondsOnly(str) {
  16. var p = str.split(':'),
  17. s = 0, m = 1;
  18. while (p.length > 0) {
  19. s += m * parseInt(p.pop(), 10);
  20. m *= 60;
  21. }
  22. return s;
  23. }
  24. setTimeout(() => {
  25. var counter = 0;
  26. var myTimer = setInterval(() => {
  27. ++counter;
  28. let total_time = 0;
  29. let current_time = 0;
  30. for (let node of document.querySelectorAll('div#multi_page div.cur-list ul li')) {
  31. if (node.getAttribute('class') == 'watched on' || node.getAttribute('class') == 'on') {
  32. current_time = total_time;
  33. }
  34. total_time += hmsToSecondsOnly(node.querySelector('div.duration').textContent);
  35. }
  36. if (total_time == 0 && counter >= 5) {
  37. clearInterval(myTimer);
  38. }
  39. let watch_progress = current_time / total_time;
  40. let data = document.querySelector('div.video-data');
  41. let node = data.querySelector('span#progress ');
  42. let texts = '播放总进度:' + (current_time / 60).toFixed(0) + 'min' + ' / ' + (total_time / 60).toFixed(0) + 'min' + ' ( ' + (watch_progress * 100).toFixed(2) + '%' + ' )';
  43. if (!isNaN(watch_progress)) {
  44. if (node == null) {
  45. var span = document.createElement("span");
  46. span.id = 'progress'
  47. span.textContent = texts;
  48. data.innerHTML += '   '
  49. data.appendChild(span);
  50. } else {
  51. node.textContent = texts
  52. }
  53. }
  54. }, 2000)
  55. }, 1000)
  56. })();

QingJ © 2025

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