A-soul视频分区插件

自定义分区

目前为 2022-01-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name A-soul视频分区插件
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.4
  5. // @description 自定义分区
  6. // @author tuntun
  7. // @match https://www.bilibili.com/*
  8. // @icon https://i2.hdslb.com/bfs/face/48d65a10a2c643dddc4a51e0a60fae892393417a.jpg
  9. // @grant GM_addStyle
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. GM_addStyle(`
  18. .tuntun-setting-popover {
  19. width: 300px;
  20. // height: 200px;
  21. background-color: white;
  22. border-radius: 20px;
  23. position: absolute;
  24. left: -120px;
  25. top: 43px;
  26. box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
  27. transition: opacity 0.5s, height 0.25s;
  28. }
  29.  
  30. .tuntun-setting-none {
  31. opacity: 0;
  32. height: 0;
  33. overflow: hidden;
  34. }
  35.  
  36. .tuntun-setting-form {
  37. padding: 15px;
  38. display: flex;
  39. flex-direction: column;
  40. justify-content: center;
  41. }
  42.  
  43. .tuntun-setting-btn {
  44. margin: 0 auto;
  45. width: 84px;
  46. height: 38px;
  47. background-color:#b8a6d9;
  48. border: none;
  49. border-radius:10px;
  50. display:inline-block;
  51. cursor:pointer;
  52. color:#ffffff;
  53. font-family:Arial;
  54. font-size:17px;
  55. text-decoration:none;
  56. text-shadow:0px 0px 0px #9752cc;
  57. }
  58. .tuntun-setting-btn:hover {
  59. background-color:#bc80ea;
  60. }
  61. .tuntun-setting-btn:active {
  62. position:relative;
  63. top:1px;
  64. }
  65.  
  66. .tuntun-setting-input {
  67. margin-bottom: 15px;
  68. display: flex;
  69. align-items: center;
  70. }
  71.  
  72. .tuntun-setting-input div {
  73. margin-right: 10px
  74. }
  75.  
  76. .tuntun-setting-input input,select{
  77. width: 200px;
  78. border: 1px solid #ccc;
  79. padding: 7px 0px;
  80. border-radius: 3px;
  81. padding-left: 5px;
  82. transition: border 0.25s
  83. }
  84.  
  85. .tuntun-setting-input input:focus{
  86. outline: none;
  87. border: 1px solid #B8A6D9;
  88. }
  89.  
  90. .tuntun-setting-input select:focus{
  91. outline: none;
  92. border: 1px solid #B8A6D9;
  93. }
  94. .tuntun-setting-imgRadius {
  95. padding-left: 0px !important;
  96. }
  97. `);
  98.  
  99. const getTemplete = (videoKey, imgUrl = '') => {
  100. return `
  101. <section class="bili-grid">
  102. <div class="video-card-list is-main">
  103. <div class="area-header" style="z-index: 1000;">
  104. <div class="left tuntun-part-left">
  105. <a id="A-soul分区" class="the-world area-anchor" data-id="8"></a>
  106. <img class="icon tuntun-part-img" src="${imgUrl}"></img>
  107. <a
  108. class="title"
  109. href="https://search.bilibili.com/all?keyword=${videoKey}"
  110. target="_blank"
  111. >
  112. <span>${videoKey}分区</span>
  113. </a>
  114. </div>
  115. <div class="right" style="position: relative;">
  116. <div id="tuntun-setting" style="position: relative;">
  117. <button class="primary-btn roll-btn">
  118. <span>设置</span></button
  119. >
  120. <div
  121. class="tuntun-setting-popover tuntun-setting-none"
  122. >
  123. <form class="tuntun-setting-form">
  124. <div class="tuntun-setting-input">
  125. <div>分区名称:</div>
  126. <input type="text" name="name" />
  127. </div>
  128. <div class="tuntun-setting-input">
  129. <div>分区图片:</div>
  130. <input type="text" name="picUrl" />
  131. </div>
  132. <div class="tuntun-setting-input">
  133. <div>图片圆角:</div>
  134. <input class="tuntun-setting-imgRadius" type="range" min="0" max="50"/>
  135. </div>
  136. <div class="tuntun-setting-input">
  137. <div>时间范围:</div>
  138. <select name="timeRange" id="">
  139. <option value="7">一周之内</option>
  140. <option value="30" selected>一月之内</option>
  141. <option value="90">三个月之内</option>
  142. <option value="0">不限时间</option>
  143. </select>
  144. </div>
  145. <input class="tuntun-setting-btn" type="submit" value="确认" />
  146. </form>
  147. </div>
  148. </div>
  149. <button id="refreshVideo" class="primary-btn roll-btn">
  150. <svg style="transform: rotate(0deg)">
  151. <use xlink:href="#widget-roll"></use></svg><span>换一换</span></button
  152. >
  153. <a
  154. class="primary-btn see-more tuntun-see-more"
  155. href="https://search.bilibili.com/all?keyword=${videoKey}"
  156. target="_blank"
  157. ><span>查看更多</span><svg><use xlink:href="#widget-arrow"></use></svg></a>
  158. </div>
  159. </div>
  160. <div class="video-card-body">
  161. </div>
  162. </div>
  163. <aside>
  164. <div class="aside-wrap">
  165. <div class="aside-head">
  166. <div class="area-header">
  167. <div class="left">
  168. <!----><!----><a
  169. class="title rank-title"
  170. href="https://www.bilibili.com/v/virtual"
  171. target="_blank"
  172. ><span>排行榜</span></a>
  173. </div>
  174. <div class="right">
  175. <a
  176. class="primary-btn see-more"
  177. href="https://www.bilibili.com/v/virtual"
  178. target="_blank"
  179. ><span>更多</span><svg><use xlink:href="#widget-arrow"></use></svg></a>
  180. </div>
  181. </div>
  182. </div>
  183. </div>
  184. </aside>
  185. </section>
  186. `;
  187. };
  188.  
  189. let asideBody = `
  190. <div class="aside-body">
  191. <div class="aside-core">
  192. <div class="bili-rank-list-video bili-rank-list-video__grid">
  193. <ul class="bili-rank-list-video__list video-rank-list">
  194. <li class="bili-rank-list-video__item">
  195. <div class="bili-rank-list-video__item--wrap">
  196. <span class="bili-rank-list-video__item--index" data-index="1"
  197. >1</span
  198. ><a
  199. href="//www.bilibili.com/video/BV1Hi4y1R7gy"
  200. class="rank-video-card"
  201. target="_blank"
  202. data-mod="partition_rank"
  203. data-idx="content"
  204. data-ext="click"
  205. ><div class="rank-video-card__image">
  206. <picture class="v-img rank-video-card__cover"
  207. ><!---->
  208. <source
  209. srcset="
  210. //i2.hdslb.com/bfs/archive/c92ce434742fb724af5577de2485a1eaff8aa226.jpg@192w_108h_1c_100q.webp
  211. "
  212. type="image/webp" />
  213. <img
  214. src="//i2.hdslb.com/bfs/archive/c92ce434742fb724af5577de2485a1eaff8aa226.jpg@192w_108h_1c_100q"
  215. alt="B站以前的LV6 VS 现在的LV6 2.0"
  216. loading="lazy"
  217. onload=""
  218. /></picture>
  219. </div>
  220. <div class="rank-video-card__info">
  221. <h3
  222. class="rank-video-card__info--tit"
  223. title="B站以前的LV6 VS 现在的LV6 2.0"
  224. >
  225. B站以前的LV6 VS 现在的LV6 2.0
  226. </h3>
  227. </div></a
  228. >
  229. </div>
  230. </li>
  231. <li class="bili-rank-list-video__item">
  232. <div class="bili-rank-list-video__item--wrap">
  233. <span class="bili-rank-list-video__item--index" data-index="2"
  234. >2</span
  235. ><a
  236. href="//www.bilibili.com/video/BV1Rb4y1Y7Pw"
  237. class="rank-video-card rank-video-card__concise"
  238. target="_blank"
  239. data-mod="partition_rank"
  240. data-idx="content"
  241. data-ext="click"
  242. ><!---->
  243. <div class="rank-video-card__info">
  244. <h3
  245. class="rank-video-card__info--tit"
  246. title="【自制动画】《鬼灭之刃》无限城篇(香奈乎单挑童磨 片段)"
  247. >
  248. 【自制动画】《鬼灭之刃》无限城篇(香奈乎单挑童磨 片段)
  249. </h3>
  250. </div></a
  251. >
  252. </div>
  253. </li>
  254. <li class="bili-rank-list-video__item">
  255. <div class="bili-rank-list-video__item--wrap">
  256. <span class="bili-rank-list-video__item--index" data-index="3"
  257. >3</span
  258. ><a
  259. href="//www.bilibili.com/video/BV1Z44y177Wt"
  260. class="rank-video-card rank-video-card__concise"
  261. target="_blank"
  262. data-mod="partition_rank"
  263. data-idx="content"
  264. data-ext="click"
  265. ><!---->
  266. <div class="rank-video-card__info">
  267. <h3
  268. class="rank-video-card__info--tit"
  269. title="小伙买了80个模型,爆肝一周,只为在家建造一个迷你世界"
  270. >
  271. 小伙买了80个模型,爆肝一周,只为在家建造一个迷你世界
  272. </h3>
  273. </div></a
  274. >
  275. </div>
  276. </li>
  277. <li class="bili-rank-list-video__item">
  278. <div class="bili-rank-list-video__item--wrap">
  279. <span class="bili-rank-list-video__item--index" data-index="4"
  280. >4</span
  281. ><a
  282. href="//www.bilibili.com/video/BV1mi4y1R7rT"
  283. class="rank-video-card rank-video-card__concise"
  284. target="_blank"
  285. data-mod="partition_rank"
  286. data-idx="content"
  287. data-ext="click"
  288. ><!---->
  289. <div class="rank-video-card__info">
  290. <h3
  291. class="rank-video-card__info--tit"
  292. title="准备好了么?来点刺激的!!!【嘉然】"
  293. >
  294. 准备好了么?来点刺激的!!!【嘉然】
  295. </h3>
  296. </div></a
  297. >
  298. </div>
  299. </li>
  300. <li class="bili-rank-list-video__item">
  301. <div class="bili-rank-list-video__item--wrap">
  302. <span class="bili-rank-list-video__item--index" data-index="5"
  303. >5</span
  304. ><a
  305. href="//www.bilibili.com/video/BV1VD4y1c788"
  306. class="rank-video-card rank-video-card__concise"
  307. target="_blank"
  308. data-mod="partition_rank"
  309. data-idx="content"
  310. data-ext="click"
  311. ><!---->
  312. <div class="rank-video-card__info">
  313. <h3
  314. class="rank-video-card__info--tit"
  315. title="顶上海鲜战争12分钟总集篇"
  316. >
  317. 顶上海鲜战争12分钟总集篇
  318. </h3>
  319. </div></a
  320. >
  321. </div>
  322. <!---->
  323. </li>
  324. <li class="bili-rank-list-video__item">
  325. <div class="bili-rank-list-video__item--wrap">
  326. <span class="bili-rank-list-video__item--index" data-index="6"
  327. >6</span
  328. ><a
  329. href="//www.bilibili.com/video/BV14r4y1S71X"
  330. class="rank-video-card rank-video-card__concise"
  331. target="_blank"
  332. data-mod="partition_rank"
  333. data-idx="content"
  334. data-ext="click"
  335. ><!---->
  336. <div class="rank-video-card__info">
  337. <h3
  338. class="rank-video-card__info--tit"
  339. title="【原神手书】荒泷一斗 【Misfit Lunatic】"
  340. >
  341. 【原神手书】荒泷一斗 Misfit Lunatic
  342. </h3>
  343. </div></a
  344. >
  345. </div>
  346. <!---->
  347. </li>
  348. <li class="bili-rank-list-video__item">
  349. <div class="bili-rank-list-video__item--wrap">
  350. <span class="bili-rank-list-video__item--index" data-index="7"
  351. >7</span
  352. ><a
  353. href="//www.bilibili.com/video/BV1jL411L7Vm"
  354. class="rank-video-card rank-video-card__concise"
  355. target="_blank"
  356. data-mod="partition_rank"
  357. data-idx="content"
  358. data-ext="click"
  359. ><!---->
  360. <div class="rank-video-card__info">
  361. <h3
  362. class="rank-video-card__info--tit"
  363. title="【平成三萌】摇起来迎接2022~~~~~~"
  364. >
  365. 【平成三萌】摇起来迎接2022~~~~~~
  366. </h3>
  367. </div></a
  368. >
  369. </div>
  370. <!---->
  371. </li>
  372. <li class="bili-rank-list-video__item">
  373. <div class="bili-rank-list-video__item--wrap">
  374. <span class="bili-rank-list-video__item--index" data-index="8"
  375. >8</span
  376. ><a
  377. href="//www.bilibili.com/video/BV1tY411p7G5"
  378. class="rank-video-card rank-video-card__concise"
  379. target="_blank"
  380. data-mod="partition_rank"
  381. data-idx="content"
  382. data-ext="click"
  383. ><!---->
  384. <div class="rank-video-card__info">
  385. <h3
  386. class="rank-video-card__info--tit"
  387. title="你瞧瞧现在哪儿有萌新啊"
  388. >
  389. 你瞧瞧现在哪儿有萌新啊
  390. </h3>
  391. </div></a
  392. >
  393. </div>
  394. <!---->
  395. </li>
  396. <li class="bili-rank-list-video__item">
  397. <div class="bili-rank-list-video__item--wrap">
  398. <span class="bili-rank-list-video__item--index" data-index="9"
  399. >9</span
  400. ><a
  401. href="//www.bilibili.com/video/BV1ji4y1R7LL"
  402. class="rank-video-card rank-video-card__concise"
  403. target="_blank"
  404. data-mod="partition_rank"
  405. data-idx="content"
  406. data-ext="click"
  407. ><!---->
  408. <div class="rank-video-card__info">
  409. <h3
  410. class="rank-video-card__info--tit"
  411. title="女生想让男朋友知道的事有哪些?"
  412. >
  413. 女生想让男朋友知道的事有哪些?
  414. </h3>
  415. </div></a
  416. >
  417. </div>
  418. <!---->
  419. </li>
  420. <li class="bili-rank-list-video__item">
  421. <div class="bili-rank-list-video__item--wrap">
  422. <span
  423. class="bili-rank-list-video__item--index"
  424. data-index="10"
  425. >10</span
  426. ><a
  427. href="//www.bilibili.com/video/BV12L4y1E7G2"
  428. class="rank-video-card rank-video-card__concise"
  429. target="_blank"
  430. data-mod="partition_rank"
  431. data-idx="content"
  432. data-ext="click"
  433. ><!---->
  434. <div class="rank-video-card__info">
  435. <h3
  436. class="rank-video-card__info--tit"
  437. title="看到朋友脱单我比si了还难受"
  438. >
  439. 看到朋友脱单我比si了还难受
  440. </h3>
  441. </div></a
  442. >
  443. </div>
  444. <!---->
  445. </li>
  446. </ul>
  447. </div>
  448. <!----><!---->
  449. </div>
  450. </div>`
  451.  
  452. const Tool = {
  453. // 大数转万
  454. formatBigNumber: (num) => {
  455. return num > 10000 ? `${(num / 10000).toFixed(2)}万` : num
  456. },
  457. // 字符串转DOM
  458. s2d: (string) => {
  459. return new DOMParser().parseFromString(string, 'text/html').body
  460. .childNodes[0]
  461. },
  462. // 发布时间格式化
  463. diffTime: (time) => {
  464. let upDate = new Date(parseInt(time, 10) * 1000);
  465. let nowDate = new Date();
  466. let nowTime = nowDate.getTime(),
  467. upTime = upDate.getTime(),
  468. Day = 24 * 60 * 60 * 1000,
  469. Hours = 60 * 60 * 1000,
  470. Minutes = 60 * 1000,
  471. diffDay = parseInt((nowTime - upTime) / Day),
  472. diffHours = parseInt((nowTime - upTime) / Hours),
  473. diffMinutes = Math.floor((nowTime - upTime) / Minutes);
  474. if(diffDay != 0 && diffDay < 7) {
  475. if ( diffDay === 1 ) {
  476. return '昨天'
  477. }
  478. return diffDay + '天前';
  479. }
  480. else if(diffDay === 0 && diffHours != 0) {
  481. return diffHours + '小时前';
  482. }
  483. else if(diffDay === 0 && diffHours === 0 && diffMinutes != 0) {
  484. return diffMinutes + '分钟前';
  485. }
  486. else if (diffDay === 0 && diffHours === 0 && diffMinutes === 0) {
  487. return '刚刚';
  488. }
  489. else {
  490. let month = upDate.getMonth() + 1;
  491. let day = upDate.getDate();
  492. if (nowDate.getFullYear() !== upDate.getFullYear()) {
  493. return `${upDate.getFullYear()}-${month < 10 ? 0 : ''}${month}-${day < 10 ? 0 : ''}${day}`
  494. }
  495. return `${month < 10 ? 0 : ''}${month}-${day < 10 ? 0 : ''}${day}`
  496. }
  497. },
  498. // 判断发布时间与现在时间是否过长
  499. isTimeTooLate: (time, rangeDay = 30) => {
  500. let day = parseInt(rangeDay, 10);
  501. if (day === 0) {
  502. return false;
  503. }
  504. let upData = new Date(parseInt(time, 10) * 1000);
  505. let nowTime = new Date().getTime(),
  506. upTime = upData.getTime(),
  507. Day = 24 * 60 * 60 * 1000,
  508. diffDay = parseInt((nowTime - upTime) / Day);
  509. if (diffDay > day) {
  510. return true;
  511. }
  512. return false;
  513. }
  514. }
  515.  
  516. const API = {
  517. // 封装get方法
  518. Get: async (props) => {
  519. const { url: baseUrl, params = {} } = props;
  520. let pStr = Object.keys(params).map((key) => {
  521. return `${key}=${params[key]}`;
  522. }).join('&');
  523. let url = `${baseUrl}?${pStr}`;
  524. try {
  525. let res = await fetch(url, {
  526. credentials: "include"
  527. });
  528. return (await res.json()).data;
  529. } catch (error) {
  530. console.error('Get Error', error);
  531. }
  532. },
  533. // 通过关键词获取视频数据
  534. getVideo: async (keyWord, page = 1) => {
  535. try {
  536. let res = await API.Get({
  537. url: 'https://api.bilibili.com/x/web-interface/search/type',
  538. params: {
  539. search_type: 'video',
  540. keyword: keyWord,
  541. page: page,
  542. }
  543. });
  544. return res.result;
  545. } catch (error) {
  546. console.log('getVideo', error);
  547. }
  548. },
  549. }
  550. let videoList = [];
  551. let page = 1;
  552. let searchPage = 1;
  553. let bvList = [];
  554. let pageSize = 10;
  555. let videoKey = GM_getValue('videoKey', 'A-soul');
  556. let rangeDay = GM_getValue('rangeDay', '30');
  557. let imgBorderRadius = GM_getValue('imgBorderRadius', '15');
  558. let defaultImgUrl = 'https://i2.hdslb.com/bfs/face/48d65a10a2c643dddc4a51e0a60fae892393417a.jpg';
  559. let imgUrl = GM_getValue('imgUrl', defaultImgUrl);
  560.  
  561. // 获取数据并渲染
  562. const getVideoCardTemplete = (data) => {
  563. let videoCardBody = document.querySelector('.video-card-body');
  564. videoCardBody.innerHTML = '';
  565. data.forEach((item, index) => {
  566. if (index < pageSize) {
  567. const {
  568. bvid, pic, mid,
  569. upic, author, play,
  570. like, duration, pubdate } = item;
  571. let title = item.title.replace(/<em class="keyword">(.*?)<\/em>/g, '$1');
  572. let domStr = `
  573. <div class="bili-video-card">
  574. <div class="bili-video-card__skeleton hide">
  575. <div class="bili-video-card__skeleton--cover"></div>
  576. <div class="bili-video-card__skeleton--info">
  577. <div class="bili-video-card__skeleton--face"></div>
  578. <div class="bili-video-card__skeleton--right">
  579. <p class="bili-video-card__skeleton--text"></p>
  580. <p class="bili-video-card__skeleton--text short"></p>
  581. <p class="bili-video-card__skeleton--light"></p>
  582. </div>
  583. </div>
  584. </div>
  585. <div class="bili-video-card__wrap __scale-wrap">
  586. <a
  587. href="//www.bilibili.com/video/${bvid}"
  588. target="_blank"
  589. data-mod="partition_recommend"
  590. data-idx="content"
  591. data-ext="click"
  592. ><div class="bili-video-card__image __scale-player-wrap">
  593. <div class="bili-video-card__image--wrap">
  594. <div class="bili-watch-later" style="display: none">
  595. <svg class="bili-watch-later__icon">
  596. <use xlink:href="#widget-watch-later"></use></svg><span
  597. class="bili-watch-later__tip"
  598. style="display: none"
  599. ></span>
  600. </div>
  601. <picture class="v-img bili-video-card__cover"
  602. ><!---->
  603. <source
  604. srcset="
  605. ${pic}@672w_378h_1c_100q.webp
  606. "
  607. type="image/webp" />
  608. <img
  609. src="${pic}@672w_378h_1c_100q"
  610. alt="${title}"
  611. loading="lazy"
  612. onload=""
  613. /></picture>
  614. <div class="v-inline-player"></div>
  615. </div>
  616. <div class="bili-video-card__mask">
  617. <div class="bili-video-card__stats">
  618. <div class="bili-video-card__stats--left">
  619. <span class="bili-video-card__stats--item"
  620. ><svg class="bili-video-card__stats--icon">
  621. <use xlink:href="#widget-play-count"></use></svg><span class="bili-video-card__stats--text"
  622. >${Tool.formatBigNumber(play)}</span
  623. ></span
  624. ><span class="bili-video-card__stats--item"
  625. ><svg class="bili-video-card__stats--icon">
  626. <use xlink:href="#widget-agree"></use></svg><span class="bili-video-card__stats--text"
  627. >${Tool.formatBigNumber(like)}</span
  628. ></span
  629. >
  630. </div>
  631. <span class="bili-video-card__stats__duration">${duration}</span>
  632. </div>
  633. </div>
  634. </div></a
  635. >
  636. <div class="bili-video-card__info __scale-disable">
  637. <a
  638. href="//space.bilibili.com/${mid}"
  639. target="_blank"
  640. data-mod="partition_recommend"
  641. data-idx="content"
  642. data-ext="click"
  643. ><div class="v-avatar bili-video-card__avatar">
  644. <picture class="v-img v-avatar__face"
  645. ><!---->
  646. <source
  647. srcset="
  648. ${upic.substr(5)}@72w_72h.webp
  649. "
  650. type="image/webp" />
  651. <img
  652. src="${upic.substr(5)}@72w_72h"
  653. alt="${author}"
  654. loading="lazy"
  655. onload="" /></picture
  656. ><!---->
  657. </div></a
  658. >
  659. <div class="bili-video-card__info--right">
  660. <a
  661. href="//www.bilibili.com/video/${bvid}"
  662. target="_blank"
  663. data-mod="partition_recommend"
  664. data-idx="content"
  665. data-ext="click"
  666. ><h3
  667. class="bili-video-card__info--tit"
  668. title="${title}"
  669. >
  670. ${title}
  671. </h3></a
  672. >
  673. <p class="bili-video-card__info--bottom">
  674. <a
  675. class="bili-video-card__info--owner"
  676. href="//space.bilibili.com/${mid}"
  677. target="_blank"
  678. data-mod="partition_recommend"
  679. data-idx="content"
  680. data-ext="click"
  681. ><span class="bili-video-card__info--author">${author}</span
  682. ><span class="bili-video-card__info--date"
  683. ${Tool.diffTime(pubdate)}</span
  684. ></a
  685. >
  686. </p>
  687. </div>
  688. </div>
  689. </div>
  690. </div>
  691. `;
  692. videoCardBody.appendChild(Tool.s2d(domStr));
  693. }
  694. });
  695. };
  696.  
  697. // 更新视频
  698. const refreshVideo = async () => {
  699. let firstVideoIndex = (page - 1) * pageSize;
  700. let lastVideoIndex = firstVideoIndex + pageSize - 1;
  701. while(videoList.length < lastVideoIndex + 1) {
  702. let data = await API.getVideo(videoKey, searchPage);
  703. data.forEach((item) => {
  704. if (!Tool.isTimeTooLate(item.pubdate, rangeDay)) {
  705. if (bvList.indexOf(item.bvid) === -1) {
  706. videoList.push(item);
  707. bvList.push(item.bvid);
  708. }
  709. }
  710. });
  711. searchPage++;
  712. };
  713. page++;
  714. let applyData = videoList.slice(firstVideoIndex, lastVideoIndex + 1)
  715. getVideoCardTemplete(applyData);
  716. };
  717.  
  718. // 填入框架
  719. let main = document.querySelector('.bili-layout');
  720. let gridAll = document.querySelectorAll('.bili-grid');
  721. let templete = getTemplete(videoKey, imgUrl);
  722. main.insertBefore(Tool.s2d(templete), gridAll[2]);
  723.  
  724. // 第一次获取数据并渲染
  725. const applyFirstData = async () => {
  726. refreshVideo();
  727. };
  728. applyFirstData();
  729. // 换一换按钮添加更新视频事件
  730. let refreshVideoBtn = document.querySelector('#refreshVideo');
  731. refreshVideoBtn.addEventListener('click', refreshVideo);
  732.  
  733. let aside = document.querySelector('.aside-wrap');
  734. // popover
  735. const showpopover = (x, y) => {
  736. return `
  737. <div id="asoul-popover" style="position: absolute; z-index: 2000; top: ${y}px; left: ${x}px;">
  738. <div class="v-popover is-top" style="padding-bottom: 0px; margin-left: 0px; pointer-events: none;">
  739. <div class="v-popover-content bili-rank-list-video">
  740. <div class="rank-video-card__popover">
  741. <div class="rank-video-card__popover--top">
  742. <div class="rank-video-card__image rank-video-card__popover--image">
  743. <picture class="v-img rank-video-card__cover rank-video-card__popover--cover">
  744. <!---->
  745. <source srcset="//i1.hdslb.com/bfs/archive/6ac4c468f90987ecd2a51f1753f7d043560ac271.jpg@192w_108h.webp"
  746. type="image/webp"><img
  747. src="//i1.hdslb.com/bfs/archive/6ac4c468f90987ecd2a51f1753f7d043560ac271.jpg@192w_108h"
  748. alt="小伙买了80个模型,爆肝一周,只为在家建造一个迷你世界" loading="lazy" onload="">
  749. </picture>
  750. </div>
  751. <div class="rank-video-card__info rank-video-card__popover--info">
  752. <h3 class="rank-video-card__popover--tit" title="小伙买了80个模型,爆肝一周,只为在家建造一个迷你世界">小伙买了80个模型,爆肝一周,只为在家建造一个迷你世界
  753. </h3>
  754. <p class="rank-video-card__popover--author"><span>拜托了小翔哥</span><span> · 12-29</span></p>
  755. </div>
  756. </div>
  757. <ul class="rank-video-card__popover--stats">
  758. <li class="rank-video-card__popover--stats__item"><svg class="rank-video-card__popover--icon">
  759. <use xlink:href="#widget-play-count"></use>
  760. </svg><span>93万</span></li>
  761. <li class="rank-video-card__popover--stats__item"><svg class="rank-video-card__popover--icon">
  762. <use xlink:href="#widget-danmaku"></use>
  763. </svg><span>3931</span></li>
  764. <li class="rank-video-card__popover--stats__item"><svg class="rank-video-card__popover--icon">
  765. <use xlink:href="#widget-favorite"></use>
  766. </svg><span>1.3万</span></li>
  767. <li class="rank-video-card__popover--stats__item"><svg class="rank-video-card__popover--icon">
  768. <use xlink:href="#widget-coin"></use>
  769. </svg><span>7.6万</span></li>
  770. </ul>
  771. </div>
  772. </div>
  773. </div>
  774. </div>
  775. `
  776. }
  777.  
  778. // 侧边
  779. aside.append(Tool.s2d(asideBody));
  780.  
  781. let setting = document.querySelector('#tuntun-setting');
  782. let settingBtn = setting.children[0];
  783. let settingPop = setting.children[1];
  784. let settingForm = settingPop.children[0];
  785. let partNameInput = settingForm.children[0].children[1];
  786. let partImgUrlInput = settingForm.children[1].children[1];
  787. let partImgDom = document.querySelector('.tuntun-part-img');
  788. console.dir(partImgDom);
  789. partImgDom.style.borderRadius = `${imgBorderRadius}%`;
  790. let radiusRangeInput = document.querySelector('.tuntun-setting-imgRadius');
  791. let partTimeRangeInput = settingForm.children[3].children[1];
  792.  
  793. // 设置按钮点击事件
  794. settingBtn.addEventListener('click', () => {
  795. if (settingPop.className === 'tuntun-setting-popover tuntun-setting-none') {
  796. settingPop.className = 'tuntun-setting-popover';
  797. } else {
  798. settingPop.className = 'tuntun-setting-popover tuntun-setting-none';
  799. }
  800. partNameInput.value = videoKey;
  801. partImgUrlInput.value = imgUrl;
  802. partTimeRangeInput.value = rangeDay;
  803. radiusRangeInput.value = imgBorderRadius;
  804. partImgDom.style.borderRadius = `${imgBorderRadius}%`;
  805. });
  806.  
  807. // videoKey改变
  808. const videoKeyChange = (newKey) => {
  809. let seeMoreBtn = document.querySelector('.tuntun-see-more');
  810. let headerLeft = document.querySelector('.tuntun-part-left');
  811. videoKey = newKey;
  812. videoList = [];
  813. page = 1;
  814. searchPage = 1;
  815. bvList = [];
  816. GM_setValue('videoKey', newKey);
  817. seeMoreBtn.href = `https://search.bilibili.com/all?keyword=${newKey}`;
  818. headerLeft.children[2].href = `https://search.bilibili.com/all?keyword=${newKey}`;
  819. headerLeft.children[2].children[0].innerHTML = `${newKey}分区`;
  820. refreshVideo();
  821. }
  822.  
  823. // imgUrl改变
  824. const imgUrlChange = (newUrl) => {
  825. let partImgDom = document.querySelector('.tuntun-part-img');
  826. imgUrl = newUrl;
  827. GM_setValue('imgUrl', newUrl);
  828. partImgDom.src = newUrl;
  829. }
  830.  
  831. // 设置img的圆角
  832. radiusRangeInput.addEventListener('change', () => {
  833. partImgDom.style.borderRadius = `${radiusRangeInput.value}%`;
  834. });
  835. const imgBorderRadiusChange = (newRadiusNum) => {
  836. imgBorderRadius = newRadiusNum;
  837. GM_setValue('imgBorderRadius', newRadiusNum);
  838. }
  839.  
  840. // 时间范围改变
  841. const timeRangeChange = (timeRange) => {
  842. rangeDay = timeRange;
  843. videoList = [];
  844. page = 1;
  845. searchPage = 1;
  846. bvList = [];
  847. GM_setValue('rangeDay', timeRange);
  848. refreshVideo();
  849. }
  850.  
  851. // 设置表单确认
  852. settingForm.addEventListener('submit', (e) => {
  853. e.preventDefault();
  854. if (partNameInput.value !== videoKey) {
  855. videoKeyChange(partNameInput.value);
  856. }
  857. if (partImgUrlInput.value !== imgUrl) {
  858. imgUrlChange(partImgUrlInput.value);
  859. }
  860. if (radiusRangeInput.value !== imgBorderRadius) {
  861. imgBorderRadiusChange(radiusRangeInput.value);
  862. }
  863. if (partTimeRangeInput.value !== rangeDay) {
  864. timeRangeChange(partTimeRangeInput.value);
  865. }
  866. settingPop.className = 'tuntun-setting-popover tuntun-setting-none';
  867. });
  868.  
  869.  
  870. // settingBtn.addEventListener('')
  871.  
  872. // 鼠标移入
  873. // aside.addEventListener('mousemove', (e) => {
  874. // if (e.target.className === 'bili-rank-list-video__item--wrap') {
  875. // }
  876. // let option = e.target.getBoundingClientRect();
  877. // })
  878. // aside.addEventListener('mouseleave', () => {
  879. // document.body.removeChild(document.querySelector('#asoul-popover'));
  880. // })
  881. })();

QingJ © 2025

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