原神玩家指示器(自用)

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

  1. // ==UserScript==
  2. // @name 原神玩家指示器(自用)
  3. // @namespace www.cber.ltd
  4. // @version 0.7
  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 keyword_match = {
  25. "原神": " |原神玩家|",
  26. "崩坏": " |崩坏玩家|"
  27. };
  28.  
  29.  
  30. const blog = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?&host_mid='
  31. const is_new = document.getElementsByClassName('item goback').length != 0 // 检测是不是新版
  32.  
  33. const get_pid = (c) => {
  34. if (is_new) {
  35. return c.dataset['userId']
  36. } else {
  37. return c.children[0]['href'].replace(/[^\d]/g, "")
  38. }
  39. }
  40.  
  41. const get_comment_list = () => {
  42. if (is_new) {
  43. let lst = new Set()
  44. for (let c of document.getElementsByClassName('user-name')) {
  45. lst.add(c)
  46. }
  47. for (let c of document.getElementsByClassName('sub-user-name')) {
  48. lst.add(c)
  49. }
  50. return lst
  51. } else {
  52. return document.getElementsByClassName('user')
  53. }
  54. }
  55.  
  56. console.log(is_new)
  57.  
  58. console.log("正常加载")
  59. let jiance = setInterval(() => {
  60. let commentlist = get_comment_list()
  61. if (commentlist.length != 0) {
  62. // clearInterval(jiance)
  63. commentlist.forEach(c => {
  64. let pid = get_pid(c)
  65. if (yuanyou.has(pid)) {
  66. if (c.textContent.includes(tag) === false) {
  67. c.append(tag)
  68. }
  69. return
  70. } else if (no_yuanyou.has(pid)) {
  71. // do nothing
  72. return
  73. }
  74. unknown.add(pid)
  75. //console.log(pid)
  76. let blogurl = blog + pid
  77. // let xhr = new XMLHttpRequest()
  78. GM_xmlhttpRequest({
  79. method: "get",
  80. url: blogurl,
  81. data: '',
  82. headers: {
  83. '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'
  84. },
  85. onload: function (res) {
  86. if (res.status === 200) {
  87. //console.log('成功')
  88. let st = JSON.stringify(JSON.parse(res.response).data)
  89. unknown.delete(pid)
  90. for (var prop in keyword_match) {
  91. // console.log(prop + " = " + keyword_match[prop]);
  92. if (st.includes(prop)) {
  93. c.append(keyword_match[prop]);
  94. yuanyou.add(pid);
  95. } else {
  96. no_yuanyou.add(pid);
  97. }
  98. }
  99. // if (st.includes(keyword)) {
  100. // c.append(tag)
  101. // yuanyou.add(pid)
  102. // } else {
  103. // no_yuanyou.add(pid)
  104. // }
  105. } else {
  106. console.log('失败')
  107. console.log(res)
  108. }
  109. },
  110. });
  111. });
  112. }
  113. }, 4000)
  114. })();

QingJ © 2025

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