Github 跳转至 DeepWiki

在 Github 页面添加一个按钮,跳转至 DeepWiki

  1. // ==UserScript==
  2. // @name Jump to DeepWiki from Github
  3. // @name:zh-CN Github 跳转至 DeepWiki
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.1.4
  6. // @description Add a button to jump to DeepWiki from Github
  7. // @description:zh-CN 在 Github 页面添加一个按钮,跳转至 DeepWiki
  8. // @author shiquda
  9. // @namespace https://github.com/shiquda/shiquda_UserScript
  10. // @supportURL https://github.com/shiquda/shiquda_UserScript/issues
  11. // @match *://github.com/*
  12. // @include *://*github*/
  13. // @grant GM_addStyle
  14. // @grant GM_setValue
  15. // @grant GM_getValue
  16. // @license MIT
  17. // ==/UserScript==
  18.  
  19. // 判断当前path是否是一个 github repo,且位于项目的主页面
  20. function isGithubRepo(path) {
  21. path = path.slice(0, -1);
  22. return (path.split('/').length === 3);
  23. }
  24.  
  25. function CreateUI() {
  26. // 如果按钮已经存在,则不再创建
  27. if (document.querySelector('.deepwiki-button')) {
  28. return;
  29. }
  30.  
  31. const path = window.location.pathname;
  32. const deepwikiUrl = `https://deepwiki.com${path}`;
  33.  
  34. const button = document.createElement('button');
  35. button.classList.add('Box-sc-g0xbh4-0', 'exSala', 'prc-Button-ButtonBase-c50BI', 'deepwiki-button');
  36. button.setAttribute('type', 'button');
  37. button.setAttribute('data-size', 'small');
  38. button.setAttribute('data-variant', 'default');
  39.  
  40. const buttonContent = document.createElement('span');
  41. buttonContent.classList.add('Box-sc-g0xbh4-0', 'gUkoLg', 'prc-Button-ButtonContent-HKbr-');
  42.  
  43. const leadingVisual = document.createElement('span');
  44. leadingVisual.classList.add('prc-Button-Visual-2epfX', 'prc-Button-VisualWrap-Db-eB');
  45.  
  46. const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  47. svg.setAttribute('aria-hidden', 'true');
  48. svg.setAttribute('focusable', 'false');
  49. svg.setAttribute('class', 'size-4 transform transition-transform duration-700 group-hover:rotate-180 [&_path]:stroke-0');
  50. svg.setAttribute('viewBox', '110 110 460 500');
  51. svg.setAttribute('width', '16');
  52. svg.setAttribute('height', '16');
  53. svg.setAttribute('fill', 'currentColor');
  54. svg.style.verticalAlign = 'text-bottom';
  55.  
  56. // Create the three paths from the provided SVG
  57. const path1 = document.createElementNS('http://www.w3.org/2000/svg', 'path');
  58. path1.setAttribute('style', 'fill:currentColor');
  59. path1.setAttribute('d', 'M418.73,332.37c9.84-5.68,22.07-5.68,31.91,0l25.49,14.71c.82.48,1.69.8,2.58,1.06.19.06.37.11.55.16.87.21,1.76.34,2.65.35.04,0,.08.02.13.02.1,0,.19-.03.29-.04.83-.02,1.64-.13,2.45-.32.14-.03.28-.05.42-.09.87-.24,1.7-.59,2.5-1.03.08-.04.17-.06.25-.1l50.97-29.43c3.65-2.11,5.9-6.01,5.9-10.22v-58.86c0-4.22-2.25-8.11-5.9-10.22l-50.97-29.43c-3.65-2.11-8.15-2.11-11.81,0l-50.97,29.43c-.08.04-.13.11-.2.16-.78.48-1.51,1.02-2.15,1.66-.1.1-.18.21-.28.31-.57.6-1.08,1.26-1.51,1.97-.07.12-.15.22-.22.34-.44.77-.77,1.6-1.03,2.47-.05.19-.1.37-.14.56-.22.89-.37,1.81-.37,2.76v29.43c0,11.36-6.11,21.95-15.95,27.63-9.84,5.68-22.06,5.68-31.91,0l-25.49-14.71c-.82-.48-1.69-.8-2.57-1.06-.19-.06-.37-.11-.56-.16-.88-.21-1.76-.34-2.65-.34-.13,0-.26.02-.4.02-.84.02-1.66.13-2.47.32-.13.03-.27.05-.4.09-.87.24-1.71.6-2.51,1.04-.08.04-.16.06-.24.1l-50.97,29.43c-3.65,2.11-5.9,6.01-5.9,10.22v58.86c0,4.22,2.25,8.11,5.9,10.22l50.97,29.43c.08.04.17.06.24.1.8.44,1.64.79,2.5,1.03.14.04.28.06.42.09.81.19,1.62.3,2.45.32.1,0,.19.04.29.04.04,0,.08-.02.13-.02.89,0,1.77-.13,2.65-.35.19-.04.37-.1.56-.16.88-.26,1.75-.59,2.58-1.06l25.49-14.71c9.84-5.68,22.06-5.68,31.91,0,9.84,5.68,15.95,16.27,15.95,27.63v29.43c0,.95.15,1.87.37,2.76.05.19.09.37.14.56.25.86.59,1.69,1.03,2.47.07.12.15.22.22.34.43.71.94,1.37,1.51,1.97.1.1.18.21.28.31.65.63,1.37,1.18,2.15,1.66.07.04.13.11.2.16l50.97,29.43c1.83,1.05,3.86,1.58,5.9,1.58s4.08-.53,5.9-1.58l50.97-29.43c3.65-2.11,5.9-6.01,5.9-10.22v-58.86c0-4.22-2.25-8.11-5.9-10.22l-50.97-29.43c-.08-.04-.16-.06-.24-.1-.8-.44-1.64-.8-2.51-1.04-.13-.04-.26-.05-.39-.09-.82-.2-1.65-.31-2.49-.33-.13,0-.25-.02-.38-.02-.89,0-1.78.13-2.66.35-.18.04-.36.1-.54.15-.88.26-1.75.59-2.58,1.07l-25.49,14.72c-9.84,5.68-22.07,5.68-31.9,0-9.84-5.68-15.95-16.27-15.95-27.63s6.11-21.95,15.95-27.63Z');
  60.  
  61. const path2 = document.createElementNS('http://www.w3.org/2000/svg', 'path');
  62. path2.setAttribute('style', 'fill:currentColor');
  63. path2.setAttribute('d', 'M141.09,317.65l50.97,29.43c1.83,1.05,3.86,1.58,5.9,1.58s4.08-.53,5.9-1.58l50.97-29.43c.08-.04.13-.11.2-.16.78-.48,1.51-1.02,2.15-1.66.1-.1.18-.21.28-.31.57-.6,1.08-1.26,1.51-1.97.07-.12.15-.22.22-.34.44-.77.77-1.6,1.03-2.47.05-.19.1-.37.14-.56.22-.89.37-1.81.37-2.76v-29.43c0-11.36,6.11-21.95,15.96-27.63s22.06-5.68,31.91,0l25.49,14.71c.82.48,1.69.8,2.57,1.06.19.06.37.11.56.16.87.21,1.76.34,2.64.35.04,0,.09.02.13.02.1,0,.19-.04.29-.04.83-.02,1.65-.13,2.45-.32.14-.03.28-.05.41-.09.87-.24,1.71-.6,2.51-1.04.08-.04.16-.06.24-.1l50.97-29.43c3.65-2.11,5.9-6.01,5.9-10.22v-58.86c0-4.22-2.25-8.11-5.9-10.22l-50.97-29.43c-3.65-2.11-8.15-2.11-11.81,0l-50.97,29.43c-.08.04-.13.11-.2.16-.78.48-1.51,1.02-2.15,1.66-.1.1-.18.21-.28.31-.57.6-1.08,1.26-1.51,1.97-.07.12-.15.22-.22.34-.44.77-.77,1.6-1.03,2.47-.05.19-.1.37-.14.56-.22.89-.37,1.81-.37,2.76v29.43c0,11.36-6.11,21.95-15.95,27.63-9.84,5.68-22.07,5.68-31.91,0l-25.49-14.71c-.82-.48-1.69-.8-2.58-1.06-.19-.06-.37-.11-.55-.16-.88-.21-1.76-.34-2.65-.35-.13,0-.26.02-.4.02-.83.02-1.66.13-2.47.32-.13.03-.27.05-.4.09-.87.24-1.71.6-2.51,1.04-.08.04-.16.06-.24.1l-50.97,29.43c-3.65,2.11-5.9,6.01-5.9,10.22v58.86c0,4.22,2.25,8.11,5.9,10.22Z');
  64.  
  65. const path3 = document.createElementNS('http://www.w3.org/2000/svg', 'path');
  66. path3.setAttribute('style', 'fill:currentColor');
  67. path3.setAttribute('d', 'M396.88,484.35l-50.97-29.43c-.08-.04-.17-.06-.24-.1-.8-.44-1.64-.79-2.51-1.03-.14-.04-.27-.06-.41-.09-.81-.19-1.64-.3-2.47-.32-.13,0-.26-.02-.39-.02-.89,0-1.78.13-2.66.35-.18.04-.36.1-.54.15-.88.26-1.76.59-2.58,1.07l-25.49,14.72c-9.84,5.68-22.06,5.68-31.9,0-9.84-5.68-15.96-16.27-15.96-27.63v-29.43c0-.95-.15-1.87-.37-2.76-.05-.19-.09-.37-.14-.56-.25-.86-.59-1.69-1.03-2.47-.07-.12-.15-.22-.22-.34-.43-.71-.94-1.37-1.51-1.97-.1-.1-.18-.21-.28-.31-.65-.63-1.37-1.18-2.15-1.66-.07-.04-.13-.11-.2-.16l-50.97-29.43c-3.65-2.11-8.15-2.11-11.81,0l-50.97,29.43c-3.65,2.11-5.9,6.01-5.9,10.22v58.86c0,4.22,2.25,8.11,5.9,10.22l50.97,29.43c.08.04.17.06.25.1.8.44,1.63.79,2.5,1.03.14.04.29.06.43.09.8.19,1.61.3,2.43.32.1,0,.2.04.3.04.04,0,.09-.02.13-.02.88,0,1.77-.13,2.64-.34.19-.04.37-.1.56-.16.88-.26,1.75-.59,2.57-1.06l25.49-14.71c9.84-5.68,22.06-5.68,31.91,0,9.84,5.68,15.95,16.27,15.95,27.63v29.43c0,.95.15,1.87.37,2.76.05.19.09.37.14.56.25.86.59,1.69,1.03,2.47.07.12.15.22.22.34.43.71.94,1.37,1.51,1.97.1.1.18.21.28.31.65.63,1.37,1.18,2.15,1.66.07.04.13.11.2.16l50.97,29.43c1.83,1.05,3.86,1.58,5.9,1.58s4.08-.53,5.9-1.58l50.97-29.43c3.65-2.11,5.9-6.01,5.9-10.22v-58.86c0-4.22-2.25-8.11-5.9-10.22Z');
  68.  
  69. // Append paths to SVG
  70. svg.appendChild(path1);
  71. svg.appendChild(path2);
  72. svg.appendChild(path3);
  73.  
  74. leadingVisual.appendChild(svg);
  75.  
  76. const text = document.createElement('span');
  77. text.classList.add('prc-Button-Label-pTQ3x');
  78. text.textContent = 'DeepWiki';
  79.  
  80. buttonContent.appendChild(leadingVisual);
  81. buttonContent.appendChild(text);
  82. button.appendChild(buttonContent);
  83.  
  84. button.addEventListener('click', () => {
  85. window.open(deepwikiUrl, '_blank');
  86. });
  87.  
  88. const li = document.createElement('li');
  89. li.appendChild(button);
  90. document.querySelector('ul.pagehead-actions').insertBefore(li, document.querySelector('ul.pagehead-actions').firstChild);
  91. }
  92.  
  93. function checkAndCreateUI() {
  94. const path = window.location.pathname;
  95. if (isGithubRepo(path)) {
  96. CreateUI();
  97. }
  98. }
  99.  
  100. (function () {
  101. "use strict";
  102.  
  103. // 初始检查
  104. checkAndCreateUI();
  105.  
  106. // 监听页面变化
  107. const observer = new MutationObserver((mutations) => {
  108. // 检查页面头部是否存在
  109. if (document.querySelector('.pagehead-actions')) {
  110. checkAndCreateUI();
  111. }
  112. });
  113.  
  114. // 监听整个body的变化
  115. observer.observe(document.body, {
  116. childList: true,
  117. subtree: true
  118. });
  119.  
  120. // 监听URL变化(适用于单页应用)
  121. let lastUrl = location.href;
  122. new MutationObserver(() => {
  123. const url = location.href;
  124. if (url !== lastUrl) {
  125. lastUrl = url;
  126. checkAndCreateUI();
  127. }
  128. }).observe(document, { subtree: true, childList: true });
  129. })();

QingJ © 2025

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