Change Telegram web page elements

Move the Telegram chat bubble to the left and hide the "All Chats" button

  1. // ==UserScript==
  2. // @name Change Telegram web page elements
  3. // @namespace https://greasyfork.org/zh-CN/users/737511
  4. // @description Move the Telegram chat bubble to the left and hide the "All Chats" button
  5. // @version 0.4
  6. // @icon https://gcore.jsdelivr.net/gh/Bush2021/img-hosting@main/Icons/Telegram.svg
  7. // @author Bush2021
  8. // @match https://web.telegram.org/k/*
  9. // @grant GM_addStyle
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. const MENU_ITEM_SELECTOR = 'div.menu-horizontal-div-item';
  17.  
  18. function moveChatElementsOnce() {
  19. GM_addStyle('.chat-input, .bubbles-date-group { transform: translateX(-95px); }');
  20. }
  21.  
  22. function clickSecondElement() {
  23. const secondMenuItem = document.querySelector(`${MENU_ITEM_SELECTOR}:nth-of-type(2)`);
  24. if (secondMenuItem) {
  25. secondMenuItem.click();
  26. }
  27. }
  28.  
  29. function hideAllChatsButton() {
  30. const allChatsButton = document.querySelector(MENU_ITEM_SELECTOR);
  31. if (allChatsButton && allChatsButton.textContent.trim().startsWith("All")) {
  32. allChatsButton.style.display = "none";
  33. }
  34. }
  35.  
  36. function checkAndExecute() {
  37. const targetElement = document.querySelector(MENU_ITEM_SELECTOR);
  38. if (targetElement) {
  39. moveChatElementsOnce();
  40. clickSecondElement();
  41. hideAllChatsButton();
  42. } else {
  43. setTimeout(checkAndExecute, 10);
  44. }
  45. }
  46.  
  47. checkAndExecute();
  48. })();