Add Raw link To GitHub Files

12/13/2023, 1:18:04 AM

目前为 2024-12-22 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Add Raw link To GitHub Files
  3. // @namespace Violentmonkey Scripts
  4. // @match https://github.com/*
  5. // @grant none
  6. // @version 0.0.1
  7. // @description 12/13/2023, 1:18:04 AM
  8. // @grant GM_addStyle
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. const cssText = `
  13.  
  14. @keyframes button384 {
  15. from{
  16. background-position-x: 1px;
  17. }
  18. to{
  19. background-position-x: 2px;
  20. }
  21. }
  22. [aria-label="Copy file name to clipboard"]:not([ls4yu]) {
  23. animation: button384 1ms linear 0s 1 normal forwards;
  24. }
  25.  
  26. .button385 {
  27. margin: 4px 2px;
  28. }
  29.  
  30. `;
  31. function f101(btn) {
  32. btn.setAttribute('ls4yu', '');
  33. let p = btn;
  34. let link;
  35. while ((p = p.parentNode) instanceof HTMLElement) {
  36. link = p.querySelector('a[href*="#diff-"]');
  37. if (link) {
  38. break;
  39. }
  40. }
  41. if (!link) return;
  42. p = link.parentElement;
  43. if (!p) return;
  44.  
  45.  
  46. if (p.querySelector('.button385')) return;
  47.  
  48. const code = link.querySelector('code');
  49. if (!code) return;
  50. const text = code.textContent.trim().replace(decodeURIComponent('%E2%80%8E'), '').trim();
  51.  
  52.  
  53. let commitId = '';
  54.  
  55. const m = /\/([\w\-]+)\/([\w\-]+)\/commit\/([0-9a-f]{40})(#|$)/.exec(location.pathname);
  56.  
  57. if (m && m[3]) {
  58. commitId = m[3];
  59. }
  60.  
  61. if (commitId) {
  62.  
  63. const a = document.createElement('a');
  64. a.classList.add('button385');
  65. p.insertBefore(a, link);
  66.  
  67. a.textContent = 'RAW';
  68. a.style.cursor = 'pointer';
  69.  
  70.  
  71.  
  72.  
  73. a.setAttribute('href', `https://github.com/${m[1]}/${m[2]}/raw/${commitId}/${text}`)
  74.  
  75. }
  76.  
  77. }
  78.  
  79.  
  80. document.addEventListener('animationstart', (evt) => {
  81. const animationName = evt.animationName;
  82. if (!animationName) return;
  83. if (animationName === 'button384') {
  84. f101(evt.target);
  85. }
  86. }, { passive: true, capture: true });
  87.  
  88. GM_addStyle(cssText);

QingJ © 2025

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