GitHub to DeepWiki

Add a hyperlink-style button to the About section of GitHub repository pages to jump to the corresponding DeepWiki page

  1. // ==UserScript==
  2. // @name GitHub to DeepWiki
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @license MIT
  6. // @description Add a hyperlink-style button to the About section of GitHub repository pages to jump to the corresponding DeepWiki page
  7. // @author Monkee
  8. // @match https://github.com/*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // 检查当前页面是否是 GitHub 仓库页面
  16. const pathParts = window.location.pathname.split('/');
  17. if (pathParts.length >= 3 && pathParts[1] !== '' && pathParts[2] !== '') {
  18. const owner = pathParts[1];
  19. const repo = pathParts[2];
  20.  
  21. // 创建超链接
  22. const link = document.createElement('a');
  23. link.href = `https://deepwiki.com/${owner}/${repo}`;
  24. link.target = '_blank';
  25. link.style.display = 'block';
  26. link.style.marginTop = '10px';
  27. link.style.color = '#6a737d'; // 与About模块中其他链接的颜色一致
  28. link.style.textDecoration = 'none';
  29.  
  30. // 创建图标
  31. const icon = document.createElement('span');
  32. icon.className = 'octicon octicon-link'; // 使用GitHub的octicon图标
  33. icon.style.marginRight = '5px';
  34. icon.style.color = '#6a737d'; // 与文本颜色一致
  35.  
  36. // 设置超链接文本
  37. const text = document.createTextNode('View on DeepWiki');
  38.  
  39. // 将图标和文本添加到超链接
  40. link.appendChild(icon);
  41. link.appendChild(text);
  42.  
  43. // 鼠标悬停时显示下划线
  44. link.addEventListener('mouseenter', function() {
  45. link.style.textDecoration = 'underline';
  46. });
  47. link.addEventListener('mouseleave', function() {
  48. link.style.textDecoration = 'none';
  49. });
  50.  
  51. // 寻找 "About" 模块
  52. const aboutSection = document.querySelector('.BorderGrid-cell');
  53. if (aboutSection) {
  54. // 插入超链接到 "About" 模块的底部
  55. aboutSection.appendChild(link);
  56. } else {
  57. // 如果上面的选择器无效,尝试其他选择器
  58. const sidebar = document.querySelector('.repository-content .BorderGrid');
  59. if (sidebar) {
  60. const aboutCell = Array.from(sidebar.querySelectorAll('.BorderGrid-cell')).find(cell => cell.querySelector('h2') && cell.querySelector('h2').textContent.trim() === 'About');
  61. if (aboutCell) {
  62. aboutCell.appendChild(link);
  63. }
  64. }
  65. }
  66. }
  67. })();

QingJ © 2025

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