Open Chat on the Same Page with Custom Icon LZT MARKET

Open chat on the same page with a custom icon

  1. // ==UserScript==
  2. // @name Open Chat on the Same Page with Custom Icon LZT MARKET
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Open chat on the same page with a custom icon
  6. // @author You
  7. // @grant none
  8. // @match https://lzt.market/*
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Общий стиль для кнопок
  15. var buttonStyle = {
  16. position: 'fixed',
  17. bottom: '85px',
  18. width: '60px',
  19. height: '60px',
  20. borderRadius: '50%',
  21. textAlign: 'center',
  22. cursor: 'pointer',
  23. zIndex: '9999',
  24. transition: 'opacity 0.1s ease-in-out',
  25. };
  26.  
  27. // Стили кастомного значка
  28. var customIconStyle = Object.assign({}, buttonStyle, {
  29. right: '15px',
  30. backgroundColor: '#8E8FFA', // Цвет круга
  31. });
  32.  
  33. // Создание кастомного значка
  34. var customIcon = createButton('chat2-button chat2-button-open lztng-1a57w7i custom-icon', 'Открыть чат', customIconStyle);
  35.  
  36. // Удаление элемента .mobileMenuButton
  37. var mobileMenuButton = document.querySelector('.mobileMenuButton');
  38. if (mobileMenuButton) {
  39. mobileMenuButton.remove();
  40. }
  41.  
  42. // Добавление кастомного значка в body
  43. document.body.appendChild(customIcon);
  44.  
  45. // Создание iframe для загрузки чата
  46. var chatIframe = createIframe('https://lzt.market/conversations/', '885px', '570px');
  47.  
  48. // Добавление iframe в body
  49. document.body.appendChild(chatIframe);
  50.  
  51. // Стили крестика
  52. var closeButtonStyle = Object.assign({}, buttonStyle, {
  53. display: 'none',
  54. opacity: '0',
  55. backgroundColor: '#FF6969', // Цвет креста
  56. });
  57.  
  58. // Создание крестика
  59. var closeButton = createButton('chat2-button chat2-button-close lztng-1a57w7i close-icon', 'Закрыть чат', closeButtonStyle);
  60.  
  61. // Добавление крестика в body
  62. document.body.appendChild(closeButton);
  63.  
  64. // Обработка клика на кастомном значке
  65. customIcon.addEventListener('click', function() {
  66. // Отображение/скрытие iframe чата
  67. toggleChat();
  68. });
  69.  
  70. // Обработка клика на крестике
  71. closeButton.addEventListener('click', function() {
  72. // Закрытие чата и отображение кастомного значка
  73. closeChat();
  74. });
  75.  
  76. // Функция для создания кнопок
  77. function createButton(className, title, style) {
  78. var button = document.createElement('div');
  79. button.className = className;
  80. button.title = title;
  81. Object.assign(button.style, style);
  82. return button;
  83. }
  84.  
  85. // Функция для создания iframe
  86. function createIframe(src, width, height) {
  87. var iframe = document.createElement('iframe');
  88. iframe.src = src;
  89. iframe.style.position = 'fixed';
  90. iframe.style.bottom = '0';
  91. iframe.style.right = '0';
  92. iframe.style.width = width;
  93. iframe.style.height = height;
  94. iframe.style.border = 'none';
  95. iframe.style.display = 'none';
  96. iframe.style.zIndex = '9998';
  97. return iframe;
  98. }
  99.  
  100. // Функция для отображения/скрытия iframe чата
  101. function toggleChat() {
  102. chatIframe.style.display = (chatIframe.style.display === 'none') ? 'block' : 'none';
  103. customIcon.style.opacity = '0';
  104. setTimeout(function() {
  105. customIcon.style.display = 'none';
  106. closeButton.style.display = 'block';
  107. closeButton.style.opacity = '1';
  108. }, 100);
  109. }
  110.  
  111. // Функция для закрытия чата и отображения кастомного значка
  112. function closeChat() {
  113. closeButton.style.opacity = '0';
  114. setTimeout(function() {
  115. closeButton.style.display = 'none';
  116. customIcon.style.display = 'block';
  117. customIcon.style.opacity = '1';
  118. }, 500);
  119. chatIframe.style.display = 'none';
  120. }
  121.  
  122. // Добавление функции в глобальную область видимости (чтобы можно было вызвать из iframe)
  123. window.closeChat = closeChat;
  124.  
  125. })();