bilibili弹幕发送者查询

查询bilibili弹幕发送者

  1. // ==UserScript==
  2. // @name bilibili弹幕发送者查询
  3. // @description 查询bilibili弹幕发送者
  4. // @match *://www.bilibili.com/video/av*
  5. // @match *://bangumi.bilibili.com/anime/*/play*
  6. // @match *://www.bilibili.com/bangumi/play/ep*
  7. // @match *://www.bilibili.com/bangumi/play/ss*
  8. // @match *://www.bilibili.com/watchlater/
  9. // @version 1.0
  10. // @author pilipili
  11. // @copyright pilipili
  12. // @license GPLv3
  13. // @grant none
  14. // @run-at document-end
  15. // @namespace https://greasyfork.org/users/206036
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. var initst = window.__INITIAL_STATE__;
  20. var pnum = -1;
  21. var cid = 0;
  22. var type = 0;
  23. var plist = Array();
  24. if (initst.hasOwnProperty("aid"))
  25. plist = initst.videoData.pages;
  26. else {
  27. plist = initst.epList;
  28. type = 1;
  29. }
  30. var damcache = Array();
  31. var loaded = Array();
  32. var uidcache = Array();
  33. var lvcache = Array();
  34. var nowdam = Array();
  35. var process = Array();
  36. var checker = 0;
  37. function getp() {
  38. //DIFF!!!
  39. //decode P
  40. var lascid = cid;
  41. if (type == 0) {
  42. var tmpst = window.location.search.length > 0 ? window.location.search.substr(1) : "";
  43. var tmparr = tmpst.split("&");
  44. var resa = Array();
  45. for (var i = 0; i < tmparr.length; i++) {
  46. var num = tmparr[i].indexOf("=");
  47. if (num > 0) {
  48. var name = tmparr[i].substring(0, num);
  49. var value = tmparr[i].substr(num + 1);
  50. resa[name] = value;
  51. }
  52. }
  53. pnum = resa.hasOwnProperty("p") ? resa.p : 1;
  54. cid = plist[pnum - 1].cid;
  55. }
  56. else {
  57. cid=window.__INITIAL_STATE__.epInfo.cid;
  58. }
  59. if (lascid != cid) rebind();
  60. if (!damcache.hasOwnProperty(cid)) {
  61. damcache[cid] = Array();
  62. $.ajax({
  63. url: "https://comment.bilibili.com/" + cid + ".xml",
  64. type: "GET",
  65. dataType: "xml",
  66. cache: false,
  67. success: function (xml) {
  68. nowdam = Array();
  69. var tot = 0;
  70. $(xml).find("d").each(function () {
  71. var p = $(this).attr("p").split(",");
  72. var obj = Array();
  73. obj['text'] = $(this).text();
  74. obj['time'] = p[0];
  75. obj['date'] = p[4];
  76. obj['crc'] = p[6];
  77. nowdam[tot] = obj;
  78. tot++;
  79. });
  80. damcache[cid] = nowdam;
  81. }
  82. });
  83. }
  84. else {
  85. nowdam = damcache[cid];
  86. }
  87. }
  88. function doit(index) {
  89. console.log(nowdam[index]);
  90. setTimeout(updatemenu, 30, index);
  91. }
  92. function updatelevel(crc, uid) {
  93. process[crc]--;
  94. if (lvcache[uid] <= 0)
  95. uidcache[crc].splice(uidcache[crc].indexOf(uid), 1);
  96. if (process[crc] == 0)
  97. render(crc);
  98. }
  99. function levelup(crc, d) {
  100. $.ajax({
  101. url: 'https://space.bilibili.com/ajax/member/GetInfo',
  102. type: "POST",
  103. dataType: 'json',
  104. data: {
  105. mid: d
  106. }, success: function (da) {
  107. if (da.status) {
  108. lvcache[d] = da.data.level_info.current_level;
  109. updatelevel(crc, d);
  110. }
  111. }
  112. }
  113. );
  114. }
  115. function render(crc) {
  116. if (document.getElementById("extd_" + crc) == null) return;
  117. if (uidcache[crc].length == 1) {
  118. document.getElementById("extd_" + crc).innerHTML = "弹幕发送者 " + uidcache[crc][0];
  119. document.getElementById("extd_" + crc).href = "https://space.bilibili.com/" + uidcache[crc][0];
  120. }
  121. if (uidcache[crc].length > 1) {
  122. document.getElementById("extd_" + crc).innerHTML = "弹幕发送者 " + uidcache[crc][uidcache[crc].length - 1];
  123. document.getElementById("extd_" + crc).href = "https://space.bilibili.com/" + uidcache[crc][uidcache[crc].length - 1];
  124. for (var i = uidcache[crc].length - 2; i >= 0; i--) {
  125. document.getElementsByClassName("bilibili-player-context-menu-container")[0].children[0].innerHTML =
  126. "<li class=\"context-line context-menu-function\" data-append=\"1\"><a class=\"context-menu-a js-action\" href=\"https://space.bilibili.com/" + uidcache[crc][i] + "\" data-disabled=\"0\" target=\"_blank\" id=\"ex_extd_" + crc + "\">弹幕发送者 " + uidcache[crc][i] + "</a></li>" +
  127. document.getElementsByClassName("bilibili-player-context-menu-container")[0].children[0].innerHTML;
  128. }
  129. }
  130. }
  131. function updatesender(crc) {
  132. if (crc[0] == 'D') {
  133. document.getElementById("extd_" + crc).innerHTML = "弹幕发送者 游客";
  134. return;
  135. }
  136. if (uidcache.hasOwnProperty(crc)) {
  137. //render
  138. render(crc);
  139. return;
  140. }
  141. if (loaded.hasOwnProperty(crc)) return;
  142. loaded[crc] = 1;
  143. $.ajax(
  144. {
  145. url: "https://pilipili.ml/query/" + crc + ".js",
  146. type: "GET",
  147. cache: true,
  148. dataType: "json",
  149. success: function (data) {
  150. data.sort(function (a, b) { return a < b ? -1 : (a > b); });
  151. for (i = 0; i < data.length; i++)
  152. if (data[i] > 360000000) {
  153. data.splice(i);
  154. }
  155. uidcache[crc] = data;
  156. if (data.length > 1) {
  157. process[crc] = data.length;
  158. for (var i = 0; i < data.length; i++)
  159. levelup(crc, data[i]);
  160. }
  161. else {
  162. render(crc);
  163. }
  164. },
  165. error: function (data) {
  166. document.getElementById("extd_" + crc).innerHTML = "查询失败";
  167. }
  168. }
  169. )
  170. }
  171. function updatemenu(index) {
  172. document.getElementsByClassName("bilibili-player-context-menu-container")[0].children[0].innerHTML =
  173. "<li class=\"context-line context-menu-function\" data-append=\"1\"><a class=\"context-menu-a js-action\" href=\"javascript:;\" data-disabled=\"0\" target=\"_blank\" id=\"extd_" + nowdam[index].crc + "\">弹幕发送者 加载中</a></li>" +
  174. document.getElementsByClassName("bilibili-player-context-menu-container")[0].children[0].innerHTML;
  175. updatesender(nowdam[index].crc);
  176. }
  177. setInterval(getp, 1000);
  178. rebind();
  179. function rebind() {
  180. checker = setInterval(function () {
  181. if (document.getElementsByClassName("bilibili-player-danmaku-list").length > 0) clearInterval(checker);
  182. else return;
  183. document.getElementsByClassName("bilibili-player-danmaku-list")[0].oncontextmenu = function (evt) {
  184. var sbsb = evt.path;
  185. for (var i = 0; i < sbsb.length; i++) {
  186. if (sbsb[i].localName == "li") {
  187. doit(sbsb[i].attributes[0].value);
  188. break;
  189. }
  190. }
  191. }
  192. }, 100);
  193. }
  194. })();