Youtube LiveChat Modification

Youtube直播分離聊天室調整

目前為 2024-01-15 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Youtube LiveChat Modification
  3. // @namespace https://github.com/RutsuLun
  4. // @version 0.1
  5. // @description Youtube直播分離聊天室調整
  6. // @author Rutsu Lun
  7. // @match https://www.youtube.com/live_chat?*
  8. // @icon https://www.google.com/s2/favicons?domain=youtube.com
  9. // @license Only Share
  10. // @grant GM.registerMenuCommand
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. GM.registerMenuCommand('呼叫', Lun_createBtnList);
  15. GM.registerMenuCommand('表符調整', Lun_removeEmojiTag);
  16. GM.registerMenuCommand('移除愛心', hideShitHard);
  17. })();
  18.  
  19. const btnListSetting = [
  20. { id: 'Lun_emojiMenuChenge', name: '移除愛心', method: hideShitHard, },
  21. { id: 'Lun_removeEmojiTag', name: '表符調整', method: Lun_removeEmojiTag }
  22. ]
  23. const btnListCss = 'position: fixed; top: 0; right: 40px;'
  24.  
  25. function Lun_removeEmojiTag() {
  26. document.querySelector('#search-panel')?document.querySelector('#search-panel').remove():'';
  27. document.querySelector('#category-buttons')?document.querySelector('#category-buttons').remove():'';
  28. document.querySelector('yt-emoji-picker-renderer').style.cssText += 'margin: 0 -24px;';
  29. document.getElementById('categories').querySelector('yt-emoji-picker-category-renderer').querySelectorAll('img.yt-emoji-picker-category-renderer').forEach(el => {
  30. el.style.cssText += 'width: 36px;height: 36px;'
  31. })
  32. }
  33.  
  34. function Lun_emojiMenuChenge() {
  35. const iframe = document.getElementById('chatframe');
  36. if (iframe.contentDocument) {
  37. var iframeDocument = iframe.contentDocument;
  38. var targetElement = iframeDocument.querySelector('yt-emoji-picker-renderer[floating-emoji-picker]');
  39. targetElement.style.cssText = 'min-height: 400px';
  40. }
  41. }
  42.  
  43. function hideShitHard() {
  44. document.querySelector('#reaction-control-panel').remove()
  45. }
  46.  
  47. function Lun_createBtnList() {
  48. if (document.querySelector('Lun_btnList') == null) {
  49. const btnList = document.createElement('span');
  50. btnList.id = 'Lun_btnList';
  51. btnList.style = btnListCss;
  52. document.body.append(btnList);
  53. btnListSetting.forEach(b => {
  54. let btn = document.createElement('button');
  55. btn.id = b.id;
  56. btn.innerText = b.name;
  57. btnList.append(btn);
  58. btn.addEventListener('click', b.method);
  59. });
  60. }
  61. }
  62.  
  63. const main = function () {
  64. Lun_createBtnList();
  65. }
  66.  
  67. const injectScript = function (frameWindow) {
  68. main()
  69. }
  70.  
  71. const retrieveChatFrameWindow = function () {
  72. if (window.location.pathname === "/live_chat" || window.location.pathname === "/live_chat_replay") return window;
  73. for (let i = 0; i < window.frames.length; i++) {
  74. try {
  75. if (window.frames[i].location) {
  76. let pathname = window.frames[i].location.pathname;
  77. if (pathname === "/live_chat" || pathname === "/live_chat_replay") return frames[i];
  78. }
  79. } catch (ex) { }
  80. }
  81. }
  82.  
  83. const tryBrowserIndependentExecution = function () {
  84. let destinationFrameWindow = retrieveChatFrameWindow();
  85. if (!destinationFrameWindow || !destinationFrameWindow.document || destinationFrameWindow.document.readyState != "complete") {
  86. setTimeout(tryBrowserIndependentExecution, 1000);
  87. return;
  88. }
  89. if (destinationFrameWindow.channelResolverInitialized) return;
  90. injectScript(destinationFrameWindow);
  91. destinationFrameWindow.channelResolverInitialized = true;
  92. }
  93.  
  94. tryBrowserIndependentExecution();

QingJ © 2025

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