Загрузка...

Add buttons to quickly copy specified text.

Thread in Extentions created by Yowori Sep 14, 2024. (bumped Sep 14, 2024) 359 views

  1. Yowori
    Yowori Topic starter Sep 14, 2024 Эльфографика грядёт ~ https://lolz.live/threads/7861550/ 15,574 Jun 3, 2019
    Небольшой скрипт который позволяет добавлятьдалять кнопки для копирования сохраненного текста.
    Например если вы часто используете один и тот же текст, вы можете добавить кнопку и делать это всё одним нажатием (думаю подойдет больше оффтоперам, для всякой пасты).
    Лично я использую данное расширения для того чтобы быстро копировать котика.
    [IMG]
    Максимальное количество кнопок - 11 штук.
    Максимальное количество символов в названии кнопки - 28 штук.​
    https://greasyfork.org/ru/scripts/508362-buttons-for-quick-copying-of-text-zelenka-guru
    или
    JS
    // ==UserScript==
    // @name Buttons for quick copying of text. Zelenka.guru.
    // @namespace http://tampermonkey.net/
    // @license https://zelenka.guru/rukia/
    // @version 1.0
    // @description Добавляет кнопки для копирования текста, позволяет создавать/удалять пользовательские кнопки и сохраняет их после перезагрузки.
    // @author Rukia
    // @match https://lolz.live/*
    // @match https://zelenka.guru/*
    // @match https://lolz.guru/*
    // @icon [IMG][IMG] https://i.imgur.com/IOOaCrP.png[/IMG][/IMG][/CENTER][/spoiler][/SIZE]
    [spoiler=Установка скрипта;align=center][CENTER][SIZE=4]// @grant GM_setClipboard
    // ==/UserScript==

    (function() {
    'use strict';

    let buttonData = JSON.parse(localStorage.getItem('customButtons')) || [];
    let buttonCount = buttonData.length;
    const maxButtonCount = 11;
    const maxButtonTextLength = 28;

    function createButton(buttonText, copyText, isNew = false) {
    let button = document.createElement("button");
    button.textContent = buttonText;
    button.style.position = "fixed";
    button.style.right = "20px";
    button.style.width = "110px";
    button.style.height = "40px";
    button.style.backgroundColor = "#228e5d";
    button.style.color = "#fff";
    button.style.border = "none";
    button.style.borderRadius = "5px";
    button.style.cursor = "pointer";
    button.style.zIndex = "1000";
    button.style.top = `${calcButtonPosition()}px`;

    button.onclick = function() {
    GM_setClipboard(copyText);
    button.style.backgroundColor = "#303030";
    setTimeout(function() {
    button.style.backgroundColor = "#228e5d";
    }, 500);
    };

    button.classList.add('custom-button');
    document.body.appendChild(button);
    buttonCount++;
    updateButtonPositions();

    if (isNew) {
    buttonData.push({text: buttonText, copyText: copyText});
    localStorage.setItem('customButtons', JSON.stringify(buttonData));
    }
    }

    // Создание кнопки +
    function createAddButton() {
    let addButton = document.createElement("button");
    addButton.textContent = "+";
    addButton.style.position = "fixed";
    addButton.style.right = "85px";
    addButton.style.width = "20px";
    addButton.style.height = "20px";
    addButton.style.backgroundColor = "#32CD32";
    addButton.style.color = "#fff";
    addButton.style.border = "none";
    addButton.style.borderRadius = "5px";
    addButton.style.cursor = "pointer";
    addButton.style.zIndex = "1000";
    addButton.style.top = "95%";

    addButton.onclick = function() {
    if (buttonCount >= maxButtonCount) {
    alert('Нельзя создать больше 11 кнопок.');
    return;
    }

    let buttonText = prompt("Введите текст для кнопки (макс. 28 символов):");
    let copyText = prompt("Введите текст, который будет копироваться:");

    if (buttonText && buttonText.length > maxButtonTextLength) {
    alert(`Текст кнопки слишком длинный! Максимум ${maxButtonTextLength} символов.`);
    return;
    }

    if (buttonText && copyText) {
    createButton(buttonText, copyText, true);
    }
    };

    document.body.appendChild(addButton);
    }

    function createRemoveButton() {
    let removeButton = document.createElement("button");
    removeButton.textContent = "-";
    removeButton.style.position = "fixed";
    removeButton.style.right = "110px";
    removeButton.style.width = "20px";
    removeButton.style.height = "20px";
    removeButton.style.backgroundColor = "#FF6347";
    removeButton.style.color = "#fff";
    removeButton.style.border = "none";
    removeButton.style.borderRadius = "5px";
    removeButton.style.cursor = "pointer";
    removeButton.style.zIndex = "1000";
    removeButton.style.top = "95%";

    removeButton.onclick = function() {
    if (buttonData.length === 0) {
    alert("Нет кнопок для удаления.");
    return;
    }

    let buttonNames = buttonData.map((btn, index) => `${index + 1}: ${btn.text}`).join("\n");

    let choice = prompt(`Введите номер кнопки для удаления или напишите "all" для удаления всех кнопок:\n${buttonNames}`);

    if (choice && choice.toLowerCase() === "all") {
    if (confirm("Вы уверены, что хотите удалить все кнопки?")) {
    buttonData = [];
    localStorage.setItem('customButtons', JSON.stringify(buttonData));
    reloadButtons();
    alert("Все кнопки удалены.");
    }
    } else {
    let indexToRemove = parseInt(choice) - 1;
    if (indexToRemove >= 0 && indexToRemove < buttonData.length) {
    buttonData.splice(indexToRemove, 1);
    localStorage.setItem('customButtons', JSON.stringify(buttonData));
    reloadButtons();
    } else {
    alert('Неверный выбор!');
    }
    }
    };

    document.body.appendChild(removeButton);
    }

    function calcButtonPosition() {
    const screenHeight = window.innerHeight;
    const buttonSpacing = 60;
    const totalButtonHeight = buttonCount * buttonSpacing;
    return (screenHeight / 2) - (totalButtonHeight / 2) + (buttonCount * buttonSpacing);
    }

    function updateButtonPositions() {
    let buttons = document.querySelectorAll('.custom-button');
    buttons.forEach((button, index) => {
    button.style.top = `${calcButtonPositionForIndex(index)}px`;
    });
    }

    function calcButtonPositionForIndex(index) {
    const screenHeight = window.innerHeight;
    const buttonSpacing = 45;
    const totalButtonHeight = buttonCount * buttonSpacing;
    return (screenHeight / 2) - (totalButtonHeight / 2) + (index * buttonSpacing);
    }

    function reloadButtons() {
    document.querySelectorAll('.custom-button').forEach(btn => btn.remove());
    buttonCount = 0;

    buttonData.forEach(btn => {
    createButton(btn.text, btn.copyText);
    });
    }

    createAddButton();
    createRemoveButton();
    reloadButtons();
    })();
    P.S Я не профессиональный кодер, это первый мой скрипт на Javascript, так что не бейте если считаете это говнокодом ;3
     
  2. ReLife
    ReLife Sep 14, 2024 Лучшие, антиабуз домены - lolz.live/threads/111111 9872 Apr 8, 2019
    Так это же те же шаблоны
     
    1. Yowori Topic starter
      ReLife, что-то на подобии
  3. blessed
    blessed Sep 14, 2024 19,261 Aug 1, 2018
    Делаем брат :yodaluv: :catwait:
     
    1. Yowori Topic starter
      blessed, дарова брат давно тя не видел лю
    2. blessed
      Yowori, давно не был в уличных гонках
Loading...
Top