Open GitHub jupyter in Colab

Add a Colab link for GitHub .ipynb file

安裝腳本?
作者推薦腳本

您可能也會喜歡 Go Sci-hub Back

安裝腳本
  1. // ==UserScript==
  2. // @name Open GitHub jupyter in Colab
  3. // @name:zh-CN 在Colab中打开GitHub Jupyter
  4. // @namespace https://github.com/windingwind/Open-GitHub-Jupyter-in-Colab
  5. // @version 0.1
  6. // @description Add a Colab link for GitHub .ipynb file
  7. // @description:zh-CN 在GitHub .ipynb 添加Colab链接
  8. // @author winding
  9. // @include *://github.com/*
  10. // @grant none
  11. // @require https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js
  12. // @supportURL https://github.com/windingwind/Open-GitHub-Jupyter-in-Colab/blob/master/README.md
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. function addColabBtn(){
  19. const r = new RegExp(/https?:\/\/github.com[^/]*\//g);
  20. let link = window.location.href;
  21. $('.Box-header').children('.text-mono').next().prepend('<button id="BtnColab" class="btn btn-sm" style="background-color: #ff9800; margin-right: 5px;">Open in Colab</button>');
  22. $('#BtnColab').click(function(){
  23. window.open(link.replace(r, 'https://colab.research.google.com/github/'));
  24. });
  25. }
  26. function addFileListBtn() {
  27. $('[aria-labelledby="files"]').find('[role="rowheader"]').each(function(i,e){
  28. try{
  29. let file = $(e).find('a').text();
  30. if(file.indexOf('.ipynb')>=0){
  31. let link = 'https://colab.research.google.com/github'+$(e).find('a').attr("href");
  32. $(e).before(`<a role='gridcell' id='FileListBtnColab' href=${link} target="_blank" style='margin: 0 5px 0 5px;'>
  33. <img height='25px' src='https://raw.githubusercontent.com/windingwind/Open-GitHub-Jupyter-in-Colab/master/colab.png'/>
  34. </a>`);
  35. }
  36. }
  37. catch(e){
  38. console.warn(e);
  39. }
  40. })
  41. }
  42. function checkColabBtn(){
  43. if($('#BtnColab').length == 0){
  44. addColabBtn();
  45. }
  46. if($('#FileListBtnColab').length == 0){
  47. addFileListBtn();
  48. }
  49. }
  50. function main(){
  51. addColabBtn();
  52. addFileListBtn();
  53. setInterval(checkColabBtn, 1500);
  54. }
  55. main();
  56. })();