Skip to content

Instantly share code, notes, and snippets.

@lantrix
Forked from abernier/README.md
Last active August 29, 2015 14:08
Show Gist options
  • Save lantrix/be6feabbc44328d85dde to your computer and use it in GitHub Desktop.
Save lantrix/be6feabbc44328d85dde to your computer and use it in GitHub Desktop.
'Clone in Mac' button on gists for GitHub

Download the user.js file and then drop it into your chrome://extensions/ tab and enjoy the Clone in Desktop button on your gists!

// ==UserScript==
// @id clonegistindesktop
// @name Clone gist in Desktop
// @author Antoine BERNIER (abernier) - Fix by @lantrix
// @version 0.0.2
// @description Add a 'Clone in Desktop' button to gists
// @match https://gist.github.com/*
// ==/UserScript==
(function () {
var li = document.createElement('li');
var downloadLi = document.querySelector('a[href*="/download"]').parentNode;
var repoUrl = document.querySelector('input[name="url-field"]').getAttribute('value');
// make a copy of the download li
li.innerHTML = downloadLi.innerHTML;
// Change some things
li.innerHTML = li.innerHTML.replace(/href="[^"]*"/, 'href="github-mac://openRepo/' + repoUrl + '"');
li.innerHTML = li.innerHTML.replace('Download Gist', 'Clone in Desktop');
li.innerHTML = li.innerHTML.replace('octicon-cloud-download', 'octicon-device-desktop');
// insert just before
downloadLi.parentNode.insertBefore(li, downloadLi);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment