Youtube Interface Modification

將聊天室與直播位置切換

目前為 2023-12-08 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Youtube Interface Modification
  3. // @namespace https://github.com/RutsuLun
  4. // @version 1.0
  5. // @description 將聊天室與直播位置切換
  6. // @author Rutsu Lun
  7. // @match https://www.youtube.com/watch?*
  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_loayoutSwitch);
  16. GM.registerMenuCommand('emoji調整', Lun_removeEmojiTag);
  17. GM.registerMenuCommand('移除愛心', hideShitHard);
  18. GM.registerMenuCommand('表符', Lun_emojiMenuChenge);
  19. })();
  20.  
  21. function Lun_loayoutSwitch() {
  22. document.getElementById('columns').style.cssText == '' ? document.getElementById('columns').style.cssText = 'flex-direction: row-reverse;' : document.getElementById('columns').style.cssText = '';
  23. document.querySelector('ytd-player').style.cssText += 'border-radius: 0;'
  24. }
  25.  
  26. function Lun_removeEmojiTag() {
  27. const iframe = document.getElementById('chatframe');
  28. if (iframe.contentDocument) {
  29. var iframeDocument = iframe.contentDocument;
  30. var category = iframeDocument.getElementById('category-buttons');
  31. var search = iframeDocument.getElementById('search-panel');
  32. var emoji = iframeDocument.querySelector('yt-emoji-picker-renderer');
  33. category.style.cssText += 'display:none;'
  34. search.style.cssText += 'display:none;'
  35. emoji.style.cssText += 'margin: -5px -24px !important'
  36. }
  37. }
  38.  
  39. function Lun_emojiMenuChenge() {
  40. const iframe = document.getElementById('chatframe');
  41. if (iframe.contentDocument) {
  42. var iframeDocument = iframe.contentDocument;
  43. var targetElement = iframeDocument.querySelector('yt-emoji-picker-renderer[floating-emoji-picker]');
  44. targetElement.style.cssText = 'min-height: 400px';
  45. }
  46. }
  47.  
  48. function hideShitHard() {
  49. const iframe = document.getElementById('chatframe');
  50. if (iframe.contentDocument) {
  51. var iframeDocument = iframe.contentDocument;
  52. var targetElement = iframeDocument.querySelector('#reaction-control-panel');
  53. targetElement.style.cssText = 'display:none;'
  54. }
  55. }
  56.  
  57. function Lun_createBtnList() {
  58. const btnListSetting = [
  59. { id: 'Lun_loayoutSwitch', name: '介面', method: Lun_loayoutSwitch, },
  60. { id: 'Lun_emojiMenuChenge', name: '表符', method: Lun_removeEmojiTag, },
  61. { id: 'Lun_emojiMenuChenge', name: '移除愛心', method: hideShitHard, },
  62. ]
  63. const iframe = document.getElementById('chatframe');
  64. if (iframe.contentDocument) {
  65. var iframeDocument = iframe.contentDocument;
  66. var buttons = iframeDocument.getElementById('buttons');
  67. var targetElement = buttons.querySelector('#picker-buttons');
  68. if (targetElement.querySelector('Lun_btnList') == null) {
  69. var btnList = iframeDocument.createElement('span');
  70. btnList.id = 'Lun_btnList';
  71. targetElement.append(btnList);
  72. btnListSetting.forEach(b => {
  73. let btn = document.createElement('button');
  74. btn.id = b.id;
  75. btn.innerText = b.name;
  76. btnList.append(btn);
  77. btn.addEventListener('click', b.method);
  78. });
  79. }
  80. }
  81. }
  82.  
  83. const main = function () {
  84. // Lun_emojiMenuChenge();
  85. console.log('載入完畢');
  86. //Lun_createBtnList();
  87. }
  88.  
  89. const injectScript = function (frameWindow) {
  90. main()
  91. }
  92.  
  93. const retrieveChatFrameWindow = function () {
  94. if (window.location.pathname === "/live_chat" || window.location.pathname === "/live_chat_replay") return window;
  95. for (let i = 0; i < window.frames.length; i++) {
  96. try {
  97. if (window.frames[i].location) {
  98. let pathname = window.frames[i].location.pathname;
  99. if (pathname === "/live_chat" || pathname === "/live_chat_replay") return frames[i];
  100. }
  101. } catch (ex) { }
  102. }
  103. }
  104.  
  105. const tryBrowserIndependentExecution = function () {
  106. let destinationFrameWindow = retrieveChatFrameWindow();
  107. if (!destinationFrameWindow || !destinationFrameWindow.document || destinationFrameWindow.document.readyState != "complete") {
  108. setTimeout(tryBrowserIndependentExecution, 1000);
  109. return;
  110. }
  111. if (destinationFrameWindow.channelResolverInitialized) return;
  112. injectScript(destinationFrameWindow);
  113. destinationFrameWindow.channelResolverInitialized = true;
  114. }
  115.  
  116. if (ytInitialPlayerResponse.videoDetails.isLiveContent) {
  117. console.log('直播')
  118. tryBrowserIndependentExecution();
  119. } else {
  120. console.log('正常影片')
  121. }

QingJ © 2025

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