原神玩家指示器

B站评论区自动标注原神玩家,依据是动态里是否有原神相关内容(0.6一些小的修改)

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

  1. // ==UserScript==
  2. // @name 原神玩家指示器
  3. // @namespace www.cber.ltd
  4. // @version 0.6
  5. // @description B站评论区自动标注原神玩家,依据是动态里是否有原神相关内容(0.6一些小的修改)
  6. // @author xulaupuz
  7. // @match https://www.bilibili.com/video/*
  8. // @icon https://static.hdslb.com/images/favicon.ico
  9. // @connect bilibili.com
  10. // @grant GM_xmlhttpRequest
  11. // @license MIT
  12. // @run-at document-end
  13. // ==/UserScript==
  14.  
  15.  
  16. (function() {
  17. 'use strict';
  18. const unknown = new Set()
  19. const yuanyou = new Set()
  20. const no_yuanyou = new Set()
  21.  
  22. const keyword = "原神" // 可以自行修改,如"#原神","明日方舟"
  23. const tag = " |原神玩家|"
  24. const blog = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?&host_mid='
  25. const is_new = document.getElementsByClassName('item goback').length != 0 // 检测是不是新版
  26.  
  27. const get_pid = (c) => {
  28. if (is_new) {
  29. return c.dataset['userId']
  30. } else {
  31. return c.children[0]['href'].replace(/[^\d]/g, "")
  32. }
  33. }
  34.  
  35. const get_comment_list = () => {
  36. if (is_new) {
  37. let lst = new Set()
  38. for (let c of document.getElementsByClassName('user-name')) {
  39. lst.add(c)
  40. }
  41. for (let c of document.getElementsByClassName('sub-user-name')) {
  42. lst.add(c)
  43. }
  44. return lst
  45. } else {
  46. return document.getElementsByClassName('user')
  47. }
  48. }
  49.  
  50. console.log(is_new)
  51.  
  52. console.log("正常加载")
  53. let jiance = setInterval(()=>{
  54. let commentlist = get_comment_list()
  55. if (commentlist.length != 0){
  56. // clearInterval(jiance)
  57. commentlist.forEach(c => {
  58. let pid = get_pid(c)
  59. if (yuanyou.has(pid)) {
  60. if (c.textContent.includes(tag) === false) {
  61. c.append(tag)
  62. }
  63. return
  64. } else if (no_yuanyou.has(pid)) {
  65. // do nothing
  66. return
  67. }
  68. unknown.add(pid)
  69. //console.log(pid)
  70. let blogurl = blog + pid
  71. // let xhr = new XMLHttpRequest()
  72. GM_xmlhttpRequest({
  73. method: "get",
  74. url: blogurl,
  75. data: '',
  76. headers: {
  77. 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
  78. },
  79. onload: function(res){
  80. if(res.status === 200){
  81. //console.log('成功')
  82. let st = JSON.stringify(JSON.parse(res.response).data)
  83. unknown.delete(pid)
  84. if (st.includes(keyword)){
  85. c.append(tag)
  86. yuanyou.add(pid)
  87. } else {
  88. no_yuanyou.add(pid)
  89. }
  90. }else{
  91. console.log('失败')
  92. console.log(res)
  93. }
  94. },
  95. });
  96. });
  97. }
  98. }, 4000)
  99. })();