Auto Copy Code Blocks

Add copy buttons to all code blocks on any website

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Auto Copy Code Blocks
// @namespace    https://flowkit.dev
// @version      1.0
// @description  Add copy buttons to all code blocks on any website
// @author       FlowKit
// @match        *://*/*
// @license      MIT
// @grant        none
// ==/UserScript==
(function() {
    'use strict';
    document.querySelectorAll('pre code, pre').forEach(b => {
        const btn = document.createElement('button');
        btn.textContent = 'Copy';
        btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:4px 8px;background:#667eea;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:12px';
        btn.onclick = () => { navigator.clipboard.writeText(b.textContent); btn.textContent = 'Copied!'; setTimeout(() => btn.textContent = 'Copy', 1500); };
        b.parentElement.style.position = 'relative';
        b.parentElement.appendChild(btn);
    });
})();