github_copy

copy button

  1. // ==UserScript==
  2. // @name github_copy
  3. // @version 0.0.2
  4. // @include http*://github.com/*
  5. // @description copy button
  6. // @namespace https://gf.qytechs.cn/users/164996a
  7. // ==/UserScript==
  8. const init = () => {
  9. const a = document.querySelector('.repository-content .BtnGroup + div')
  10. const b = document.querySelectorAll(
  11. 'table.js-file-line-container td.js-file-line'
  12. )
  13. if (!a || !b || b.length === 0) return
  14. a.insertAdjacentHTML(
  15. 'beforeend',
  16. `<button class="btn-octicon" aria-label="copy">
  17. <svg class="octicon octicon-clippy" viewBox="0 0 14 17" version="1.1" width="14" height="17" aria-hidden="true">
  18. <path fill-rule="evenodd" d="M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"></path>
  19. </svg>
  20. </button>`
  21. )
  22. const c = a.lastElementChild
  23. let d
  24. c.addEventListener('click', () => {
  25. d =
  26. d ||
  27. [...b].reduce(
  28. (a, c) => a + c.innerText + (c.innerText[0] === '\n' ? '' : '\n'),
  29. ''
  30. )
  31. navigator.clipboard.writeText(d)
  32. })
  33. }
  34.  
  35. init()
  36. document.addEventListener('pjax:success', () => init())

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址