# code-block-pro/1.1.0/src/front/front.js

Code Block Pro – Beautiful Syntax Highlighting, version 1.1.0. 22 lines.

- Page: https://pluginprobe.com/plugins/code-block-pro/1.1.0/code/src/front/front.js
- Raw: https://pluginprobe.com/plugins/code-block-pro/1.1.0/raw/src/front/front.js
- Modified: 2022-08-22T22:25:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/code-block-pro/1.1.0/code/src/front/front.js#L10-L20`.

```javascript
import copy from 'copy-to-clipboard';

addEventListener('DOMContentLoaded', () => {
    const buttons = Array.from(
        document.querySelectorAll('.code-block-pro-copy-button'),
    );
    buttons.forEach((button) => {
        // Setting it to block here lets users deactivate the plugin safely
        button.style.display = 'block';
        button.addEventListener('click', (event) => {
            const b = event.target?.closest('span');
            copy(b?.dataset?.code ?? '', {
                format: 'text/plain',
            });
            b.classList.add('copying');
            setTimeout(() => {
                b.classList.remove('copying');
            }, 1000);
        });
    });
});

```
