youutbeらいぶ#を追加

・。・→#・。・

目前为 2024-12-24 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name youutbeらいぶ#を追加
  3. // @license MIT
  4. // @namespace http://tampermonkey.net/
  5. // @version 1.3
  6. // @description ・。・→#・。・
  7. // @author You
  8. // @match https://www.youtube.com/live_chat*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // エンターキーが押されたときに実行する処理
  16. document.addEventListener('keydown', function (event) {
  17. // エンターキーが押された場合
  18. if (event.key === 'Enter') {
  19. console.log("Enter key pressed");
  20. // 現在フォーカスされている要素を取得(コメント入力欄)
  21. const activeElement = document.activeElement;
  22. console.log("Active element:", activeElement);
  23.  
  24. // コメント入力欄かどうかを確認
  25. if (activeElement && activeElement.tagName === 'DIV' && activeElement.contentEditable === 'true') {
  26. console.log("Detected input field");
  27. event.preventDefault(); // エンターキーのデフォルト動作を無効化
  28.  
  29. // 入力されたテキストを取得
  30. const currentText = activeElement.innerText;
  31. console.log("Current text:", currentText);
  32.  
  33. // コメントが空の場合は何もしない
  34. if (!currentText.trim()) {
  35. console.log("Empty comment, skipping...");
  36. return;
  37. }
  38.  
  39. // コメントの先頭に「#」を追加(すでに「#」があればそのまま)
  40. if (!currentText.startsWith('#')) {
  41. activeElement.innerText = `#${currentText}`;
  42.  
  43. // **inputイベントを手動で発生させて変更を通知**
  44. const inputEvent = new Event('input', { bubbles: true });
  45. activeElement.dispatchEvent(inputEvent);
  46. }
  47.  
  48. // 少し待機してから送信
  49. setTimeout(() => {
  50. // コメントを送信するボタンを探す
  51. const sendButton = document.querySelector(
  52. 'yt-live-chat-message-input-renderer #send-button button'
  53. );
  54.  
  55. // コメント送信ボタンが存在する場合はクリック
  56. if (sendButton) {
  57. console.log("Send button found, clicking...");
  58. sendButton.click();
  59. } else {
  60. console.error('送信ボタンが見つかりませんでした。');
  61. }
  62. }, 5); // 100ms待機
  63. }
  64. }
  65. });
  66. })();

QingJ © 2025

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