华为用户指示器

B站评论区自动标注华为用户,依据是动态里是否有华为相关内容(基于原神玩家指示器0.6)

  1. // ==UserScript==
  2. // @name 华为用户指示器
  3. // @namespace carbodrake
  4. // @version 0.11
  5. // @description B站评论区自动标注华为用户,依据是动态里是否有华为相关内容(基于原神玩家指示器0.6)
  6. // @author carbodrake
  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. (function() {
  15. 'use strict';
  16. const unknown = new Set()
  17. const yuanyou = new Set()
  18. const no_yuanyou = new Set()
  19. const keyword = "华为" // 可以自行修改,如"#原神","明日方舟"
  20. const tag = " |华为用户|"
  21. const blog = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?&host_mid='
  22. const is_new = document.getElementsByClassName('item goback').length != 0 // 检测是不是新版
  23. const get_pid = (c) => {
  24. if (is_new) {
  25. return c.dataset['userId']
  26. } else {
  27. return c.children[0]['href'].replace(/[^\d]/g, "")
  28. }
  29. }
  30. const get_comment_list = () => {
  31. if (is_new) {
  32. let lst = new Set()
  33. for (let c of document.getElementsByClassName('user-name')) {
  34. lst.add(c)
  35. }
  36. for (let c of document.getElementsByClassName('sub-user-name')) {
  37. lst.add(c)
  38. }
  39. return lst
  40. } else {
  41. return document.getElementsByClassName('user')
  42. }
  43. }
  44. console.log(is_new)
  45. console.log("正常加载")
  46. let jiance = setInterval(()=>{
  47. let commentlist = get_comment_list()
  48. if (commentlist.length != 0){
  49. // clearInterval(jiance)
  50. commentlist.forEach(c => {
  51. let pid = get_pid(c)
  52. if (yuanyou.has(pid)) {
  53. if (c.textContent.includes(tag) === false) {
  54. c.append(tag)
  55. }
  56. return
  57. } else if (no_yuanyou.has(pid)) {
  58. // do nothing
  59. return
  60. }
  61. unknown.add(pid)
  62. //console.log(pid)
  63. let blogurl = blog + pid
  64. // let xhr = new XMLHttpRequest()
  65. GM_xmlhttpRequest({
  66. method: "get",
  67. url: blogurl,
  68. data: '',
  69. headers: {
  70. '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'
  71. },
  72. onload: function(res){
  73. if(res.status === 200){
  74. //console.log('成功')
  75. let st = JSON.stringify(JSON.parse(res.response).data)
  76. unknown.delete(pid)
  77. if (st.includes(keyword)){
  78. c.append(tag)
  79. yuanyou.add(pid)
  80. } else {
  81. no_yuanyou.add(pid)
  82. }
  83. }else{
  84. console.log('失败')
  85. console.log(res)
  86. }
  87. },
  88. });
  89. });
  90. }
  91. }, 4000)
  92. })();

QingJ © 2025

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