GitHubSourceTreeLink

Adds a "Clone in SourceTree" link to github pages. Based on jamesgarfield/GitHubSourceTree.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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			GitHubSourceTreeLink
// @namespace		https://github.com/cunneen
// @version			1.0.0
// @description		Adds a "Clone in SourceTree" link to github pages. Based on jamesgarfield/GitHubSourceTree.
// @respository		https://github.com/cunneen/GitHubSourceTreeLink
// @match			https://github.com/*
// @match			https://*.github.com/*
// @grant			none
// @license			MIT
// @copyright		2025, Mike Cunneen
// @run-at			document-idle
// @homepageURL		https://github.com/cunneen/GitHubSourceTreeLink
// @supportURL		https://github.com/cunneen/GitHubSourceTreeLink/issues
// ==/UserScript==

/* jshint esversion: 11 */
//Firefox/GreaseMonkey apppears to not like IIFEs, so use of a named function is required
ghst();
function ghst(){
    const $ = document.querySelectorAll.bind(document);

    //Defining constants
    const sourceTreeUrlPrefix = "x-github-client://openRepo/";
    //GitHub's "Code" dropdown Button
    const gitHubNode = $("react-partial[partial-name='repos-overview'] button[aria-haspopup=true][aria-describedBy$='-loading-announcement'][data-variant='primary']")[0];
    //This is the node before which we're going to insert the new button
    const insertBeforeNode = document.querySelector(".Layout-sidebar > div > div:first-child h2");
    const parentNode = insertBeforeNode.parentNode;


    const sourceTreeNode = document.createElement("a");
    const cloneURL = getSelectedCloneUrl();
    sourceTreeNode.href = sourceTreeUrlPrefix + cloneURL;
    sourceTreeNode.innerHTML = '<span class="octicon octicon-device-desktop"></span>&nbsp;Clone in SourceTree';

    parentNode.insertBefore(sourceTreeNode, insertBeforeNode);

    //Function returns currently selected clone url
    function getSelectedCloneUrl() {
      const reposOverview = JSON.parse(document.body.querySelectorAll('[partial-name="repos-overview"] [data-target="react-partial.embeddedData"][type="application/json"]')[0].textContent) ;

      return reposOverview?.props?.initialPayload?.overview?.codeButton?.local?.protocolInfo?.httpUrl ;
    }
}