Live Stream Chat Users (Mentions & Search)

Minimalistic userscript that allows you to mention any user in chat by one click on their name or to search for their channel by double or middle click.

  1. // ==UserScript==
  2. // @name Live Stream Chat Users (Mentions & Search)
  3. // @name:ru Пользователи в чате стрима (упоминания и поиск)
  4. // @namespace https://gf.qytechs.cn/en/users/830433-vintprox
  5. // @description Minimalistic userscript that allows you to mention any user in chat by one click on their name or to search for their channel by double or middle click.
  6. // @description:ru Минималистичный пользовательский скрипт, который позволяет упомянуть пользователя в чате при одном лишь клику по его имени, а также производить поиск канала при двойном клике или колёсиком.
  7. // @version 1.1.1
  8. // @icon https://i.postimg.cc/mkQB9T7G/youtube-mentions-userscript.png
  9. // @license MIT
  10. // @author vintprox
  11. // @match https://www.youtube.com/*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. if (location.pathname != "/live_chat") return;
  17.  
  18. const style = document.createElement("style");
  19. style.type = "text/css";
  20. style.appendChild(document.createTextNode(`
  21. #chat #author-name {
  22. cursor: pointer;
  23. }
  24. #chat #author-name:hover {
  25. text-decoration: underline;
  26. }
  27. `));
  28. document.head.appendChild(style);
  29.  
  30. const chat = document.querySelector("#chat");
  31. const inputPanel = document.querySelector("#input-panel");
  32. let input;
  33.  
  34. function updateInput() {
  35. input = inputPanel.querySelector("#input[contenteditable]");
  36. }
  37. updateInput();
  38.  
  39. const inputPanelObserver = new MutationObserver(function (mutations) {
  40. mutations.forEach(function (mutation) {
  41. if (mutation.addedNodes.length) {
  42. updateInput();
  43. }
  44. });
  45. });
  46. inputPanelObserver.observe(inputPanel, { childList: true });
  47.  
  48. function searchChannel(e) {
  49. if (e.target.id != "author-name") return;
  50.  
  51. e.preventDefault();
  52. window.open(`https://www.youtube.com/results?search_query="${encodeURI(e.target.innerText)}"&sp=CAASAhAC`);
  53. }
  54.  
  55. chat.addEventListener("click", function (e) {
  56. if (e.detail > 1) return;
  57. if (e.target.id != "author-name") return;
  58.  
  59. const mention = `@${e.target.innerText}\xa0`;
  60. input.innerText = mention + input.innerText;
  61. input.dispatchEvent(new Event("input"));
  62. setTimeout(() => {
  63. input.click();
  64. input.focus();
  65. }, 150);
  66.  
  67. const range = document.createRange();
  68. range.setStart(input, 1);
  69. range.collapse(true);
  70. const selection = window.getSelection();
  71. selection.removeAllRanges();
  72. selection.addRange(range);
  73. });
  74.  
  75. chat.addEventListener("dblclick", searchChannel.bind(chat));
  76. chat.addEventListener("auxclick", searchChannel.bind(chat));
  77. })();

QingJ © 2025

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