github-go-deepwiki

github仓库跳转到deepwiki

目前为 2025-04-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name github-go-deepwiki
  3. // @namespace
  4. // @version 0.2
  5. // @description github仓库跳转到deepwiki
  6. // @source https://github.com/gxr404/go-deepwiki
  7. // @author gxr404
  8. // @match https://github.com/*
  9. // @grant none
  10. // @namespace
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14.  
  15. const bodyEl = document.querySelector('body')
  16. if (bodyEl) {
  17. watchDom(bodyEl, main)
  18. main()
  19. }
  20. })();
  21.  
  22. function watchDom(dom, callback) {
  23. const observer = new MutationObserver(() => {
  24. callback()
  25. })
  26. observer.observe(dom, {
  27. childList: true,
  28. subtree: true,
  29. })
  30. }
  31.  
  32. function main() {
  33. if (document.getElementById('go-deepwiki')) return
  34. const repoBtnContainer = document.getElementById('repository-details-container')
  35. if (!repoBtnContainer) return
  36. const btnList = repoBtnContainer.querySelector('ul')
  37. if (!btnList) return
  38. btnList.appendChild(createGoDeepWikiDOM())
  39. }
  40.  
  41. function createGoDeepWikiDOM() {
  42. const li = document.createElement('li')
  43. const repName = location.pathname.split('/').filter(Boolean).slice(0,2).join('/')
  44. const deepWikiUrl = `https://deepwiki.com/${repName}`
  45. li.innerHTML = `
  46. <li id="go-deepwiki">
  47. <div data-view-component="true" class="BtnGroup d-flex">
  48. <a href="${deepWikiUrl}"
  49. rel="nofollow"
  50. aria-label="Go DeepDeepwikiWiki"
  51. data-view-component="true"
  52. class="tooltipped tooltipped-sw btn-sm btn">
  53. Go Deepwiki
  54. </a>
  55. </div>
  56. </li>
  57. `
  58. return li
  59. }