GitHub to DeepWiki Button

Adds a button to GitHub pages to open the corresponding page on DeepWiki.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         GitHub to DeepWiki Button
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Adds a button to GitHub pages to open the corresponding page on DeepWiki.
// @author       You
// @match        https://github.com/*/*
// @icon         https://www.google.com/as2/favicons?sz=64&domain=github.com
// @grant        none
// @license MIT
// @run-at       document-idle
// ==/UserScript==

;(function () {
  'use strict'
  function addButton() {
    const actionsList = document.querySelector('.AppHeader-actions')

    if (!actionsList) {
      return false
    }

    if (document.getElementById('deepwiki-button')) {
      return true
    }

    const button = document.createElement('button')
    button.textContent = 'Open in DeepWiki'
    button.id = 'deepwiki-button'
    button.type = 'button'

    button.classList.add('btn', 'btn-sm')
    button.addEventListener('click', function () {
      const deepwikiUrl = window.location.href.replace('github.com', 'deepwiki.com')
      window.open(deepwikiUrl, '_blank')
    })
    actionsList.appendChild(button)
    console.log('Tampermonkey - GitHub to DeepWiki: Button added successfully.')
    return true
  }

  if (!addButton()) {
    const retryInterval = setInterval(() => {
      if (addButton()) {
        clearInterval(retryInterval)
      }
    }, 500)
    setTimeout(() => {
      clearInterval(retryInterval)

      if (!document.getElementById('deepwiki-button')) {
        console.warn('Tampermonkey - GitHub to DeepWiki: Failed to add button after multiple retries.')
      }
    }, 5000)
  }
})()