github-go-deepwiki

github仓库跳转到deepwiki

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         github-go-deepwiki
// @namespace
// @version      0.3
// @description  github仓库跳转到deepwiki
// @source       https://github.com/gxr404/go-deepwiki
// @author       gxr404
// @match        https://github.com/*
// @grant        none
// @namespace 
// ==/UserScript==
(function() {
  'use strict';

  const bodyEl = document.querySelector('body')
  if (bodyEl) {
      watchDom(bodyEl, main)
      main()
  }
})();

function watchDom(dom, callback) {
  const observer = new MutationObserver(() => {
    callback()
  })
  observer.observe(dom, {
    childList: true,
    subtree: true,
  })
}

function main() {
  // match https://github.com/<user>/<repo>
  if (location.pathname.split('/').filter(Boolean).length !== 2) return
  if (document.getElementById('go-deepwiki')) return
  const repoBtnContainer = document.getElementById('repository-details-container')
  if (!repoBtnContainer) return
  const btnList = repoBtnContainer.querySelector('ul')
  if (!btnList) return
  btnList.appendChild(createGoDeepWikiDOM())
}

function createGoDeepWikiDOM() {
  const li = document.createElement('li')
  const repName = location.pathname.split('/').filter(Boolean).slice(0,2).join('/')
  const deepWikiUrl = `https://deepwiki.com/${repName}`
  li.innerHTML = `
<li id="go-deepwiki">
  <div data-view-component="true" class="BtnGroup d-flex">
      <a href="${deepWikiUrl}"
        rel="nofollow"
        aria-label="Go DeepDeepwikiWiki"
        data-view-component="true"
        class="tooltipped tooltipped-sw btn-sm btn">
        Go Deepwiki
      </a>
  </div>
</li>
`
  return li
}