哔哩哔哩助手(播放记录,下载视频)

哔哩哔哩助手(播放记录,下载视频) bilibili,B站,b站,小破站

  1. // ==UserScript==
  2. // @name 哔哩哔哩助手(播放记录,下载视频)
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.01
  5. // @description 哔哩哔哩助手(播放记录,下载视频) bilibili,B站,b站,小破站
  6. // @author LY
  7. // @match *://*.bilibili.com/video/*
  8. // @icon https://www.bilibili.com/favicon.ico
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. var ly_div_son,
  14. ly_div,
  15. ly_span,
  16. list_box,
  17. b_title,
  18. b_url,
  19. b_id,
  20. ly_a = null,
  21. bvid,
  22. b_href;
  23. var flag = true;
  24. (function () {
  25. window.onload = function () {
  26. if (document
  27. .querySelector(".list-box") === null) {
  28. return
  29. }
  30. main(function () {
  31. init();
  32. if (flag) {
  33. //显示show
  34. show();
  35. var timer1 = setInterval(function () {
  36. if (
  37. document
  38. .querySelector(".list-box")
  39. .querySelectorAll("li")[0]
  40. .querySelector("a") != null
  41. ) {
  42. clearInterval(timer1);
  43. htmlChange(getP(b_id));
  44. localStorageChange(b_id, b_p);
  45. bvid = window.bvid
  46. watch();
  47. }
  48. }, 500);
  49. }
  50. });
  51. };
  52. })();
  53. //显示html
  54. function init() {
  55. b_href = window.location.href;
  56. var href = window.location.href;
  57. if (href.indexOf("video") == -1) {
  58. flag = false;
  59. } else {
  60. b_id = href.split("/video/")[1].split("?")[0];
  61. if (href.indexOf("?p=")) {
  62. b_p = href.split("?p=")[1];
  63. }
  64. }
  65. }
  66. function show() {
  67. ly_div = document.createElement("div");
  68. ly_div_son = document.createElement("div");
  69. ly_div_son.className = "ly_son";
  70. ly_div.className = "aaabbb";
  71. ly_div.style.cssText =
  72. "position:absolute;top:152px;right:7px;height:46px;color:#222;border-radius:2px;box-sizing:border-box;font-size:16px;line-height:46px;font-weight:400;z-index:999";
  73. ly_span = document.createElement("span");
  74. ly_span.style.cssText = "float:right;background:#f4f4f4;";
  75. ly_span.innerHTML = "等待页面加载...";
  76. ly_a = document.createElement("a");
  77. ly_a.style.cssText = "float:right;color:#00a1d6;background:#f4f4f4;";
  78. ly_div.appendChild(ly_div_son);
  79. ly_div.appendChild(ly_a);
  80. ly_div.appendChild(ly_span);
  81. document.body.append(ly_div);
  82. ly_a.onmouseover = function () {
  83. this.parentNode.children[0].style.display = "block";
  84. };
  85. ly_a.onmouseleave = function () {
  86. this.parentNode.children[0].style.display = "none";
  87. };
  88. var styles = document.createElement("style");
  89. styles.id = "id";
  90. styles.type = "text/css";
  91. if (styles.styleSheet) {
  92. styles.styleSheet.cssText =
  93. '.ly_son{display:none;position:absolute;top:55px;right:4px;padding:0 8px;white-space:nowrap;height:40px;border-radius:8px;color:#fff;font-size:18px;line-height:40px;background-color:#00b5e5}.ly_son::after{position:absolute;top:-20px;right:11px;content:" ";width:0;height:0;border-top:10px solid transparent;border-bottom:10px solid #00b5e5;border-left:10px solid transparent;border-right:10px solid transparent}'; //IE
  94. } else {
  95. styles.appendChild(
  96. document.createTextNode(
  97. '.ly_son{display:none;position:absolute;top:55px;right:4px;padding:0 8px;white-space:nowrap;height:40px;border-radius:8px;color:#fff;font-size:18px;line-height:40px;background-color:#00b5e5}.ly_son::after{position:absolute;top:-20px;right:11px;content:" ";width:0;height:0;border-top:10px solid transparent;border-bottom:10px solid #00b5e5;border-left:10px solid transparent;border-right:10px solid transparent}'
  98. )
  99. ); //for FF
  100. }
  101.  
  102. document.getElementsByTagName("head")[0].appendChild(styles);
  103. }
  104. //集数改变
  105. function htmlChange(p) {
  106. ly_span.innerHTML = "上次播放第";
  107. list_box = document.querySelector(".list-box").querySelectorAll("li");
  108. b_title = list_box[p - 1].querySelector("a").title;
  109. ly_div_son.innerHTML = b_title;
  110. ly_a.innerHTML = p + "集"; //鼠标进入显示文字
  111. ly_a.href = "http://www.bilibili.com/video/" + b_id + "?p=" + p;
  112. var url = "https://api.bilibili.com/x/player/playurl?fourk=1&bvid=" + window.bvid + "&cid=" + window.cid;
  113. get(url)
  114. }
  115. function localStorageChange(b_id, p) {
  116. var json = getLocalStorage();
  117. json[b_id] = p;
  118. setLocalStorage(json);
  119. }
  120. function getLocalStorage() {
  121. if (localStorage.getItem("b_localStorage") === null) {
  122. localStorage.setItem("b_localStorage", JSON.stringify({ by: "ly" }));
  123. } else {
  124. return JSON.parse(localStorage.getItem("b_localStorage"));
  125. }
  126. }
  127. function add(id, p) {
  128. var json = getLocalStorage();
  129. json[id] = p;
  130. setLocalStorage(json);
  131. }
  132. function setLocalStorage(json) {
  133. localStorage.setItem("b_localStorage", JSON.stringify(json));
  134. }
  135. function getP(id) {
  136. var json = getLocalStorage("b_localStorage");
  137. for (var jsonItem in json) {
  138. if (jsonItem === id) {
  139. return parseInt(json[jsonItem]);
  140. }
  141. }
  142. add(b_id, 1);
  143. return 1;
  144. }
  145. function watch() {
  146. var timer = setInterval(function () {
  147. var href = window.location.href;
  148. if (b_href !== href) {
  149. htmlChange(getP(b_id));
  150. localStorageChange(b_id, href.split("?p=")[1]);
  151. b_href = href;
  152. }
  153.  
  154. }, 2500);
  155. }
  156. function main(fn) {
  157. fn();
  158. }
  159.  
  160. (function () {
  161.  
  162. "use strict";
  163. var bvid;
  164. var isLoad = false;
  165. var timer = setInterval(function () {
  166. if (!window.$) {
  167. return;
  168. }
  169. var url = "https://api.bilibili.com/x/player/playurl?fourk=1&bvid=" + window.bvid + "&cid=" + window.cid;
  170. var downloadBtn = $("<span></span>").css("width", 0).html("<span><i class=\"van-icon-download\" style=\"font-size:28px;cursor: pointer;padding-left: 10px\"></i></span>");
  171. $(".ops").append(downloadBtn);
  172. $(".toolbar-left").append(downloadBtn)
  173.  
  174. window.modal = $("<div></div>").css({
  175. padding: "20px",
  176. background: "#ffffff",
  177. position: "fixed",
  178. top: "40%",
  179. left: "50%",
  180. transform: "translate(-40%,-50%)",
  181. zIndex: "999",
  182. borderRadius: "5%",
  183. boxShadow: "2px 2px 13px #333",
  184. fontSize: "20px",
  185. color: "#00a1d6",
  186. lineHeight: "50px",
  187. width: "300px",
  188. textAlign: "center",
  189. display: "none"
  190. }).html("<span>选择下载清晰度</span>").append($("<span>X</span>").css({
  191. color: "red",
  192. fontSize: "28px",
  193. top: "0px",
  194. position: "absolute",
  195. right: "19px",
  196. cursor: "pointer"
  197.  
  198. }).on("click", function () {
  199. modal.fadeToggle()
  200. }));
  201. $("#app").append(modal);
  202. downloadBtn.hover(function () {
  203. downloadBtn.css({
  204. color: "#00a1d6"
  205. });
  206. }, function () {
  207. downloadBtn.css({
  208. color: "#505050"
  209. });
  210. });
  211. downloadBtn.on("click", function () {
  212. if (isLoad) {
  213. bvid = window.bvid
  214. modal.fadeToggle()
  215. return;
  216. }
  217. isLoad = true;
  218. modal.fadeToggle()
  219. get(url)
  220. });
  221.  
  222. clearInterval(timer);
  223. }, 500);
  224. bvid = window.bvid
  225.  
  226. setInterval(() => {
  227. var _bvid = window.bvid
  228. if (bvid != _bvid) {
  229. var url = "https://api.bilibili.com/x/player/playurl?fourk=1&bvid=" + window.bvid + "&cid=" + window.cid;
  230. get(url)
  231. bvid = _bvid
  232. }
  233. }, 3000)
  234. })();
  235.  
  236. function get(url) {
  237. fetch(url).then(function (res) {
  238. return res.json();
  239. }).then(function (res) {
  240. var support_formats = res.data.support_formats;
  241. modal.find("li").remove()
  242. support_formats.forEach(function (item) {
  243. var li = $("<li></li>").click(function () {
  244. fetch(url + "&qn=" + item.quality).then(function (res) {
  245. return res.json();
  246. }).then(function (res) {
  247. var a = $("<a target=\"_blank\">下载</a>").attr("href", res.data.durl[0].url);
  248.  
  249. $("body").append(a);
  250. a[0].click();
  251. a.empty();
  252. });
  253. }).hover(function () {
  254. li.css({
  255. background: "#f4f4f4",
  256. cursor: "pointer"
  257. });
  258. }, function () {
  259. li.css({
  260. background: "#fff"
  261. });
  262. });
  263. li.html(item.new_description);
  264. modal.append(li);
  265. });
  266.  
  267. });
  268. }

QingJ © 2025

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