哔哩哔哩PWA

立刻将哔哩哔哩网页变为轻量的、简洁的软件界面

  1. // ==UserScript==
  2. // @name 哔哩哔哩PWA
  3. // @namespace https://ez118.github.io/
  4. // @version 1.3.0
  5. // @description 立刻将哔哩哔哩网页变为轻量的、简洁的软件界面
  6. // @author ZZY_WISU
  7. // @match https://www.bilibili.com/*
  8. // @match https://m.bilibili.com/*
  9. // @match https://bilibili.com/*
  10. // @icon https://www.bilibili.com/favicon.ico?v=114514
  11. // @license GNU GPLv3
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @grant GM_addStyle
  15. // @require https://unpkg.com/jquery@3.7.1/dist/jquery.min.js
  16. // ==/UserScript==
  17.  
  18.  
  19. /* DLG.JS */
  20. /* 自定义Toast */
  21. function showToast(message, duration) {
  22. duration = duration ? duration : "3000";
  23. var toast = $('#toast_container');
  24. toast.text(message);
  25. toast.fadeIn(200);
  26. setTimeout(function () {
  27. toast.fadeOut(200);
  28. }, duration);
  29. }
  30.  
  31. /* 悬浮搜索框 */
  32. function showSearchBox(){
  33. $(".searchbox_container").fadeIn(200)
  34. $("#searchbox_searchInput").val("");
  35. $("#searchbox_searchInput").focus();
  36. }
  37. function closeSearchBox(){
  38. $(".searchbox_container").fadeOut();
  39. }
  40.  
  41. /* HOME.JS */
  42. var currentTab = "home";
  43. var currentUid = "114514";
  44. var rcmdCnt = 1;
  45.  
  46. function getSearchResult(wd) {
  47. window.open('https://search.bilibili.com/all?keyword=' + encodeURI(wd));
  48. }
  49.  
  50. function getRecommendedVideos() {
  51. $("#item_container").html("");
  52. $("#dynamic_loader").show();
  53. for (let i = 1; i <= 2; i++) {
  54. $.get("https://api.bilibili.com/x/web-interface/wbi/index/top/feed/rcmd?web_location=1430650&y_num=5&fresh_type=3&feed_version=V8&fresh_idx_1h=1&fetch_row=1&fresh_idx=" + rcmdCnt + "&brush=0&homepage_ver=1&ps=30&last_y_num=5", function (tjlist) {
  55. var WebList = "";
  56. for (var i = 0; i < tjlist.data.item.length; i++) {
  57. WebList += `<div class='dynamic_singlebox'>
  58. <a href="#bvid_` + tjlist.data.item[i].bvid + `">
  59. <img src='` + tjlist.data.item[i].pic + `@412w_232h_1c.webp'><br>
  60. <div class="dynamic_singlebox_vt">` + tjlist.data.item[i].title + `</div>
  61. </a>
  62. <a href="#uid_` + tjlist.data.item[i].owner.mid + `">
  63. <div class="dynamic_singlebox_un">🔘&nbsp;` + tjlist.data.item[i].owner.name + `</div>
  64. </a>
  65. </div>`;
  66. }
  67. $("#item_container").append(WebList);
  68. $("#dynamic_loader").hide();
  69.  
  70. rcmdCnt += 1;
  71. });
  72. }
  73. }
  74.  
  75. function getHotVideos() {
  76. $("#item_container").html("");
  77. $("#dynamic_loader").show();
  78. $.get("https://api.bilibili.com/x/web-interface/popular?ps=40&pn=1", function (tjlist) {
  79. var WebList = "";
  80. for (var i = 0; i < tjlist.data.list.length; i++) {
  81. var card = tjlist.data.list[i];
  82. var tooltipText = '- 点赞数量: ' + card.stat.like + '\n- 视频简介: ' + (card.desc ? card.desc : "无简介") + (card.rcmd_reason.content ? ("\n- 推荐原因: " + card.rcmd_reason.content) : "");
  83. WebList += `<div class='wide_singlebox' title='` + tooltipText + `'>
  84. <a href="#bvid_` + card.bvid + `">
  85. <img src='` + card.pic + `@412w_232h_1c.webp'><br>
  86. </a>
  87. <div height="100%">
  88. <a href="#bvid_` + card.bvid + `">
  89. <div class="wide_singlebox_vt">` + card.title + `</div>
  90. </a>
  91. <a href="#uid_` + card.owner.mid + `">
  92. <div class="wide_singlebox_un">🔘&nbsp;` + card.owner.name + `</div>
  93. </a>
  94. </div>
  95. </div>`;
  96. }
  97. $("#item_container").append(WebList);
  98. $("#dynamic_loader").hide();
  99. });
  100. }
  101.  
  102. function routeCtrl(isOnload) {
  103. var data = window.location.hash.substring(1);
  104. if (data.includes("bvid")) {
  105. /* 视频播放bvid */
  106. openPlayer({
  107. bvid: data.split("_")[1],
  108. refreshOnly: data.includes("refreshonly") ? "watch_later" : null,
  109. videoList: data.includes("watchlater") ? "watch_later" : null
  110. });
  111. } else if (data.includes("aid")) {
  112. /* 视频播放aid */
  113. openPlayer({
  114. aid: data.split("_")[1],
  115. refreshOnly: data.includes("refreshonly") ? "watch_later" : null,
  116. videoList: data.includes("watchlater") ? "watch_later" : null
  117. });
  118. } else if (data[0] == "n") {
  119. /* 导航栏 */
  120. let tab = data.split("_")[1];
  121. if (tab == "home") { getRecommendedVideos(); } else if (tab == "hot") { getHotVideos(); } else if (tab == "search") { showSearchBox(); }
  122. currentTab = tab;
  123. } else {
  124. getRecommendedVideos();
  125. }
  126.  
  127. if (isOnload == true && data[0] != "n") {
  128. getRecommendedVideos();
  129. }
  130. }
  131.  
  132.  
  133. /* PLAYER.JS */
  134. var bvidPlayingNow = ""; /* 正在播放的bvid */
  135. var cidPlayingNow = "";
  136. var player_danmuList = []; /* 弹幕列表 */
  137. var player_danmuCnt = 0; /* 弹幕数量 */
  138. var player_advancedDanmu = false; /* 高级弹幕显示模式 */
  139. var player_highQuality = 0; /* 视频高画质Flag,1为开启,0为关闭 */
  140.  
  141. function xml2json(xml) {
  142. /* xml转json */
  143. var obj = {};
  144. if (xml.nodeType == 1) {
  145. if (xml.attributes.length > 0) {
  146. obj["@attributes"] = {};
  147. for (var j = 0; j < xml.attributes.length; j++) {
  148. var attribute = xml.attributes.item(j);
  149. obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
  150. }
  151. }
  152. } else if (xml.nodeType == 3) {
  153. obj = xml.nodeValue;
  154. }
  155. // do children
  156. if (xml.hasChildNodes()) {
  157. for (var i = 0; i < xml.childNodes.length; i++) {
  158. var item = xml.childNodes.item(i);
  159. var nodeName = item.nodeName;
  160. if (typeof (obj[nodeName]) == "undefined") {
  161. obj[nodeName] = xml2json(item);
  162. } else {
  163. if (typeof (obj[nodeName].length) == "undefined") {
  164. var old = obj[nodeName];
  165. obj[nodeName] = [];
  166. obj[nodeName].push(old);
  167. }
  168. obj[nodeName].push(xml2json(item));
  169. }
  170. }
  171. }
  172. return obj;
  173. }
  174.  
  175. function parseComments(comments) {
  176. /* 解析评论 */
  177. let result = '';
  178.  
  179. comments.forEach(comment => {
  180. const { member, content, replies, ctime } = comment;
  181. const timeString = new Date(ctime * 1000).toLocaleString();
  182.  
  183. result += `<div class="reply"><b>🔘&nbsp;${member.uname}</b><br>`;
  184. result += `<div class="content">${content.message}</div>`;
  185. result += `<i>时间:${timeString}</i></div><hr>`;
  186.  
  187. if (replies && replies.length > 0) {
  188. result += `<div class="moreReply">回复:<br>`;
  189. result += parseComments(replies);
  190. result += `</div>`;
  191. }
  192. });
  193.  
  194. return result;
  195. }
  196.  
  197. function getDanmu(cid) {
  198. /* 获取弹幕 */
  199. $.get("https://comment.bilibili.com/" + cid + ".xml", function (s) {
  200. var cInfo = xml2json(s).i.d;
  201. var newInfo = [];
  202. for (let i = 0; i < cInfo.length; i++) {
  203. try {
  204. newInfo.push({ "text": cInfo[i]["#text"], "time": parseFloat(cInfo[i]["@attributes"]["p"].split(",")[0]) });
  205. } catch (e) {
  206. console.log("弹幕装填出错(解析时)")
  207. }
  208. }
  209. player_danmuList = newInfo.sort(function (x, y) {
  210. /* 弹幕排序方式 */
  211. return x["time"] - y["time"];
  212. });
  213. });
  214. }
  215.  
  216. function showDanmu(content) {
  217. /* 装填高级弹幕 */
  218. var containerWidth = $("#player_container").innerWidth() - 380;
  219. var containerHeight = $("#player_container").innerHeight() - 20;
  220. var pageH = parseInt(Math.random() * containerHeight);
  221. var newSpan = $("<div class='player_danmuText'></span>");
  222. newSpan.text(content);
  223.  
  224. newSpan.appendTo("#player_scrComment");
  225.  
  226. newSpan.css("left", (containerWidth - newSpan.innerWidth() + 20));
  227. newSpan.css("top", pageH);
  228. //弹幕动画
  229. newSpan.animate({ "left": -500 }, 10000, "linear", function () {
  230. $(this).remove();
  231. });
  232. }
  233.  
  234. function loadVideoSource(bvid, cid) {
  235. /* 加载视频源 */
  236. $.get("https://api.bilibili.com/x/player/playurl?type=mp4&platform=html5&bvid=" + bvid + "&cid=" + cid + "&qn=64&high_quality=" + player_highQuality, function (result) {
  237. /* 获取视频播放源 */
  238. var vidUrl = result.data.durl[0].url;
  239. $("#player_videoContainer").attr("src", vidUrl);
  240. bvidPlayingNow = bvid;
  241. cidPlayingNow = cid;
  242. });
  243. }
  244.  
  245. function openPlayer(option) {
  246. /* 显示播放器并展示指定视频 */
  247.  
  248. /* 视频ID */
  249. if (option.bvid) {
  250. var urlStr = "bvid=" + option.bvid;
  251. } else if (option.aid) {
  252. urlStr = "aid=" + option.aid;
  253. } else {
  254. console.log("[ERROR] 播放器参数错误:缺少一个可用的bvid或aid");
  255. showToast("播放器参数错误");
  256. return;
  257. }
  258.  
  259. $("#player_container").fadeIn(200);
  260.  
  261. /* 视频详情 */
  262. $.get("https://api.bilibili.com/x/web-interface/view?" + urlStr, function (VideoInfo) {
  263. /* 获取视频信息 */
  264. var cid = VideoInfo["data"]["pages"][0]["cid"];
  265. var bvid = VideoInfo["data"]["bvid"];
  266. var aid = VideoInfo["data"]["aid"];
  267. var desc = VideoInfo["data"]["desc"] || "-";
  268.  
  269. $("#player_title").html(VideoInfo["data"]["title"]);
  270. $("#player_descArea").html("<b style='font-size:18px;'>[详情]</b><br>" + desc);
  271.  
  272. getDanmu(cid); /* 获取弹幕 */
  273.  
  274. loadVideoSource(bvid, cid); /* 获取视频源 */
  275.  
  276. $.get("https://api.bilibili.com/x/v2/reply?jsonp=jsonp&pn=1&type=1&sort=2&oid=" + aid, function (ReplyInfo) {
  277. /* 获取评论 */
  278. var textAll = parseComments(ReplyInfo.data.replies);
  279. $("#player_descArea").append("<hr><b style='font-size:18px;'>[评论]</b><br>" + textAll);
  280. });
  281. });
  282.  
  283. if (option.refreshOnly) { return; }
  284.  
  285. /* 侧边栏列表 */
  286.  
  287. /* 如果是从普通视频页面进入的话,侧边栏显示推荐视频 */
  288. $.get("https://api.bilibili.com/x/web-interface/archive/related?" + urlStr, function (res) {
  289. var VidList = "";
  290. res.data.forEach((item, index) => {
  291. VidList += `<div class='dynamic_singlebox'>
  292. <a href="#bvid_` + item.bvid + `">
  293. <img src='` + item.pic + `@412w_232h_1c.webp'><br>
  294. <div class="dynamic_singlebox_vt">` + item.title + `</div>
  295. </a>
  296. <a href="#uid_` + item.owner.mid + `">
  297. <div class="dynamic_singlebox_un">🔘&nbsp;` + item.owner.name + `</div>
  298. </a>
  299. </div>`
  300. })
  301. $("#player_videoList").html(VidList);
  302. });
  303. }
  304.  
  305. function closePlayer() {
  306. /* 关闭播放器 */
  307. $("#player_container").fadeOut(150);
  308. $("#player_videoContainer").attr("src", "");
  309. player_danmuList = [];
  310. player_danmuCnt = 0;
  311. }
  312.  
  313.  
  314.  
  315. function isFirstPage() {
  316. let url = window.location.href;
  317. let a = url.replace(".com/", ".com").split("/");
  318. return (a.length == 3 && url.includes("bilibili.com"));
  319. }
  320.  
  321. (function () {
  322. 'use strict';
  323.  
  324. if (!isFirstPage()) { return; }
  325.  
  326. document.head.innerHTML = `
  327. <meta http-equiv="Content-Type"content="text/html; charset=utf-8"><meta name="viewport"content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0"><title>哔哩哔哩PWA</title><link rel="stylesheet"type="text/css"href="https://fonts.googleapis.com/icon?family=Material+Icons">
  328. `;
  329.  
  330. document.body.innerHTML = `
  331. <div class="sidenavBar"align="center"><a href="#nav_search"><div class="sidenavItem"><i class="material-icons">search_rounded</i></div></a><a href="#nav_home"><div class="sidenavItem"><i class="material-icons">home_rounded</i></div></a><a href="#nav_hot"><div class="sidenavItem"><i class="material-icons">whatshot_rounded</i></div></a></div><div id="RefreshBtn"title="刷新"><i class="material-icons">refresh_rounded</i></div><i id="dynamic_loader"style="display:block;"class="material-icons">hourglass_empty_rounded</i><div id="item_container"></div><div id="player_container"style="display:none;"><table style="width:100%; height:100%;"><tr height="40px"><td align="left"><b id="player_title">[视频标题]</b></td><td align="right"width="380px"><i class="material-icons"style="width:30px;cursor:pointer;"id="player_highQnBtn"title="切换到高画质">high_quality_rounded</i><i class="material-icons"style="width:30px;cursor:pointer;"id="player_pipBtn"title="画中画">picture_in_picture_rounded</i><i class="material-icons"style="width:30px;cursor:pointer;"id="player_scrSwitchBtn"title="切换弹幕模式">notes_rounded</i><i class="material-icons"style="width:35px;cursor:pointer;"id="player_openNewBtn"title="打开原网页">open_in_new_rounded</i><i class="material-icons"style="width:30px;cursor:pointer;"id="player_closeBtn"title="关闭播放器">close_rounded</i></td></tr><tr><td align="center"><video src=""id="player_videoContainer"controls></video></td><td align="left"style="border-left:1px solid #666; vertical-align:top;"width="380px"><div class="player_sidebarTabs"><p id="player_sidebarTab_1"class="player_sidebarTab_sel">详情&amp;评论</p><p id="player_sidebarTab_2"class="player_sidebarTab">相关推荐</p></div><div id="player_descArea">暂无</div><div id="player_videoList"style="display:none;">无视频</div></td></tr></table><div id="player_scrComment"></div></div><div class="searchbox_container"style="display:none;"><input type="text"class="searchInput"id="searchbox_searchInput"placeholder="回车/Enter开始搜索"><i class="material-icons searchClose"id="searchbox_searchClose"title="关闭搜索框">close_rounded</i></div><div id="toast_container"></div>
  332. `;
  333.  
  334. GM_addStyle(`
  335. img{-webkit-user-drag:none}a{text-decoration:none;color:#FFF}body{background-color:#17181a;color:#FFF;user-select:none;overflow-y:auto;height:100%;width:100%;margin:0px}html{height:100%;width:100%}#item_container{width:calc(100% - 85px);margin-left:85px;margin-top:10px}.dynamic_singlebox{height:220px;width:250px;font-size:15px;float:left;background:#18181c;overflow:hidden;border-radius:10px;margin:8px;padding:5px;transition:all 0.2s;cursor:pointer;z-index:1}.dynamic_singlebox:hover{background:#3b3b3b}.dynamic_singlebox_un{color:#848484;font-size:12px;position:relative;top:0px;width:100%;overflow:hidden}.dynamic_singlebox_vt{color:#FFFFFF;width:100%;height:60px;overflow:hidden;word-wrap:break-word;word-break:normal}.dynamic_singlebox img{width:100%;border-radius:8px}.wide_singlebox{display:flex;width:calc(33% - 40px);height:120px;margin-left:15px;margin-top:15px;float:left;background:#18181c;overflow:hidden;border-radius:10px;padding:10px;transition:all 0.2s;cursor:pointer;z-index:1;border:1px solid #3b3b3b}.wide_singlebox:hover{background:#3b3b3b}.wide_singlebox img{height:100%;border-radius:8px}.wide_singlebox_un{color:#848484;font-size:12px;position:relative;top:0px;width:100%;overflow:hidden;margin-left:8px}.wide_singlebox_vt{color:#FFFFFF;width:99%;height:100px;overflow:hidden;font-size:15px;margin-left:8px}.wide_singlebox_vt .keyword{color:#00a1d6}#dynamic_loader{margin-left:calc(50% - 50px);margin-top:50px;font-size:40px}#RefreshBtn{position:fixed;left:22px;top:430px;z-index:101;height:24px;width:24px;padding:12px;border-radius:50px;border:1px solid #383942;background:#1e2022;color:#FFF;cursor:pointer;display:flex;justify-content:center;align-items:center;transition:all .1s;transform-origin:center center;overflow:hidden}#RefreshBtn:hover{color:#00a1d6;background:#FFF;border-color:#FFF;box-shadow:0 0 15px rgba(255,255,255,.6)}#RefreshBtn .material-icons{width:24px;margin-top:1px}.sidenavBar{display:flex;flex-direction:column;background:#1e2022;color:#FFF;padding:1px;border:1px solid #383942;width:60px;height:fit-content;position:fixed;left:15px;top:235px;z-index:1000;border-radius:50px}.sidenavItem{margin:6px;width:24px;height:24px;background:#1b1c22;padding:12px;cursor:pointer;border-radius:40px;transition:all .1s;display:flex;justify-content:center;align-items:center;overflow:hidden;transform-origin:center center;box-shadow:0 10px 15px #00000038,0 4px 6px #00000029}.sidenavItem:hover{color:#00a1d6;transform:scale(1.1,1.1);box-shadow:0 0 20px rgba(255,255,255,.7);background:#FFF}.sidenavItem .material-icons{width:24px}.searchbox_container{position:fixed;top:0px;left:0px;width:100vw;height:100vh;z-index:105;background:rgba(0,0,0,0.6)}.searchbox_container .searchInput{padding:15px 25px;outline:none;font-size:16px;border-radius:30px;color:#FFF;background:#1e2022;position:absolute;top:70px;left:50vw;transform:translateX(-50%);width:400px;border:1px solid #383942;box-shadow:0 10px 18px #00000038,0 6px 8px #00000029;transition:all .3s}.searchbox_container .searchInput:focus{border:1px solid #51515b}.searchbox_container .searchClose{position:absolute;top:84px;left:calc(50vw + 187px);color:#FFF;cursor:pointer;width:24px}#player_container{position:fixed;top:0px;left:92px;z-index:103;width:calc(100vw - 103px);height:100vh;background:#1e2022;border-radius:20px 0px 0px 20px}#player_videoContainer{max-width:100%;outline:none;height:calc(100% - 10px);border:none;background:#000}#player_title{margin-left:15px;font-size:18px}#player_descArea{user-select:text;word-wrap:break-word;word-break:break-all;height:100%;font-size:16px;color:#DDD;overflow-y:auto}#player_descArea hr{margin:1px;color:#888;border:none;border-bottom:1px solid #848484}#player_descArea .moreReply{padding:5px;margin:10px;border:1px dashed #646464;border-radius:8px}#player_descArea .reply{margin-bottom:5px}#player_descArea .reply .content{color:#EEE;margin-left:15px}#player_descArea .reply i{color:#888;margin-left:20px}#player_videoList{user-select:none;word-wrap:break-word;word-break:break-all;height:100%;font-size:16px;color:#DDD;overflow-y:auto}#player_scrComment{width:80%;position:fixed;top:50px;left:85px;z-index:104;font-size:16px;color:#EEE}.player_danmuText{width:fit-content;max-width:500px;font-size:18px;font-weight:bold;opacity:0.8;z-index:104;position:fixed;color:#EEEEEE;text-shadow:0 0 2px #000}.player_sidebarTabs{display:flex;flex-direction:row;overflow:hidden;height:fit-content;margin-bottom:10px;margin-top:10px}.player_sidebarTabs .player_sidebarTab_sel{padding:5px 8px;border-bottom:4px solid #00a1d6;font-size:15px;margin:8px 5px 0px 0px;cursor:pointer}.player_sidebarTabs .player_sidebarTab{padding:5px 8px;border-bottom:4px solid #333;font-size:15px;margin:8px 5px 0px 0px;cursor:pointer}#toast_container{display:none;position:fixed;bottom:40px;left:50%;transform:translateX(-50%);background-color:#333;color:#fff;padding:8px 20px;border-radius:5px;z-index:9999}
  336. `);
  337.  
  338.  
  339.  
  340. /* HOME.JS */
  341. routeCtrl(true);
  342.  
  343. window.addEventListener('popstate', function (event) {
  344. routeCtrl();
  345. });
  346.  
  347. $("#RefreshBtn").click(function () {
  348. /* 刷新 */
  349. if (currentTab == "home") { getRecommendedVideos(); } else if (currentTab == "hot") { getHotVideos(); }
  350. });
  351.  
  352.  
  353. /* PLAYER.JS */
  354.  
  355. /* 按钮事件监听 */
  356. $("#player_openNewBtn").click(function () {
  357. window.open("https://www.bilibili.com/video/" + bvidPlayingNow); /* 在新标签页打开 */
  358. });
  359. $("#player_closeBtn").click(function () {
  360. closePlayer(); /* 关闭播放器 */
  361. });
  362. $("#player_scrSwitchBtn").click(function () {
  363. player_advancedDanmu = !player_advancedDanmu; /* 切换弹幕模式 */
  364. showToast("弹幕模式已切换,当前模式:" + (player_advancedDanmu ? "全屏滑动弹幕模式" : "简单弹幕模式"));
  365. });
  366. $("#player_pipBtn").click(function () {
  367. var pip = $("#player_videoContainer")[0].requestPictureInPicture(); /* 切换画中画 */
  368. showToast("画中画", 1000);
  369. });
  370. $("#player_highQnBtn").click(function () {
  371. /* 切换高画质 */
  372. if (player_highQuality == 1) {
  373. player_highQuality = 0;
  374. showToast("已切换为普通画质", 5000);
  375. } else {
  376. player_highQuality = 1;
  377. showToast("已切换为高画质", 5000);
  378. }
  379. loadVideoSource(bvidPlayingNow, cidPlayingNow);
  380. });
  381.  
  382.  
  383. /* 侧边栏标签切换 */
  384. $("#player_sidebarTab_1").click(function () {
  385. $("#player_descArea").show();
  386. $("#player_videoList").hide();
  387. $("#player_sidebarTab_1").attr("class", 'player_sidebarTab_sel');
  388. $("#player_sidebarTab_2").attr("class", 'player_sidebarTab');
  389. });
  390. $("#player_sidebarTab_2").click(function () {
  391. $("#player_descArea").hide();
  392. $("#player_videoList").show();
  393.  
  394. $("#player_sidebarTab_1").attr("class", 'player_sidebarTab');
  395. $("#player_sidebarTab_2").attr("class", 'player_sidebarTab_sel');
  396. });
  397.  
  398.  
  399. /* 弹幕输出 */
  400. setInterval(function () {
  401. if (!player_danmuList || player_danmuList.length == 0 || player_danmuList.length <= player_danmuCnt) { return; }
  402. try {
  403. if (player_danmuList[player_danmuCnt]["time"] <= $("#player_videoContainer")[0].currentTime) {
  404. if (player_advancedDanmu) {
  405. showDanmu(player_danmuList[player_danmuCnt]["text"]);
  406. } else {
  407. $("#player_scrComment").html("<b>「弹幕」</b>" + player_danmuList[player_danmuCnt]["text"]);
  408. }
  409. player_danmuCnt += 1;
  410. }
  411. } catch (e) { console.log("弹幕装填出错(显示时)" + e) }
  412. }, 200);
  413.  
  414. (function () {
  415. /* 视频播放完毕事件 */
  416. $("#player_videoContainer").bind('ended', function () {
  417. $("#player_videoContainer")[0].currentTime = 0;
  418. player_danmuCnt = 0;
  419. showToast("视频播放完毕", 1000);
  420. });
  421. })();
  422.  
  423.  
  424. /* DLG.JS */
  425. $("#searchbox_searchInput").keydown(function (e) {
  426. if (e.keyCode == 13) {
  427. getSearchResult($(this).val());
  428. closeSearchBox();
  429. }
  430. });
  431.  
  432. $('.searchbox_container').click(function (event) {
  433. /* 点击搜索框之外,自动关闭搜索框 */
  434. var target = $(event.target);
  435. if (!target.is('#searchbox_searchInput')) {
  436. closeSearchBox();
  437. }
  438. });
  439.  
  440. $(document).keydown(function (event) {
  441. /* 快捷键: ctrl+Q快速关闭窗口 */
  442. if (event.ctrlKey && event.key === 'q') {
  443. event.preventDefault();
  444.  
  445. var playerHidden = $("#player_container").is(":hidden");
  446. var searchHidden = $(".searchbox_container").is(":hidden");
  447.  
  448. if (!searchHidden) {
  449. closeSearchBox();
  450. } else if (!playerHidden) {
  451. closePlayer();
  452. } else {
  453. closePlayer();
  454. }
  455.  
  456. return false;
  457. }
  458. });
  459. })();