🏠 返回首頁 

Greasy Fork is available in English.

Bilibili UP主更新周期显示

尝试找出真正高产的优秀up主!


安装此脚本?
  1. // ==UserScript==
  2. // @name Bilibili UP主更新周期显示
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description 尝试找出真正高产的优秀up主!
  6. // @author 卧波云龙
  7. // @match *://space.bilibili.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
  9. // @grant GM_addStyle
  10. // @license MIT
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14. function processVideoItems(){
  15. // 查找ID为page-video的div元素
  16. const videoPageContainer = document.getElementById('page-video');
  17. // 确保找到了ID为page-video的元素
  18. if (videoPageContainer) {
  19. // 在ID为page-video的元素内部查找所有的视频项
  20. const videoItems = videoPageContainer.querySelectorAll('.small-item.fakeDanmu-item');
  21. console.log(`找到的视频项数量: ${videoItems.length}`);
  22. if (videoItems.length === 0) {
  23. console.warn('在指定的容器内没有找到视频项,检查选择器或页面结构是否正确。');
  24. } else {
  25. let videosDate = []; // 用于存储视频发布日期
  26. // 转换字符串日期为日期对象
  27. /* videoItems.forEach((item, index) => {
  28. const timeSpan = item.querySelector('span.time');
  29. if (timeSpan) {
  30. const dateStr = timeSpan.textContent.trim(); // 移除字符串两端的空白字符
  31. // 正则表达式匹配提供的日期格式
  32. const dateRegex = /^(?:(\d{4})-)?(\d{1,2})-(\d{1,2})$/;
  33. const match = dateStr.match(dateRegex);
  34. if (match) {
  35. let year, month, day;
  36. // 如果日期字符串中包含年份
  37. if (match[1]) {
  38. year = match[1];
  39. } else {
  40. // 如果没有年份,使用当前年份
  41. year = new Date().getFullYear();
  42. }
  43. // 月份和日期,确保是两位数
  44. month = String(match[2]).padStart(2, '0');
  45. day = String(match[3]).padStart(2, '0');
  46. // 构建完整的日期字符串
  47. const fullDateStr = `${year}-${month}-${day}`;
  48. // 使用构建的日期字符串创建Date对象
  49. const releaseDate = new Date(fullDateStr);
  50. const sixMonthsAgo = new Date();
  51. sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
  52. if (releaseDate >= sixMonthsAgo && !isNaN(releaseDate.getTime())) {
  53. videosDate.push(releaseDate);
  54. }
  55. }
  56. else
  57. {
  58. console.warn('日期转化失败:',dateStr);
  59. }
  60. }
  61. }); */
  62. // 转换字符串日期为日期对象
  63. videoItems.forEach((item, index) => {
  64. const timeSpan = item.querySelector('span.time');
  65. if (timeSpan) {
  66. const dateStr = timeSpan.textContent.trim();
  67. // 正则表达式匹配提供的日期格式或包含"分钟"、"小时"、"昨天"的字符串
  68. const dateRegex = /^(?:(\d{4})-)?(\d{1,2})-(\d{1,2})$/;
  69. const recentRegex = /分钟|小时|昨天/;
  70. let releaseDate;
  71. if (dateStr.match(recentRegex)) {
  72. // 如果包含"分钟"、"小时"、"昨天",则使用当前日期
  73. releaseDate = new Date();
  74. } else {
  75. const match = dateStr.match(dateRegex);
  76. if (match) {
  77. let year, month, day;
  78. if (match[1]) {
  79. year = match[1];
  80. } else {
  81. year = new Date().getFullYear();
  82. }
  83. month = String(match[2]).padStart(2, '0');
  84. day = String(match[3]).padStart(2, '0');
  85. const fullDateStr = `${year}-${month}-${day}`;
  86. releaseDate = new Date(fullDateStr);
  87. }
  88. }
  89. if (releaseDate && !isNaN(releaseDate.getTime())) {
  90. const sixMonthsAgo = new Date();
  91. sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
  92. if (releaseDate >= sixMonthsAgo) {
  93. videosDate.push(releaseDate);
  94. }
  95. } else {
  96. console.warn('日期转化失败:', dateStr);
  97. }
  98. }
  99. });
  100. // 确保至少有两个日期数据以进行计算
  101. if (videosDate.length >= 2) {
  102. // 将日期对象转换为时间戳
  103. const dates = videosDate.map(date => date.getTime());
  104. // 计算第一个和最后一个日期之间的天数差
  105. const diffInDays = (dates[0] - dates[dates.length - 1]) / (1000 * 60 * 60 * 24);
  106. // 计算平均更新周期,结果为平均多少天更新一次视频
  107. const averageUpdatePeriod = diffInDays / videosDate.length;
  108. // 保留一位小数
  109. const averageUpdatePeriodRounded = averageUpdatePeriod.toFixed(1);
  110. if (0 <= averageUpdatePeriod &&averageUpdatePeriod <= 1) {
  111. displayR###lt("发现更新狂魔一枚");
  112. } else {
  113. displayR###lt(`平均更新周期: ${averageUpdatePeriodRounded} 天`);
  114. }
  115. console.log('脚本加载完成');
  116. }
  117. else {
  118. displayR###lt('视频数量不足以计算平均更新周期');
  119. }
  120. }
  121. } else {
  122. console.warn('未找到ID为page-video的元素,请检查页面结构是否正确。');
  123. }
  124. }
  125. function displayR###lt(message) {
  126. const targetElement = document.querySelector('h4.h-sign');
  127. if (targetElement) {
  128. targetElement.textContent += ` | ${message}`;
  129. } else {
  130. console.warn('未找到h4.h-sign元素,无法显示结果。');
  131. }
  132. }
  133. function setupObserver() {
  134. const observer = new MutationObserver((mutations, obs) => {
  135. const videoPageContainer = document.getElementById('page-video');
  136. if (videoPageContainer) {
  137. processVideoItems();
  138. obs.disconnect();
  139. }
  140. });
  141. observer.observe(document.body, {
  142. childList: true,
  143. subtree: true
  144. });
  145. }
  146. window.addEventListener('load', setupObserver);
  147. })();