Preview:
<script>
  document.addEventListener('DOMContentLoaded', function () {
      var codeBlocks = document.querySelectorAll('pre code');

      codeBlocks.forEach(function (codeBlock) {
          var copyButton = document.createElement('button');
          copyButton.className = 'copy-button';
          copyButton.textContent = 'Copy';

          copyButton.addEventListener('click', function () {
              var textArea = document.createElement('textarea');
              textArea.value = codeBlock.textContent;
              document.body.appendChild(textArea);
              textArea.select();
              document.execCommand('copy');
              document.body.removeChild(textArea);

              copyButton.textContent = 'Copied!';
              setTimeout(function () {
                  copyButton.textContent = 'Copy';
              }, 2000);
          });

          codeBlock.parentNode.insertBefore(copyButton, codeBlock);
      });
  });
</script>
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter