b站首页视频列数调整

修改b站首页视频列表的列数吗,并移除大图

  1. // ==UserScript==
  2. // @name b站首页视频列数调整
  3. // @namespace http://tampermonkey.net/
  4. // @license MIT
  5. // @version 0.1.1
  6. // @author byhgz
  7. // @description 修改b站首页视频列表的列数吗,并移除大图
  8. // @icon https://static.hdslb.com/images/favicon.ico
  9. // @noframes
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM_addStyle
  13. // @grant GM_registerMenuCommand
  14. // @match https://www.bilibili.com/
  15. // @match https://www.bilibili.com/?spm_id_from=333.337.0.0
  16. // @require https://greasyfork.org/scripts/462234-message/code/Message.js?version=1170653
  17. // ==/UserScript==
  18. "use strict";
  19.  
  20. const Util = {
  21. //设置数据
  22. setData(key, content) {
  23. GM_setValue(key, content);
  24. },
  25. //读取数据
  26. getData(key, defaultValue) {
  27. return GM_getValue(key, defaultValue);
  28. },
  29. //删除数据
  30. delData(key) {
  31. if (!this.isData(key)) {
  32. return false;
  33. }
  34. GM_deleteValue(key);
  35. return true;
  36. },
  37. isData(key) {//判断数据是否存在
  38. return this.getData(key) !== undefined;
  39. },
  40. addStyle(style){
  41. GM_addStyle(style);
  42. },
  43. /**
  44. *注册一个菜单并返回菜单id,可在插件中点击油猴时看到对应脚本的菜单
  45. * @param {string}text 显示文本
  46. * @param {function}func 事件
  47. * @param {string}shortcutKey 快捷键
  48. * @return menu 菜单id
  49. */
  50. addGMMenu(text, func, shortcutKey = null) {
  51. return GM_registerMenuCommand(text, func, shortcutKey);
  52. },
  53. }
  54.  
  55.  
  56. const Tip={
  57. success(text, config) {
  58. Qmsg.success(text, config);
  59. },
  60. successBottomRight(text) {
  61. this.success(text, {position: "bottomright"});
  62. },
  63. }
  64.  
  65. // 这里是项目主文件,请在这里编写代码同样这也是最后执行的JS文件;
  66. "use strict";//设置严格模式,可以避免一些潜在的错误,不需要可以删除该行
  67.  
  68. //作者b站账号:https://space.bilibili.com/473239155
  69. const bili_url = "https://space.bilibili.com/473239155";
  70.  
  71. const defVideoListColumn = 6;
  72.  
  73. const i1 = setInterval(() => {
  74. const els = document.querySelectorAll(".feed-card");
  75. if (els.length === 0) return;
  76. clearInterval(i1);
  77. Util.addStyle(`@media (min-width: 1560px) and (max-width: 2059.9px) {
  78. .recommended-container_floor-aside .container > *:nth-of-type(n + 8) {
  79. margin-top: 0 !important;
  80. }
  81. }`);
  82. const msg = "已移除首页推荐视频区域中的顶部空白";
  83. console.log(msg);
  84. Tip.successBottomRight(msg);
  85. }, 500);
  86.  
  87. const videoListColumn = Util.getData("videoListColumn", defVideoListColumn);
  88.  
  89. const i2 = setInterval(() => {
  90. const el = document.querySelector(".recommended-container_floor-aside .container");
  91. if (el === null) return;
  92. clearInterval(i2);
  93. Util.addStyle(`@media (min-width: 1560px) and (max-width: 2059.9px) and (min-width: 1560px) and (max-width: 2059.9px) {
  94. .recommended-container_floor-aside .container {
  95. grid-column: span 5;
  96. grid-template-columns: repeat(${videoListColumn}, 1fr) !important;
  97. }
  98. }
  99. `);
  100. }, 1000);
  101.  
  102. const i4 = setInterval(() => {
  103. const el = document.querySelector(".bili-feed4-layout");
  104. if (el === null) return;
  105. clearInterval(i4);
  106. Util.addStyle(`.bili-feed4-layout {
  107. padding-bottom: 100px;
  108. }`);
  109. const msg = "已调整视频列表底部距离";
  110. console.log(msg);
  111. Tip.successBottomRight(msg);
  112. }, 1000);
  113.  
  114.  
  115. Util.addGMMenu("设置列数", () => {
  116. let input = prompt("请输入视频列表列数,范围2-13,默认为" + defVideoListColumn, defVideoListColumn.toString());
  117. if (input === null) return;
  118. input = input.trim();
  119. if (isNaN(input)) {
  120. return alert("请输入数字!");
  121. }
  122. input = Number.parseInt(input);
  123. if (input < 2 || input > 13) {
  124. return alert("请输入2-13之间的整数!");
  125. }
  126. Util.setData("videoListColumn", input);
  127. alert(`已将视频列表列数设置为${input}!\n刷新页面生效。\n如不生效,请反馈给作者。`);
  128. });
  129.  
  130.  
  131. Util.addGMMenu("查看设置的列数", () => {
  132. const videoListColumn = Util.getData("videoListColumn", defVideoListColumn);
  133. alert(`当前脚本视频列表列数为${videoListColumn}!\n如不生效,请刷新页面。再不行,请反馈给作者。`);
  134. });
  135.  
  136. Util.addGMMenu("反馈作者", () => {
  137. window.open(bili_url, "_blank");
  138. });