Buttons for quick copying of text. Zelenka.guru.

Добавляет кнопки для копирования текста, позволяет создавать/удалять пользовательские кнопки и сохраняет их после перезагрузки.

  1. // ==UserScript==
  2. // @name Buttons for quick copying of text. Zelenka.guru.
  3. // @namespace http://tampermonkey.net/
  4. // @license https://zelenka.guru/rukia/
  5. // @version 1.0
  6. // @description Добавляет кнопки для копирования текста, позволяет создавать/удалять пользовательские кнопки и сохраняет их после перезагрузки.
  7. // @author Rukia
  8. // @match https://lolz.live/*
  9. // @match https://zelenka.guru/*
  10. // @match https://lolz.guru/*
  11. // @icon https://i.imgur.com/IOOaCrP.png
  12. // @grant GM_setClipboard
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. let buttonData = JSON.parse(localStorage.getItem('customButtons')) || [];
  19. let buttonCount = buttonData.length;
  20. const maxButtonCount = 11;
  21. const maxButtonTextLength = 28;
  22.  
  23. function createButton(buttonText, copyText, isNew = false) {
  24. let button = document.createElement("button");
  25. button.textContent = buttonText;
  26. button.style.position = "fixed";
  27. button.style.right = "20px";
  28. button.style.width = "110px";
  29. button.style.height = "40px";
  30. button.style.backgroundColor = "#228e5d";
  31. button.style.color = "#fff";
  32. button.style.border = "none";
  33. button.style.borderRadius = "5px";
  34. button.style.cursor = "pointer";
  35. button.style.zIndex = "1000";
  36. button.style.top = `${calcButtonPosition()}px`;
  37.  
  38. button.onclick = function() {
  39. GM_setClipboard(copyText);
  40. button.style.backgroundColor = "#303030";
  41. setTimeout(function() {
  42. button.style.backgroundColor = "#228e5d";
  43. }, 500);
  44. };
  45.  
  46. button.classList.add('custom-button');
  47. document.body.appendChild(button);
  48. buttonCount++;
  49. updateButtonPositions();
  50.  
  51. if (isNew) {
  52. buttonData.push({text: buttonText, copyText: copyText});
  53. localStorage.setItem('customButtons', JSON.stringify(buttonData));
  54. }
  55. }
  56.  
  57. // Создание кнопки +
  58. function createAddButton() {
  59. let addButton = document.createElement("button");
  60. addButton.textContent = "+";
  61. addButton.style.position = "fixed";
  62. addButton.style.right = "85px";
  63. addButton.style.width = "20px";
  64. addButton.style.height = "20px";
  65. addButton.style.backgroundColor = "#32CD32";
  66. addButton.style.color = "#fff";
  67. addButton.style.border = "none";
  68. addButton.style.borderRadius = "5px";
  69. addButton.style.cursor = "pointer";
  70. addButton.style.zIndex = "1000";
  71. addButton.style.top = "95%";
  72.  
  73. addButton.onclick = function() {
  74. if (buttonCount >= maxButtonCount) {
  75. alert('Нельзя создать больше 11 кнопок.');
  76. return;
  77. }
  78.  
  79. let buttonText = prompt("Введите текст для кнопки (макс. 28 символов):");
  80. let copyText = prompt("Введите текст, который будет копироваться:");
  81.  
  82. if (buttonText && buttonText.length > maxButtonTextLength) {
  83. alert(`Текст кнопки слишком длинный! Максимум ${maxButtonTextLength} символов.`);
  84. return;
  85. }
  86.  
  87. if (buttonText && copyText) {
  88. createButton(buttonText, copyText, true);
  89. }
  90. };
  91.  
  92. document.body.appendChild(addButton);
  93. }
  94.  
  95. function createRemoveButton() {
  96. let removeButton = document.createElement("button");
  97. removeButton.textContent = "-";
  98. removeButton.style.position = "fixed";
  99. removeButton.style.right = "110px";
  100. removeButton.style.width = "20px";
  101. removeButton.style.height = "20px";
  102. removeButton.style.backgroundColor = "#FF6347";
  103. removeButton.style.color = "#fff";
  104. removeButton.style.border = "none";
  105. removeButton.style.borderRadius = "5px";
  106. removeButton.style.cursor = "pointer";
  107. removeButton.style.zIndex = "1000";
  108. removeButton.style.top = "95%";
  109.  
  110. removeButton.onclick = function() {
  111. if (buttonData.length === 0) {
  112. alert("Нет кнопок для удаления.");
  113. return;
  114. }
  115.  
  116. let buttonNames = buttonData.map((btn, index) => `${index + 1}: ${btn.text}`).join("\n");
  117.  
  118. let choice = prompt(`Введите номер кнопки для удаления или напишите "all" для удаления всех кнопок:\n${buttonNames}`);
  119.  
  120. if (choice && choice.toLowerCase() === "all") {
  121. if (confirm("Вы уверены, что хотите удалить все кнопки?")) {
  122. buttonData = [];
  123. localStorage.setItem('customButtons', JSON.stringify(buttonData));
  124. reloadButtons();
  125. alert("Все кнопки удалены.");
  126. }
  127. } else {
  128. let indexToRemove = parseInt(choice) - 1;
  129. if (indexToRemove >= 0 && indexToRemove < buttonData.length) {
  130. buttonData.splice(indexToRemove, 1);
  131. localStorage.setItem('customButtons', JSON.stringify(buttonData));
  132. reloadButtons();
  133. } else {
  134. alert('Неверный выбор!');
  135. }
  136. }
  137. };
  138.  
  139. document.body.appendChild(removeButton);
  140. }
  141.  
  142. function calcButtonPosition() {
  143. const screenHeight = window.innerHeight;
  144. const buttonSpacing = 60;
  145. const totalButtonHeight = buttonCount * buttonSpacing;
  146. return (screenHeight / 2) - (totalButtonHeight / 2) + (buttonCount * buttonSpacing);
  147. }
  148.  
  149. function updateButtonPositions() {
  150. let buttons = document.querySelectorAll('.custom-button');
  151. buttons.forEach((button, index) => {
  152. button.style.top = `${calcButtonPositionForIndex(index)}px`;
  153. });
  154. }
  155.  
  156. function calcButtonPositionForIndex(index) {
  157. const screenHeight = window.innerHeight;
  158. const buttonSpacing = 45;
  159. const totalButtonHeight = buttonCount * buttonSpacing;
  160. return (screenHeight / 2) - (totalButtonHeight / 2) + (index * buttonSpacing);
  161. }
  162.  
  163. function reloadButtons() {
  164. document.querySelectorAll('.custom-button').forEach(btn => btn.remove());
  165. buttonCount = 0;
  166.  
  167. buttonData.forEach(btn => {
  168. createButton(btn.text, btn.copyText);
  169. });
  170. }
  171.  
  172. createAddButton();
  173. createRemoveButton();
  174. reloadButtons();
  175. })();