Microsoft Teams - Toggle Sidebar + Expand Message Pane

Add toggle buttons to hide the Chat/Teams sidebar and also expand the message pane

目前为 2024-09-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Microsoft Teams - Toggle Sidebar + Expand Message Pane
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.0
  5. // @description Add toggle buttons to hide the Chat/Teams sidebar and also expand the message pane
  6. // @author D365Fixes
  7. // @license MIT
  8. // @match https://teams.microsoft.com/v2/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=teams.microsoft.com
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. "use strict";
  15.  
  16. const styles = `
  17. .hide-sub-nav div[data-tid="experience-layout"] {
  18. --sub-nav-width: 0rem !important;
  19. }
  20.  
  21. .hide-sub-nav div[data-tid="app-layout-area--sub-nav"] {
  22. opacity: 0;
  23. visibility: hidden;
  24. }
  25.  
  26. .expand-msg-pane div[data-tid="message-pane-list-runway"], .expand-msg-pane div[data-tid="message-pane-footer"] {
  27. max-width: 80vw;
  28. }
  29.  
  30. div[data-tid="experience-layout"], div[data-tid^="app-layout-area"], div[data-tid="app-layout-area--sub-nav"] {
  31. transition: all .25s ease-in-out !important;
  32. transition-delay: unset !important;
  33. }
  34.  
  35. #toggle-sidebar-btn, #expand-msg-pane-btn {
  36. background-color: transparent;
  37. color: #fff;
  38. display: flex;
  39. align-items: center;
  40. justify-content: center;
  41. font-size: 20px;
  42. line-height: 1;
  43. width: 36px;
  44. height: 36px;
  45. padding: 5px;
  46. margin-left: 10px;
  47. border: 0;
  48. cursor: pointer;
  49. }
  50. `;
  51.  
  52. function injectStyles() {
  53. const styleElement = document.createElement("style");
  54. styleElement.appendChild(document.createTextNode(styles));
  55. document.head.appendChild(styleElement);
  56. }
  57.  
  58. function createSVGIcon(collapse) {
  59. const svgNS = "http://www.w3.org/2000/svg";
  60. const svg = document.createElementNS(svgNS, "svg");
  61. svg.setAttribute("xmlns", svgNS);
  62. svg.setAttribute("width", "24");
  63. svg.setAttribute("height", "24");
  64. svg.setAttribute("fill", "currentColor");
  65. svg.setAttribute("aria-hidden", "true");
  66.  
  67. const path = document.createElementNS(svgNS, "path");
  68. const d = collapse
  69. ? "m13.1 11.3 1.4-1.2c.3-.3.3-.7.1-1s-.7-.3-1-.1l-2.8 2.4c-.3.2-.3.7-.1 1 0 0 0 .1.1.1l2.8 2.4c.3.3.7.2 1-.1.3-.3.2-.7-.1-1l-1.4-1.2h5.1c.4 0 .7-.3.7-.7 0-.4-.3-.7-.7-.7h-5.1zM2.2 20.2h19.6c.7 0 1.2-.5 1.2-1.2V5c0-.7-.5-1.2-1.2-1.2H2.2C1.5 3.8 1 4.3 1 5v14c0 .7.5 1.2 1.2 1.2zm.2-1.9V5.7c0-.3.3-.6.6-.6h4.9v13.8H3c-.4 0-.6-.3-.6-.6zm6.8.6V5.1H21c.3 0 .6.3.6.6v12.5c0 .3-.3.6-.6.6H9.2z"
  70. : "M16.4 12.7 15 13.9c-.3.3-.3.7-.1 1 .3.3.7.3 1 .1l2.8-2.4c.3-.2.3-.7.1-1 0 0 0-.1-.1-.1l-2.8-2.4c-.3-.3-.7-.2-1 .1-.3.3-.2.7.1 1l1.4 1.2h-5.1c-.4 0-.7.3-.7.7 0 .4.3.7.7.7h5.1zM2.2 20.2h19.6c.7 0 1.2-.5 1.2-1.2V5c0-.7-.5-1.2-1.2-1.2H2.2C1.5 3.8 1 4.3 1 5v14c0 .7.5 1.2 1.2 1.2zm.2-1.9V5.7c0-.3.3-.6.6-.6h4.9v13.8H3c-.4 0-.6-.3-.6-.6zm6.8.6V5.1H21c.3 0 .6.3.6.6v12.5c0 .3-.3.6-.6.6H9.2z";
  71.  
  72. path.setAttribute("d", d);
  73. path.setAttribute("fill", "currentColor");
  74.  
  75. svg.appendChild(path);
  76.  
  77. return svg;
  78. }
  79.  
  80. function createMessagePaneSVGIcon(expanded) {
  81. const svgNS = "http://www.w3.org/2000/svg";
  82. const svg = document.createElementNS(svgNS, "svg");
  83. svg.setAttribute("xmlns", svgNS);
  84. svg.setAttribute("width", "24");
  85. svg.setAttribute("height", "24");
  86. svg.setAttribute("fill", "currentColor");
  87. svg.setAttribute("aria-hidden", "true");
  88.  
  89. const path = document.createElementNS(svgNS, "path");
  90. const d = expanded
  91. ? "m16.4 12.7 1.4 1.2c.3.3.3.7.1 1-.3.3-.7.3-1 .1l-2.8-2.4c-.3-.2-.3-.7-.1-1 0 0 0-.1.1-.1l2.8-2.4c.3-.3.7-.2 1 .1.3.3.2.7-.1 1l-1.4 1.2h5.1c.4 0 .7.3.7.7s-.3.7-.7.7h-5.1v-.1zM7.6 12.7l-1.4 1.2c-.3.3-.3.7-.1 1 .3.3.7.3 1 .1l2.8-2.4c.3-.2.3-.7.1-1 0 0 0-.1-.1-.1L7.1 9.1c-.3-.3-.7-.2-1 .1s-.2.7.1 1l1.4 1.2H2.5c-.4 0-.7.3-.7.7s.3.7.7.7h5.1v-.1zM2 2h20v2H2M2 6h20v2H2M2 16h20v2H2M2 20h20v2H2"
  92. : "m19.6 12.7-1.4 1.2c-.3.3-.3.7-.1 1 .3.3.7.3 1 .1l2.8-2.4c.3-.2.3-.7.1-1 0 0 0-.1-.1-.1l-2.8-2.4c-.3-.3-.7-.2-1 .1-.3.3-.2.7.1 1l1.4 1.2h-5.1c-.4 0-.7.3-.7.7s.3.7.7.7h5.1v-.1zM4.4 12.7l1.4 1.2c.3.3.3.7.1 1-.3.3-.7.3-1 .1l-2.8-2.4c-.3-.2-.3-.7-.1-1 0 0 0-.1.1-.1l2.8-2.4c.3-.3.7-.2 1 .1s.2.7-.1 1l-1.4 1.2h5.1c.4 0 .7.3.7.7s-.3.7-.7.7H4.4v-.1zM2 2h20v2H2M2 6h20v2H2M2 16h20v2H2M2 20h20v2H2";
  93.  
  94. path.setAttribute("d", d);
  95. path.setAttribute("fill", "currentColor");
  96.  
  97. svg.appendChild(path);
  98.  
  99. return svg;
  100. }
  101.  
  102. function addToggleButton() {
  103. const waitForTitlebarStartSlot = window.setInterval(function() {
  104. const titlebarSlot = document.querySelector('div[data-tid="titlebar-start-slot"]');
  105. if (titlebarSlot) {
  106. window.clearInterval(waitForTitlebarStartSlot);
  107.  
  108. const toggleButton = document.createElement("button");
  109. toggleButton.id = "toggle-sidebar-btn";
  110.  
  111. let sidebarOpen = true;
  112.  
  113. toggleButton.appendChild(createSVGIcon(sidebarOpen));
  114.  
  115. toggleButton.addEventListener("click", function() {
  116. sidebarOpen = !sidebarOpen;
  117.  
  118. while (toggleButton.firstChild) {
  119. toggleButton.removeChild(toggleButton.firstChild);
  120. }
  121.  
  122. toggleButton.appendChild(createSVGIcon(sidebarOpen));
  123.  
  124. document.body.classList.toggle("hide-sub-nav");
  125. });
  126.  
  127. titlebarSlot.appendChild(toggleButton);
  128.  
  129. const expandButton = document.createElement("button");
  130. expandButton.id = "expand-msg-pane-btn";
  131.  
  132. let messagePaneExpanded = false;
  133.  
  134. expandButton.appendChild(createMessagePaneSVGIcon(messagePaneExpanded));
  135.  
  136. expandButton.addEventListener("click", function() {
  137. messagePaneExpanded = !messagePaneExpanded;
  138.  
  139. while (expandButton.firstChild) {
  140. expandButton.removeChild(expandButton.firstChild);
  141. }
  142.  
  143. expandButton.appendChild(createMessagePaneSVGIcon(messagePaneExpanded));
  144.  
  145. document.body.classList.toggle("expand-msg-pane");
  146. });
  147.  
  148. titlebarSlot.appendChild(expandButton);
  149. }
  150. }, 300);
  151. }
  152.  
  153. document.addEventListener("DOMContentLoaded", function() {
  154. injectStyles();
  155. addToggleButton();
  156. });
  157. })();