Add GitHack Links To GitHub Files

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

  1. // ==UserScript==
  2. // @name Add GitHack Links To GitHub Files
  3. // @namespace Violentmonkey Scripts
  4. // @match https://github.com/*
  5. // @grant none
  6. // @version 0.0.2
  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 rawButtonAppended {
  15. from{
  16. background-position-x: 1px;
  17. }
  18. to{
  19. background-position-x: 2px;
  20. }
  21. }
  22. [data-testid="raw-button"]:not([ls4yu]) {
  23. animation: rawButtonAppended 1ms linear 0s 1 normal forwards;
  24. }
  25.  
  26.  
  27. `;
  28. function f101(rawButton) {
  29. rawButton.setAttribute('ls4yu', '');
  30. const newButton = rawButton.cloneNode(true);
  31. newButton.innerHTML = newButton.innerHTML.replace('Raw', 'GitHack');
  32. const newURL = newButton.href.replace(/^https\:\/\/github.com\/([-\w]+)\/([-\w.]+)\/(blob|raw)\/([-\w\/\.]+)$/g,
  33. (_, u, r, x1, k) => `https://raw.githack.com/${u}/${r}/${k}`
  34. );
  35. newButton.href = newURL;
  36. rawButton.parentNode.insertBefore(newButton, rawButton.nextSibling);
  37. }
  38.  
  39.  
  40. document.addEventListener('animationstart', (evt) => {
  41. const animationName = evt.animationName;
  42. if (!animationName) return;
  43. if (animationName === 'rawButtonAppended') {
  44. f101(evt.target);
  45. }
  46. }, { passive: true, capture: true });
  47.  
  48. GM_addStyle(cssText);