GitHub to DeepWiki Button

在GitHub仓库页面插入Go DeepWiki按钮,跳转到对应DeepWiki页面

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         GitHub to DeepWiki Button
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  在GitHub仓库页面插入Go DeepWiki按钮,跳转到对应DeepWiki页面
// @author       teddyxiong53
// @match        https://github.com/*/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    // 按钮唯一标识,防止重复插入
    const BUTTON_ID = 'go-deepwiki-btn';
    // 监听目标区域变化
    function insertButtonIfNeeded() {
        const titleContainer = document.querySelector('.pagehead-actions');
        if (!titleContainer) return;
        if (document.getElementById(BUTTON_ID)) return;
        const button = document.createElement('button');
        button.id = BUTTON_ID;
        button.className = 'btn ml-2';
        button.style.backgroundColor = '#2da44e';
        button.style.color = 'white';
        button.textContent = 'Go DeepWiki';
        button.addEventListener('click', function() {
            const currentUrl = window.location.href;
            const newUrl = currentUrl.replace('github.com', 'deepwiki.com');
            window.open(newUrl, '_blank');
        });
        titleContainer.prepend(button);
    }
    // MutationObserver用于兼容GitHub的动态页面
    const observer = new MutationObserver(function() {
        insertButtonIfNeeded();
    });
    function tryObserve() {
        const titleContainer = document.querySelector('.pagehead-actions');
        if (titleContainer) {
            observer.observe(titleContainer, {childList: true, subtree: false});
            insertButtonIfNeeded();
        } else {
            // 页面未加载完全时重试
            setTimeout(tryObserve, 500);
        }
    }
    // 页面加载后启动监听
    window.addEventListener('load', tryObserve);
    // 兼容pjax页面切换
    document.addEventListener('pjax:end', insertButtonIfNeeded);
})();