github-jump

Read github code by jumping to vscode with one click

  1. // ==UserScript==
  2. // @name github-jump
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description Read github code by jumping to vscode with one click
  6. // @author xrz
  7. // @match https://github.com/*/*
  8. // @icon https://github1s.com/favicon.ico
  9. // @grant GM_addStyle
  10. // ==/UserScript==
  11.  
  12. GM_addStyle(".jump-btn{color: var(--color-btn-primary-text)!important;background-color:var(--color-btn-primary-bg)!important}");
  13.  
  14. (function() {
  15. 'use strict';
  16. const btnMap = new Map([['Github1s','github1s.com'],['GithubDev','github.dev']]);
  17.  
  18. function createAndAddButton(text, targetUrl) {
  19. const button = document.createElement("li");
  20. button.innerHTML = text;
  21. button.className = 'btn btn-sm jump-btn';
  22. const li = document.getElementsByClassName('pagehead-actions flex-shrink-0 d-none d-md-inline').item(0)?.getElementsByTagName('li')[0]
  23. document.getElementsByClassName('pagehead-actions flex-shrink-0 d-none d-md-inline').item(0)?.insertBefore(button, li)
  24. button.onclick = function() {
  25. const href = top.location.href.replace('github.com', targetUrl);
  26. window.open(href,'_blank');
  27. }
  28. }
  29.  
  30. for (let [key, value] of btnMap.entries()) {
  31. createAndAddButton(key, value);
  32. }
  33. })();