GitHub Repo Share-to-Twitter Button

Add a Twitter share button to repository page

  1. // ==UserScript==
  2. // @name GitHub Repo Share-to-Twitter Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Add a Twitter share button to repository page
  6. // @author eggplants
  7. // @homepage https://github.com/eggplants
  8. // @match https://github.com/*/*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (window.onload = function() {
  14. "use strict";
  15.  
  16. const description = document.title;
  17. const pg_link = location.href;
  18.  
  19. var a = document.getElementsByClassName('pagehead-actions flex-shrink-0 d-none d-md-inline')[0];
  20. var b = document.createElement('a');
  21. b.className = 'btn btn-sm';
  22. b.setAttribute('target', '_blank');
  23. b.href = 'http://twitter.com/share?text="' + description + '"%0a%0a' + pg_link;
  24. b.textContent = 'Share to Twitter';
  25.  
  26. var c = document.createElement('li');
  27. c.appendChild(b);
  28.  
  29. a.insertBefore(c, document.getElementsByClassName('pagehead-actions flex-shrink-0 d-none d-md-inline')[0].children[0]);
  30. }());