TG Shortcuts

Add kb shortcut to Telegram

  1. // ==UserScript==
  2. // @name TG Shortcuts
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-06-21
  5. // @description Add kb shortcut to Telegram
  6. // @author Jatin Sharma
  7. // @match https://web.telegram.org/k/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=telegram.org
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. function waitForElem(selector) {
  16. return new Promise(resolve => {
  17. if (document.querySelector(selector)) {
  18. return resolve(document.querySelector(selector));
  19. }
  20.  
  21. const observer = new MutationObserver(mutations => {
  22. if (document.querySelector(selector)) {
  23. observer.disconnect();
  24. resolve(document.querySelector(selector));
  25. }
  26. });
  27.  
  28. // If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
  29. observer.observe(document.body, { childList: true, subtree: true });
  30. });
  31. }
  32.  
  33. document.addEventListener('keydown', async function(event) {
  34. // Define the key combination for the shortcut
  35. const isShortcut = event.ctrlKey && event.key === '/' && !event.repeat;
  36. if(isShortcut) {
  37. if (document.querySelector('button.sidebar-close-button')?.offsetParent) {
  38. document.querySelector('button.sidebar-close-button').click();
  39. }
  40. else {
  41. document.querySelector('div.sidebar-header__btn-container > button').click();
  42. (await waitForElem('span.archived-count'));//.parentElement.click();
  43. setTimeout(() => document.querySelector('span.archived-count').parentElement.click(), 40);
  44. }
  45. }
  46.  
  47. });
  48. // Your code here...
  49. })();

QingJ © 2025

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