GitHub DeepWiki Link

在GitHub项目主页添加DeepWiki链接

  1. // ==UserScript==
  2. // @name GitHub DeepWiki Link
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description 在GitHub项目主页添加DeepWiki链接
  6. // @author zerah
  7. // @match https://github.com/*/*
  8. // @grant none
  9. // @run-at document-idle
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // 初始化变异观察器
  17. function initMutationObserver() {
  18. const targetNode = document.body;
  19.  
  20. // 观察器配置
  21. const config = {
  22. childList: true,
  23. subtree: true
  24. };
  25.  
  26. // 创建观察器实例
  27. const observer = new MutationObserver((mutationsList) => {
  28. for(const mutation of mutationsList) {
  29. if (mutation.type === 'childList') {
  30. const publicLabel = document.querySelector('.Label--secondary.v-align-middle.mr-1');
  31. if (publicLabel && !document.querySelector('.deepwiki-link')) {
  32. addDeepWikiLink(publicLabel);
  33. // 一旦添加了链接,就不再需要继续监视
  34. // observer.disconnect();
  35. // 但我们保持观察,以防导航到其他页面
  36. }
  37. }
  38. }
  39. });
  40.  
  41. // 开始观察
  42. observer.observe(targetNode, config);
  43. }
  44.  
  45. // 立即运行一次,以防元素已经存在
  46. setTimeout(() => {
  47. const publicLabel = document.querySelector('.Label--secondary.v-align-middle.mr-1');
  48. if (publicLabel) {
  49. addDeepWikiLink(publicLabel);
  50. }
  51.  
  52. // 无论是否找到元素,都启动观察器
  53. initMutationObserver();
  54. }, 500);
  55.  
  56. function addDeepWikiLink(publicLabel) {
  57. // 获取项目路径,例如 qzz0518/coss
  58. const pathParts = window.location.pathname.split('/');
  59. if (pathParts.length < 3) return; // 不是项目页面
  60.  
  61. const owner = pathParts[1];
  62. const repo = pathParts[2];
  63.  
  64. // 确保我们在项目的主页上
  65. if (pathParts.length > 3 && pathParts[3] !== '') return;
  66.  
  67. // 检查是否已经添加了DeepWiki链接
  68. if (publicLabel.parentNode.querySelector('.deepwiki-link')) return;
  69.  
  70. // 创建DeepWiki链接
  71. const deepWikiLink = document.createElement('a');
  72. deepWikiLink.href = `https://deepwiki.com/${owner}/${repo}`;
  73. deepWikiLink.target = '_blank'; // 在新窗口打开
  74. deepWikiLink.className = 'Label Label--secondary v-align-middle mr-1 deepwiki-link';
  75. deepWikiLink.textContent = 'DeepWiki';
  76. deepWikiLink.style.textDecoration = 'none';
  77. deepWikiLink.style.cursor = 'pointer';
  78.  
  79. // 在Public标签后面插入DeepWiki链接
  80. publicLabel.parentNode.insertBefore(deepWikiLink, publicLabel.nextSibling);
  81. }
  82. })();

QingJ © 2025

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