bilibili 首页刷新可选择上一个

在b站首页刷一刷按钮上添加上一个下一个按钮以此来回到上一个想看的视频

  1. // ==UserScript==
  2. // @name bilibili 首页刷新可选择上一个
  3. // @namespace https://fybgame.top/
  4. // @version 1.01
  5. // @description 在b站首页刷一刷按钮上添加上一个下一个按钮以此来回到上一个想看的视频
  6. // @author fyb
  7. // @match https://www.bilibili.com/
  8. // @match https://www.bilibili.com/?*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.  
  15. window.onload = function (){
  16. let videoArray = []
  17. let videos = document.getElementsByClassName('feed-card');
  18. let itemArray = []
  19. for(let i = 0 ; i < videos.length ; i ++){
  20. itemArray.push(videos[i].cloneNode(true))
  21. }
  22. videoArray.push(itemArray)
  23. let nowIndex = 0
  24. let toAppendLast = document.createElement("BUTTON");
  25. let spanTextLast = document.createElement("span");
  26. spanTextLast.innerHTML = '上一个';
  27. toAppendLast.addEventListener("click", function () {
  28. if(nowIndex != 0){
  29. nowIndex -- ;
  30. nowCountText.innerHTML = (nowIndex+1)+'/'+videoArray.length
  31. for(let i = 0 ; i < videos.length ; i ++){
  32. videos[i].innerHTML = videoArray[nowIndex][i].innerHTML;
  33. }
  34. }
  35.  
  36. })
  37. toAppendLast.className = 'primary-btn roll-btn';
  38. toAppendLast.style.marginBottom = "8px"
  39. toAppendLast.appendChild(spanTextLast);
  40.  
  41. let toAppendNext = document.createElement("BUTTON");
  42. let spanTextNext = document.createElement("span");
  43. spanTextNext.innerHTML = '下一个';
  44. toAppendNext.addEventListener("click", function () {
  45. if(nowIndex < videoArray.length -1){
  46. nowIndex ++ ;
  47. nowCountText.innerHTML = (nowIndex+1)+'/'+videoArray.length
  48. for(let i = 0 ; i < videos.length ; i ++){
  49. videos[i].innerHTML = videoArray[nowIndex][i].innerHTML;
  50. }
  51. }
  52.  
  53. })
  54. toAppendNext.className = 'primary-btn roll-btn';
  55. toAppendNext.style.marginBottom = "8px"
  56. toAppendNext.appendChild(spanTextNext);
  57.  
  58.  
  59.  
  60. var nowCount = document.createElement("BUTTON");
  61. var nowCountText = document.createElement("span");
  62. nowCountText.innerHTML = '1/1';
  63. nowCount.className = 'primary-btn roll-btn';
  64. nowCount.style.marginBottom = "8px"
  65. nowCount.appendChild(nowCountText);
  66.  
  67.  
  68. let c = document.getElementsByClassName('feed-roll-btn')[0];
  69. c.children[0].removeChild(c.children[0].children[0]);
  70. c.children[0].children[0].innerHTML = '刷新下';
  71.  
  72. c.children[0].addEventListener("click", function () {
  73.  
  74. setTimeout(function (){
  75. let itemArray = []
  76. for(let i = 0 ; i < videos.length ; i ++){
  77. itemArray.push(videos[i].cloneNode(true))
  78. }
  79. videoArray.push(itemArray)
  80. nowIndex = videoArray.length-1;
  81. nowCountText.innerHTML = (nowIndex+1)+'/'+videoArray.length
  82. },500)
  83.  
  84. })
  85.  
  86. c.insertBefore(toAppendNext,c.children[0])
  87. c.insertBefore(nowCount,c.children[0])
  88. c.insertBefore(toAppendLast,c.children[0])
  89.  
  90. }
  91.  
  92. })();