Greasy Fork is available in English.

Copy code xda

copy code from code block with one click/tap

  1. // ==UserScript==
  2. // @name Copy code xda
  3. // @match https://forum.xda-developers.com/t/*
  4. // @grant GM_setClipboard
  5. // @namespace xda
  6. // @version 0.1
  7. // @description copy code from code block with one click/tap
  8. // @author drakulaboy
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const codeBlocks = document.querySelectorAll('div.bbCodeBlock-content');
  16. codeBlocks.forEach(block => {
  17. // Create a button element and add it before the code block
  18. const button = document.createElement('button');
  19. button.textContent = 'Copy';
  20. block.parentNode.insertBefore(button, block);
  21.  
  22. // When the button is clicked, copy the code to the clipboard
  23. button.addEventListener('click', () => {
  24. const code = block.innerText;
  25. GM_setClipboard(code);
  26. alert('Code is copied in the clipboard!');
  27. });
  28. });
  29. })();