Youtube Interface Modification

Youtube聊天室與直播位置切換

当前为 2024-04-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube Interface Modification
  3. // @namespace https://github.com/RutsuLun
  4. // @version 1.6
  5. // @description Youtube聊天室與直播位置切換
  6. // @author Rutsu Lun
  7. // @match https://www.youtube.com/watch?*
  8. // @match https://www.youtube.com/live_chat?*
  9. // @icon https://www.google.com/s2/favicons?domain=youtube.com
  10. // @license Only Share
  11. // @grant GM.registerMenuCommand
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. if (location.search.includes('is_popout=1')) {
  16. GM.registerMenuCommand('彈出式呼叫', pop_createBtnList);
  17. GM.registerMenuCommand('彈出式調整', pop_removePopChat);
  18. } else {
  19. GM.registerMenuCommand('呼叫', Lun_createBtnList);
  20. GM.registerMenuCommand('介面', Lun_loayoutSwitch);
  21. GM.registerMenuCommand('emoji調整', Lun_removeEmojiTag);
  22. GM.registerMenuCommand('移除愛心', hideShitHard);
  23. }
  24. })();
  25.  
  26. const btnListSetting = [
  27. { id: 'Lun_loayoutSwitch', name: '介面', method: Lun_loayoutSwitch, },
  28. { id: 'Lun_removeEmojiTag', name: '表符', method: Lun_removeEmojiTag, },
  29. { id: 'Lun_emojiMenuChenge', name: '移除愛心', method: hideShitHard, },
  30. ]
  31. const pop_btnListSetting = [
  32. { id: 'pop_removePopChat', name: '彈出式調整', method: pop_removePopChat, },
  33. ]
  34. const btnListCss = 'position: absolute;top: 0;left: 0;'
  35. const pop_btnListCss = 'position: absolute;top: 0;right: 0;'
  36.  
  37. function Lun_loayoutSwitch() {
  38. document.getElementById('columns').style.cssText == '' ? document.getElementById('columns').style.cssText = 'flex-direction: row-reverse;' : document.getElementById('columns').style.cssText = '';
  39. document.querySelector('ytd-player').style.cssText += 'border-radius: 0;'
  40. }
  41.  
  42. function Lun_removeEmojiTag() {
  43. const iframe = document.getElementById('chatframe');
  44. if (iframe.contentDocument) {
  45. var iframeDocument = iframe.contentDocument;
  46. var category = iframeDocument.getElementById('category-buttons');
  47. var search = iframeDocument.getElementById('search-panel');
  48. var emoji = iframeDocument.querySelector('yt-emoji-picker-renderer');
  49. category.style.cssText += 'display:none;'
  50. search.style.cssText += 'display:none;'
  51. emoji.style.cssText += 'margin: -5px -24px !important'
  52. }
  53. }
  54.  
  55. function Lun_emojiMenuChenge() {
  56. const iframe = document.getElementById('chatframe');
  57. if (iframe.contentDocument) {
  58. var iframeDocument = iframe.contentDocument;
  59. var targetElement = iframeDocument.querySelector('yt-emoji-picker-renderer[floating-emoji-picker]');
  60. targetElement.style.cssText = 'min-height: 400px';
  61. }
  62. }
  63.  
  64. function hideShitHard() {
  65. const iframe = document.getElementById('chatframe');
  66. if (iframe.contentDocument) {
  67. var iframeDocument = iframe.contentDocument;
  68. var targetElement = iframeDocument.querySelector('#reaction-control-panel');
  69. targetElement.style.cssText = 'display:none;'
  70. }
  71. }
  72.  
  73. function Lun_createBtnList() {
  74. const chat = document.getElementById('secondary');
  75. const chat2 = document.getElementById('below');
  76. if (chat && document.querySelector('Lun_btnList') == null) {
  77. const btnList = document.createElement('span');
  78. btnList.id = 'Lun_btnList';
  79. btnList.style = btnListCss;
  80. chat.append(btnList);
  81. chat2.append(btnList);
  82. btnListSetting.forEach(b => {
  83. let btn = document.createElement('button');
  84. btn.id = b.id;
  85. btn.innerText = b.name;
  86. btnList.append(btn);
  87. btn.addEventListener('click', b.method);
  88. });
  89. }
  90. }
  91.  
  92. function pop_createBtnList() {
  93. const btnList = document.createElement('span');
  94. btnList.id = 'btnList'
  95. btnList.style = pop_btnListCss;
  96. pop_btnListSetting.forEach(b => {
  97. let btn = document.createElement('button');
  98. btn.id = b.id;
  99. btn.innerText = b.name;
  100. btnList.append(btn);
  101. btn.addEventListener('click', b.method);
  102. })
  103. document.body.append(btnList)
  104. }
  105.  
  106. function pop_removePopChat() {
  107. document.querySelector('#reaction-control-panel').style.cssText = 'display:none;';
  108. document.querySelector('#search-panel').style.cssText = 'display:none;';
  109. document.querySelector('#category-buttons').style.cssText = 'display:none;';
  110. }
  111.  
  112. const main = function () {
  113. console.log('載入完畢');
  114. if (location.search.includes('is_popout=1')) {
  115. pop_createBtnList();
  116. } else {
  117. Lun_createBtnList();
  118. }
  119. }
  120.  
  121. const injectScript = function (frameWindow) {
  122. main()
  123. }
  124.  
  125. const retrieveChatFrameWindow = function () {
  126. if (window.location.pathname === "/live_chat" || window.location.pathname === "/live_chat_replay") return window;
  127. for (let i = 0; i < window.frames.length; i++) {
  128. try {
  129. if (window.frames[i].location) {
  130. let pathname = window.frames[i].location.pathname;
  131. if (pathname === "/live_chat" || pathname === "/live_chat_replay") return frames[i];
  132. }
  133. } catch (ex) { }
  134. }
  135. }
  136.  
  137. const tryBrowserIndependentExecution = function () {
  138. let destinationFrameWindow = retrieveChatFrameWindow();
  139. if (!destinationFrameWindow || !destinationFrameWindow.document || destinationFrameWindow.document.readyState != "complete") {
  140. setTimeout(tryBrowserIndependentExecution, 1000);
  141. return;
  142. }
  143. if (destinationFrameWindow.channelResolverInitialized) return;
  144. injectScript(destinationFrameWindow);
  145. destinationFrameWindow.channelResolverInitialized = true;
  146. }
  147.  
  148. if (ytInitialPlayerResponse.videoDetails.isLiveContent && !location.search.includes('is_popout=1')) {
  149. console.log('直播');
  150. tryBrowserIndependentExecution();
  151. } else if (location.search.includes('is_popout=1')) {
  152. console.log('彈出式聊天室');
  153. pop_createBtnList();
  154. } else {
  155. console.log('正常影片');
  156. Lun_createBtnList();
  157. }

QingJ © 2025

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