pakku advanced filter

弹幕屏蔽Pro+ (依赖于 pakku≥8.7)

目前为 2018-08-01 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name pakku advanced filter
  3. // @namespace http://s.xmcp.ml/pakkujs/
  4. // @version 0.2.1
  5. // @description 弹幕屏蔽Pro+ (依赖于 pakku≥8.7)
  6. // @author xmcp
  7. // @match *://*.bilibili.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // 请先安装 [pakku](http://s.xmcp.ml/pakkujs/)
  12.  
  13. const NEED_UID=true; // 是否需要使用 cracked_uid 属性(慢)
  14. const NEED_SENDER_INFO=true; // 是否需要使用 sender_info 属性(更慢)
  15. const SILENCE=false; // 加载用户信息时不显示进度条
  16.  
  17. function do_filter(D) {
  18. // 屏蔽规则写在这个函数里
  19.  
  20. return D.filter((d) => {
  21. // const [time, mode, size, color, sendtime, pool, uid_hash, danmaku_id] = d.peers[0].attr;
  22.  
  23. // 示例:仅显示 LV3 以上用户的弹幕
  24. return d.sender_info && d.sender_info.level_info.current_level>=3;
  25.  
  26. /*
  27.  
  28. d = {
  29. "text": "₍₂₎]][[",
  30. "desc": [],
  31. "xml_src": "<d p=\"0.00000,1,25,16777215,1524407489,0,91d6b7d0,4480700090\">₍₂₎]][[</d>",
  32. "peers": [
  33. {
  34. // time, mode, size, color, sendtime, pool, uid_hash, danmaku_id
  35. "attr": ["0.00000", "1", "25", "16777215", "1524407489", "0", "91d6b7d0", "4480700090"],
  36. "time": 0, // === parseFloat(attr[0])
  37. "orig_str": "]][[",
  38. "mode": "1", // === attr[1]
  39. "reason": "ORIG"
  40. },
  41. {
  42. "attr": ["0.00000","1","25","16777215","1524407554","0","91d6b7d0","4480703586"],
  43. "time": 0,
  44. "orig_str": "]]][[[",
  45. "mode": "1",
  46. "reason": "≤2"
  47. }
  48. ],
  49. "cracked_uid": 10119345,
  50. "sender_info": {
  51. "mid": "10119345",
  52. "uname": "xmcp",
  53. "face": "/bfs/face/902415752868028e925cf3ee508a7d6c6d4d57e3.jpg",
  54. "avatar": "http://i2.hdslb.com/bfs/face/902415752868028e925cf3ee508a7d6c6d4d57e3.jpg",
  55. "rank": "10000",
  56. "DisplayRank": "10000",
  57. "sex": "男",
  58. "sign": "pcmx",
  59. "level_info": {
  60. "next_exp": 28800,
  61. "current_level": 5,
  62. "current_min": 10800,
  63. "current_exp": 14392
  64. },
  65. "pendant": {
  66. "pid": 0,
  67. "name": "",
  68. "image": "",
  69. "expire": 0
  70. },
  71. "nameplate": {
  72. "nid": 60,
  73. "name": "
饭圈萌新",
  74. "image": "http://i1.hdslb.com/bfs/face/51ca16136e570938450bca360f28761ceb609f33.png",
  75. "image_small": "http://i2.hdslb.com/bfs/face/9abfa4769357f85937782c2dbc40fafda4f57217.png",
  76. "level": "普通勋章",
  77. "condition": "当前持有粉丝勋章最高等级>=5级"
  78. },
  79. "official_verify": {
  80. "type": -1,
  81. "desc": ""
  82. }
  83. }
  84. }
  85.  
  86. */
  87. });
  88. }
  89.  
  90. (function() {
  91. 'use strict';
  92.  
  93. // https://stackoverflow.com/questions/6832596/how-to-compare-software-version-number-using-js-only-number
  94. function comp_ver(ver1, ver2) {
  95. ver1 = ver1.split('.').map( s => s.padStart(10) ).join('.');
  96. ver2 = ver2.split('.').map( s => s.padStart(10) ).join('.');
  97. return ver1 < ver2;
  98. }
  99. function check_ver(ver) {
  100. if((NEED_SENDER_INFO || NEED_UID) && comp_ver(ver,'8.7'))
  101. alert('按发送者屏蔽弹幕需要 pakku 8.7 或更高版本');
  102. if(SILENCE && comp_ver(ver,'8.7.1'))
  103. alert('隐藏加载进度条需要 pakku 8.7.1 或更高版本');
  104. }
  105.  
  106. let COMPLETED=false;
  107.  
  108. addEventListener('message',function(e) {
  109. if(e.data.type==='pakku_event_danmaku_loaded') {
  110. if(COMPLETED) return;
  111. check_ver(e.data.pakku_version||'0');
  112. if(NEED_SENDER_INFO) {
  113. postMessage({type: 'pakku_get_danmaku_with_info', silence: SILENCE},'*');
  114. } else if(NEED_UID) {
  115. postMessage({type: 'pakku_get_danmaku_with_uid'},'*');
  116. } else {
  117. postMessage({type: 'pakku_get_danmaku'},'*');
  118. }
  119. } else if(e.data.type==='pakku_return_danmaku') {
  120. const D=do_filter(e.data.resp);
  121. console.log('pakku advanced filter: '+D.length+' danmakus left');
  122. let xml='<i>';
  123. D.forEach(d=>{
  124. xml+=d.xml_src;
  125. });
  126. xml+='</i>';
  127. COMPLETED=true;
  128. window.postMessage({type: 'pakku_set_xml_bounce', xml: xml},'*');
  129. }
  130. });
  131. })();