Torn.com Enhanced Chat Buttons V2

Add customizable buttons to Torn.com chat with enhanced UI and features

当前为 2024-05-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Torn.com Enhanced Chat Buttons V2
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.02
  5. // @description Add customizable buttons to Torn.com chat with enhanced UI and features
  6. // @author Created by Callz [2188704], updated by Weav3r [1853324]
  7. // @match https://www.torn.com/*
  8. // @grant GM_setClipboard
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. const buttonCSS = `
  15. .custom-chat-button {
  16. background-color: #007BFF;
  17. color: white;
  18. padding: 2px 7px;
  19. text-align: center;
  20. text-decoration: none;
  21. display: inline-block;
  22. font-size: 14px;
  23. margin: 4px 6px;
  24. cursor: pointer;
  25. border-radius: 5px;
  26. border: none;
  27. transition: transform 0.1s ease, box-shadow 0.1s ease;
  28. min-width: 80px;
  29. overflow: hidden;
  30. white-space: nowrap;
  31. }
  32.  
  33. .custom-chat-button:active {
  34. transform: scale(0.95);
  35. box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  36. }
  37.  
  38. .custom-chat-button.recent {
  39. border: 2px solid #FFD700;
  40. box-shadow: 0 0 5px rgba(255, 215, 0, 0.8);
  41. }
  42.  
  43. .custom-ui-panel {
  44. position: fixed;
  45. top: 50%;
  46. left: 50%;
  47. transform: translate(-50%, -50%);
  48. background-color: #f5f5f5;
  49. padding: 10px;
  50. color: black;
  51. border-radius: 10px;
  52. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  53. z-index: 9999999999;
  54. width: 90%;
  55. max-width: 500px;
  56. box-sizing: border-box;
  57. max-height: 90vh;
  58. overflow: auto;
  59. }
  60.  
  61. .custom-ui-panel h3 {
  62. font-size: 20px;
  63. margin-bottom: 10px;
  64. text-align: center;
  65. }
  66.  
  67. .custom-ui-panel label {
  68. font-size: 14px;
  69. margin-bottom: 5px;
  70. display: block;
  71. }
  72.  
  73. .custom-ui-panel input[type="text"],
  74. .custom-ui-panel select,
  75. .custom-ui-panel textarea {
  76. width: calc(100% - 12px);
  77. padding: 5px;
  78. margin-bottom: 10px;
  79. border: 1px solid #ccc;
  80. border-radius: 5px;
  81. font-size: 14px;
  82. }
  83.  
  84. .custom-ui-panel input[type="color"] {
  85. padding: 0;
  86. margin-top: 5px;
  87. }
  88.  
  89. .custom-ui-panel button {
  90. background-color: #007BFF;
  91. color: white;
  92. border: none;
  93. padding: 8px 12px;
  94. border-radius: 5px;
  95. cursor: pointer;
  96. margin: 5px;
  97. font-size: 14px;
  98. transition: background-color 0.3s ease;
  99. }
  100.  
  101. .custom-ui-panel button#close-ui {
  102. background-color: #ccc;
  103. }
  104.  
  105. .custom-ui-panel button#close-ui:hover {
  106. background-color: #999;
  107. }
  108.  
  109. .custom-ui-panel textarea {
  110. height: 60px;
  111. resize: vertical;
  112. position: relative;
  113. }
  114.  
  115. .custom-ui-panel hr {
  116. margin: 10px 0;
  117. border: 0;
  118. border-top: 1px solid #ccc;
  119. }
  120.  
  121. .char-counter {
  122. position: absolute;
  123. bottom: 10px;
  124. right: 10px;
  125. font-size: 12px;
  126. color: #999;
  127. }
  128.  
  129. #chat-config-button {
  130. color: green;
  131. }
  132.  
  133. #button-configs {
  134. max-height: 400px;
  135. overflow-y: auto;
  136. margin-bottom: 10px;
  137. }
  138.  
  139. @media (max-width: 600px) {
  140. .custom-ui-panel {
  141. width: 95%;
  142. max-width: none;
  143. padding: 8px;
  144. }
  145.  
  146. .custom-ui-panel h3 {
  147. font-size: 18px;
  148. }
  149.  
  150. .custom-ui-panel label,
  151. .custom-ui-panel button {
  152. font-size: 12px;
  153. }
  154.  
  155. .custom-ui-panel input[type="text"],
  156. .custom-ui-panel select,
  157. .custom-ui-panel textarea {
  158. font-size: 12px;
  159. }
  160.  
  161. .custom-ui-panel button {
  162. padding: 6px 10px;
  163. }
  164.  
  165. .char-counter {
  166. font-size: 10px;
  167. }
  168. }
  169.  
  170. .tabs {
  171. display: flex;
  172. margin-bottom: 10px;
  173. }
  174.  
  175. .tab {
  176. flex: 1;
  177. padding: 10px;
  178. cursor: pointer;
  179. text-align: center;
  180. background-color: #e9e9e9;
  181. border: 1px solid #ccc;
  182. border-bottom: none;
  183. border-radius: 10px 10px 0 0;
  184. }
  185.  
  186. .tab.settings-tab {
  187. flex: 0.2;
  188. padding: 10px;
  189. cursor: pointer;
  190. text-align: center;
  191. background-color: #e9e9e9;
  192. border: 1px solid #ccc;
  193. border-bottom: none;
  194. border-radius: 10px 10px 0 0;
  195. }
  196.  
  197. .tab.active {
  198. background-color: #fff;
  199. border-bottom: 1px solid #fff;
  200. }
  201.  
  202. .tab-content {
  203. display: none;
  204. }
  205.  
  206. .tab-content.active {
  207. display: block;
  208. }
  209.  
  210. .custom-ui-panel.config-list-tab-active {
  211. max-height: 80vh;
  212. }
  213.  
  214. .search-container {
  215. display: flex;
  216. margin-bottom: 10px;
  217. }
  218.  
  219. .search-container input[type="text"] {
  220. flex: 3;
  221. padding: 5px;
  222. margin-right: 5px;
  223. }
  224.  
  225. .search-container select {
  226. flex: 1;
  227. padding: 5px;
  228. }
  229.  
  230. .highlight {
  231. background-color: yellow;
  232. }
  233.  
  234. .tt-chat-filter {
  235. display: flex;
  236. padding: 4px;
  237. align-items: center;
  238. background-color: var(--chat-box-bg);
  239. color: var(--chat-box-label-info);
  240. border-bottom: 1px solid var(--chat-box-input-border);
  241. margin-bottom: 8px;
  242. }
  243.  
  244. .tt-chat-filter input {
  245. margin-left: 4px;
  246. margin-right: 4px;
  247. border-radius: 5px;
  248. width: -webkit-fill-available;
  249. width: -moz-available;
  250. border: 1px solid var(--chat-box-input-border);
  251. background-color: var(--chat-box-bg);
  252. color: var(--chat-box-label-info);
  253. }
  254. `;
  255.  
  256. const conditions = {
  257. TradeChat: chatBox => chatBox.querySelector('.chat-box-header__name___jIjjM').textContent === 'Trade',
  258. HospitalChat: chatBox => chatBox.querySelector('.chat-box-header__name___jIjjM').textContent === 'Hospital',
  259. FactionChat: chatBox => chatBox.querySelector('.chat-box-header__name___jIjjM').textContent === 'Faction',
  260. CompanyChat: chatBox => chatBox.querySelector('.chat-box-header__name___jIjjM').textContent === 'Company',
  261. GlobalChat: chatBox => chatBox.querySelector('.chat-box-header__name___jIjjM').textContent === 'Global',
  262. UserChat: chatBox => chatBox.querySelector('.chat-box-header__options___nTsMU'),
  263. };
  264.  
  265. function addCSS(cssString) {
  266. const style = document.createElement('style');
  267. style.textContent = cssString;
  268. document.head.append(style);
  269. }
  270.  
  271. function saveRecentButtonInfo(buttonText, chatBoxName) {
  272. localStorage.setItem('recentButtonInfo', JSON.stringify({ buttonText, chatBoxName }));
  273. }
  274.  
  275. function clearRecentButtonInfo() {
  276. localStorage.removeItem('recentButtonInfo');
  277. }
  278.  
  279. function getButtonConfigurations() {
  280. return JSON.parse(localStorage.getItem('chatButtonConfig')) || { buttons: [] };
  281. }
  282.  
  283. function saveButtonConfigurations(config) {
  284. localStorage.setItem('chatButtonConfig', JSON.stringify(config));
  285. }
  286.  
  287. function createUIPanel() {
  288. const panel = document.createElement('div');
  289. panel.className = 'custom-ui-panel';
  290. panel.innerHTML = `
  291. <div class="tabs">
  292. <div class="tab active" data-tab="config-list-tab">Configured Buttons</div>
  293. <div class="tab" data-tab="config-edit-tab">Create/Edit Button</div>
  294. <div class="tab settings-tab" data-tab="config-settings-tab">⚙️</div>
  295. </div>
  296. <div id="config-list-tab" class="tab-content active">
  297. <div class="search-container">
  298. <input type="text" id="search-input" placeholder="Search...">
  299. <select id="search-select">
  300. <option value="buttonText">Text</option>
  301. <option value="condition">Condition</option>
  302. <option value="text">Message</option>
  303. </select>
  304. </div>
  305. <div id="button-configs"></div>
  306. </div>
  307. <div id="config-edit-tab" class="tab-content">
  308. <div>
  309. <label for="button-text">Button Text</label>
  310. <input type="text" id="button-text" placeholder="Button Text">
  311.  
  312. <label for="button-color">Background Color</label>
  313. <input type="color" id="button-color">
  314.  
  315. <label for="button-condition">Condition</label>
  316. <select id="button-condition">
  317. <option value="TradeChat">Trade Chat</option>
  318. <option value="HospitalChat">Hospital Chat</option>
  319. <option value="FactionChat">Faction Chat</option>
  320. <option value="CompanyChat">Company Chat</option>
  321. <option value="GlobalChat">Global Chat</option>
  322. <option value="UserChat">User Chat</option>
  323. </select>
  324.  
  325. <label for="button-text-content">Message</label>
  326. <textarea id="button-text-content" placeholder="Message content"></textarea>
  327. <div class="char-counter" id="char-counter">0</div>
  328.  
  329. <button id="add-button">Add Button</button>
  330. <button id="edit-button" style="display: none;">Save Button</button>
  331. </div>
  332. </div>
  333. <div id="config-settings-tab" class="tab-content">
  334. <button id="import-button">Import Config</button>
  335. <button id="export-button">Export Config</button>
  336. </div>
  337. <button id="close-ui">Close</button>
  338. `;
  339. document.body.appendChild(panel);
  340.  
  341. document.querySelectorAll('.tab').forEach(tab => {
  342. tab.addEventListener('click', () => {
  343. switchTab(tab.dataset.tab);
  344. });
  345. });
  346.  
  347. document.getElementById('add-button').addEventListener('click', addNewButtonConfig);
  348. document.getElementById('edit-button').addEventListener('click', editButtonConfig);
  349. document.getElementById('close-ui').addEventListener('click', closeUI);
  350. document.getElementById('import-button').addEventListener('click', importConfig);
  351. document.getElementById('export-button').addEventListener('click', exportConfig);
  352. document.getElementById('button-text-content').addEventListener('input', updateCharCounter);
  353. document.getElementById('search-input').addEventListener('input', filterButtonConfigs);
  354. populateButtonConfigs();
  355. }
  356.  
  357. function switchTab(tabId) {
  358. document.querySelectorAll('.tab, .tab-content').forEach(el => {
  359. el.classList.remove('active');
  360. });
  361. document.querySelector(`[data-tab="${tabId}"]`).classList.add('active');
  362. document.getElementById(tabId).classList.add('active');
  363.  
  364. const panel = document.querySelector('.custom-ui-panel');
  365. if (tabId === 'config-list-tab') {
  366. panel.classList.add('config-list-tab-active');
  367. } else {
  368. panel.classList.remove('config-list-tab-active');
  369. }
  370. }
  371.  
  372. function populateButtonConfigs() {
  373. const configsContainer = document.getElementById('button-configs');
  374. configsContainer.innerHTML = '';
  375. const configs = getButtonConfigurations();
  376.  
  377. configs.buttons.forEach((buttonConfig, index) => {
  378. const configDiv = document.createElement('div');
  379. configDiv.className = 'draggable';
  380. configDiv.dataset.index = index;
  381. configDiv.innerHTML = `
  382. <div><strong>Text:</strong> ${buttonConfig.buttonText}</div>
  383. <div><strong>Color:</strong> ${buttonConfig.backgroundColor}</div>
  384. <div><strong>Condition:</strong> ${buttonConfig.condition}</div>
  385. <div><strong>Message:</strong> ${buttonConfig.text}</div>
  386. `;
  387.  
  388. const editButton = document.createElement('button');
  389. editButton.textContent = 'Edit';
  390. editButton.addEventListener('click', () => {
  391. selectForEdit(index);
  392. switchTab('config-edit-tab');
  393. });
  394. configDiv.appendChild(editButton);
  395.  
  396. const deleteButton = document.createElement('button');
  397. deleteButton.textContent = 'Delete';
  398. deleteButton.addEventListener('click', () => deleteButtonConfig(index));
  399. configDiv.appendChild(deleteButton);
  400.  
  401. const moveUpButton = document.createElement('button');
  402. moveUpButton.textContent = 'Up';
  403. moveUpButton.addEventListener('click', () => moveButtonConfig(index, -1));
  404. configDiv.appendChild(moveUpButton);
  405.  
  406. const moveDownButton = document.createElement('button');
  407. moveDownButton.textContent = 'Down';
  408. moveDownButton.addEventListener('click', () => moveButtonConfig(index, 1));
  409. configDiv.appendChild(moveDownButton);
  410.  
  411. configsContainer.appendChild(configDiv);
  412. });
  413. }
  414.  
  415. function filterButtonConfigs() {
  416. const searchInput = document.getElementById('search-input').value.toLowerCase();
  417. const searchBy = document.getElementById('search-select').value;
  418. const configs = getButtonConfigurations();
  419.  
  420. const filteredConfigs = configs.buttons.filter(buttonConfig => {
  421. const fieldValue = buttonConfig[searchBy].toLowerCase();
  422. return fieldValue.includes(searchInput);
  423. });
  424.  
  425. const configsContainer = document.getElementById('button-configs');
  426. configsContainer.innerHTML = '';
  427.  
  428. filteredConfigs.forEach((buttonConfig, index) => {
  429. const configDiv = document.createElement('div');
  430. configDiv.className = 'draggable';
  431. configDiv.dataset.index = index;
  432. configDiv.innerHTML = `
  433. <div><strong>Text:</strong> ${buttonConfig.buttonText}</div>
  434. <div><strong>Color:</strong> ${buttonConfig.backgroundColor}</div>
  435. <div><strong>Condition:</strong> ${buttonConfig.condition}</div>
  436. <div><strong>Message:</strong> ${buttonConfig.text}</div>
  437. `;
  438.  
  439. const editButton = document.createElement('button');
  440. editButton.textContent = 'Edit';
  441. editButton.addEventListener('click', () => {
  442. selectForEdit(index);
  443. switchTab('config-edit-tab');
  444. });
  445. configDiv.appendChild(editButton);
  446.  
  447. const deleteButton = document.createElement('button');
  448. deleteButton.textContent = 'Delete';
  449. deleteButton.addEventListener('click', () => deleteButtonConfig(index));
  450. configDiv.appendChild(deleteButton);
  451.  
  452. const moveUpButton = document.createElement('button');
  453. moveUpButton.textContent = 'Up';
  454. moveUpButton.addEventListener('click', () => moveButtonConfig(index, -1));
  455. configDiv.appendChild(moveUpButton);
  456.  
  457. const moveDownButton = document.createElement('button');
  458. moveDownButton.textContent = 'Down';
  459. moveDownButton.addEventListener('click', () => moveButtonConfig(index, 1));
  460. configDiv.appendChild(moveDownButton);
  461.  
  462. configsContainer.appendChild(configDiv);
  463. });
  464. }
  465.  
  466. function selectForEdit(index) {
  467. const config = getButtonConfigurations().buttons[index];
  468. document.getElementById('button-text').value = config.buttonText;
  469. document.getElementById('button-color').value = config.backgroundColor;
  470. document.getElementById('button-condition').value = config.condition;
  471. document.getElementById('button-text-content').value = config.text;
  472.  
  473. document.getElementById('add-button').style.display = 'block';
  474. document.getElementById('edit-button').style.display = 'block';
  475. document.getElementById('edit-button').setAttribute('data-edit-index', index);
  476. }
  477.  
  478. function deleteButtonConfig(index) {
  479. const config = getButtonConfigurations();
  480. config.buttons.splice(index, 1);
  481. saveButtonConfigurations(config);
  482. populateButtonConfigs();
  483. }
  484.  
  485. function moveButtonConfig(index, direction) {
  486. const config = getButtonConfigurations();
  487. const newIndex = index + direction;
  488.  
  489. if (newIndex >= 0 && newIndex < config.buttons.length) {
  490. const buttonConfig = config.buttons.splice(index, 1)[0];
  491. config.buttons.splice(newIndex, 0, buttonConfig);
  492. saveButtonConfigurations(config);
  493. populateButtonConfigs();
  494. }
  495. }
  496.  
  497. function addNewButtonConfig() {
  498. const buttonText = document.getElementById('button-text').value;
  499. const backgroundColor = document.getElementById('button-color').value;
  500. const condition = document.getElementById('button-condition').value;
  501. const text = document.getElementById('button-text-content').value;
  502.  
  503. const config = getButtonConfigurations();
  504. config.buttons.push({ buttonText, backgroundColor, condition, text });
  505. saveButtonConfigurations(config);
  506. populateButtonConfigs();
  507. highlightButton(config.buttons.length - 1);
  508. switchTab('config-list-tab');
  509.  
  510. clearInputFields();
  511. }
  512.  
  513. function editButtonConfig() {
  514. const index = parseInt(document.getElementById('edit-button').getAttribute('data-edit-index'), 10);
  515. const buttonText = document.getElementById('button-text').value;
  516. const backgroundColor = document.getElementById('button-color').value;
  517. const condition = document.getElementById('button-condition').value;
  518. const text = document.getElementById('button-text-content').value;
  519.  
  520. const config = getButtonConfigurations();
  521. config.buttons[index] = { buttonText, backgroundColor, condition, text };
  522. saveButtonConfigurations(config);
  523. populateButtonConfigs();
  524. highlightButton(index);
  525. switchTab('config-list-tab');
  526.  
  527. document.getElementById('add-button').style.display = 'block';
  528. document.getElementById('edit-button').style.display = 'none';
  529.  
  530. clearInputFields();
  531. }
  532.  
  533. function clearInputFields() {
  534. document.getElementById('button-text').value = '';
  535. document.getElementById('button-text-content').value = '';
  536. }
  537.  
  538. function closeUI() {
  539. document.querySelector('.custom-ui-panel').remove();
  540. }
  541.  
  542. function createConfigButton() {
  543. const settingsPanel = document.querySelector('.settings-panel___IZSDs');
  544. if (settingsPanel && !document.querySelector('#chat-config-button')) {
  545. const configButton = document.createElement('button');
  546. configButton.id = 'chat-config-button';
  547. configButton.textContent = 'Edit Chat Buttons';
  548. configButton.addEventListener('click', createUIPanel);
  549. settingsPanel.appendChild(configButton);
  550. }
  551. }
  552.  
  553. function applyButtonConfigurations() {
  554. const configs = getButtonConfigurations();
  555. document.querySelectorAll('.chat-box___mHm01').forEach(chatBox => {
  556. configs.buttons.forEach(buttonConfig => {
  557. const conditionFunc = conditions[buttonConfig.condition];
  558. if (conditionFunc && conditionFunc(chatBox) && !chatBox.querySelector(`[data-button-text="${buttonConfig.buttonText}"]`)) {
  559. const button = document.createElement('button');
  560. button.className = 'custom-chat-button';
  561. button.innerText = buttonConfig.buttonText;
  562. button.style.backgroundColor = buttonConfig.backgroundColor;
  563. button.setAttribute('data-button-text', buttonConfig.buttonText);
  564. button.addEventListener('click', (event) => addCustomText(chatBox, buttonConfig.text, event));
  565. button.addEventListener('mousedown', (event) => {
  566. if (event.button === 0) { // Left mouse button
  567. let timer;
  568. const delay = 1000; // 1 second
  569.  
  570. timer = setTimeout(() => {
  571. button.classList.remove('recent');
  572. clearRecentButtonInfo();
  573. }, delay);
  574.  
  575. button.addEventListener('mouseup', () => {
  576. clearTimeout(timer);
  577. }, { once: true });
  578.  
  579. button.addEventListener('mouseleave', () => {
  580. clearTimeout(timer);
  581. }, { once: true });
  582. }
  583. });
  584.  
  585. // Add button to the appropriate container
  586. const filterContainer = chatBox.querySelector('.tt-chat-filter');
  587. const footerContainer = chatBox.querySelector('.chat-box-footer___YK914');
  588. if (filterContainer) {
  589. filterContainer.insertBefore(button, filterContainer.firstChild);
  590. } else if (footerContainer) {
  591. const buttonContainer = chatBox.querySelector('.button-container') || document.createElement('div');
  592. buttonContainer.className = 'button-container';
  593. buttonContainer.style.display = 'flex';
  594. buttonContainer.style.flexWrap = 'wrap';
  595. footerContainer.insertAdjacentElement('beforebegin', buttonContainer);
  596. buttonContainer.appendChild(button);
  597. } else {
  598. const buttonContainer = document.createElement('div');
  599. buttonContainer.className = 'button-container';
  600. buttonContainer.style.display = 'flex';
  601. buttonContainer.style.flexWrap = 'wrap';
  602. chatBox.insertBefore(buttonContainer, chatBox.firstChild);
  603. buttonContainer.appendChild(button);
  604. }
  605. }
  606. });
  607. });
  608. }
  609.  
  610. function addCustomText(chatBox, messageTemplate, event) {
  611. const nameElement = chatBox.querySelector('.typography___Dc5WV');
  612. const name = nameElement ? nameElement.textContent.trim() : 'Trader';
  613. const message = messageTemplate.replace('{name}', name);
  614.  
  615. navigator.clipboard.writeText(message).then(() => {
  616. const textArea = chatBox.querySelector('textarea');
  617. textArea.focus();
  618. textArea.value = ''; // Clear the existing text
  619. const startPos = textArea.selectionStart;
  620. const endPos = textArea.selectionEnd;
  621. textArea.setRangeText(message, startPos, endPos, 'end');
  622. textArea.dispatchEvent(new Event('input', { bubbles: true }));
  623. textArea.focus();
  624. textArea.selectionStart = textArea.selectionEnd = startPos + message.length;
  625.  
  626. // Remove the 'recent' class from all buttons
  627. chatBox.querySelectorAll('.custom-chat-button').forEach(btn => {
  628. btn.classList.remove('recent');
  629. });
  630.  
  631. // Add the 'recent' class to the clicked button
  632. event.target.classList.add('recent');
  633.  
  634. // Save the recently clicked button information
  635. const chatBoxName = chatBox.querySelector('.chat-box-header__name___jIjjM').textContent;
  636. saveRecentButtonInfo(event.target.getAttribute('data-button-text'), chatBoxName);
  637. });
  638. }
  639.  
  640. function applyRecentButtonClass() {
  641. const recentButtonInfo = JSON.parse(localStorage.getItem('recentButtonInfo'));
  642. if (recentButtonInfo) {
  643. document.querySelectorAll('.chat-box___mHm01').forEach(chatBox => {
  644. const chatBoxName = chatBox.querySelector('.chat-box-header__name___jIjjM').textContent;
  645. if (chatBoxName === recentButtonInfo.chatBoxName) {
  646. const button = chatBox.querySelector(`[data-button-text="${recentButtonInfo.buttonText}"]`);
  647. if (button) {
  648. button.classList.add('recent');
  649. }
  650. }
  651. });
  652. }
  653. }
  654.  
  655. function importConfig() {
  656. const input = document.createElement('input');
  657. input.type = 'file';
  658. input.accept = '.json';
  659. input.onchange = (event) => {
  660. const file = event.target.files[0];
  661. const reader = new FileReader();
  662. reader.onload = (e) => {
  663. const config = JSON.parse(e.target.result);
  664. saveButtonConfigurations(config);
  665. populateButtonConfigs();
  666. applyButtonConfigurations();
  667. };
  668. reader.readAsText(file);
  669. };
  670. input.click();
  671. }
  672.  
  673. function exportConfig() {
  674. const config = getButtonConfigurations();
  675. const blob = new Blob([JSON.stringify(config, null, 2)], { type: 'application/json' });
  676. const url = URL.createObjectURL(blob);
  677. const a = document.createElement('a');
  678. a.href = url;
  679. a.download = 'chatButtonConfig.json';
  680. document.body.appendChild(a);
  681. a.click();
  682. document.body.removeChild(a);
  683. URL.revokeObjectURL(url);
  684. }
  685.  
  686. function updateCharCounter() {
  687. const textArea = document.getElementById('button-text-content');
  688. const counter = document.getElementById('char-counter');
  689. counter.textContent = textArea.value.length;
  690. }
  691.  
  692. function highlightButton(index) {
  693. const configsContainer = document.getElementById('button-configs');
  694. const buttonDiv = configsContainer.querySelector(`.draggable[data-index="${index}"]`);
  695. if (buttonDiv) {
  696. buttonDiv.classList.add('highlight');
  697. buttonDiv.scrollIntoView({ behavior: 'smooth', block: 'center' });
  698. setTimeout(() => {
  699. buttonDiv.classList.remove('highlight');
  700. }, 2000);
  701. }
  702. }
  703.  
  704. addCSS(buttonCSS);
  705.  
  706. const chatContainerObserver = new MutationObserver(function(mutations) {
  707. mutations.forEach(function(mutation) {
  708. createConfigButton();
  709. applyButtonConfigurations();
  710. applyRecentButtonClass();
  711. });
  712. });
  713.  
  714. const chatContainer = document.querySelector('#chatRoot');
  715. if (chatContainer) {
  716. chatContainerObserver.observe(chatContainer, { childList: true, subtree: true });
  717. }
  718.  
  719. applyButtonConfigurations();
  720. applyRecentButtonClass();
  721. })();

QingJ © 2025

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