Gist to dabblet

By Mottie Last update Mar 4, 2013 — Installed 469 times.

There are 5 previous versions of this script.

// ==UserScript==
// @name          Gist to dabblet
// @namespace     gist2dabblet
// @description   Add a dabblet.com link button to any gist with dabblet information
// @version       1.3
// @include       https://gist.github.com/*
// @author        Rob Garrison >> http://github.com/Mottie
// @icon          https://github.com/Mottie/gist-to-dabblet/raw/master/images/g2d.png
// ==/UserScript==

var main = function () {
	var dab, b, loc = window.location,
		gist = $('#file-dabblet-css'),
		list = $('.css-truncate-target:contains(dabblet.css)');
	if ( gist.length || list.length ){
		b = '<span class="mini-icon" style="background:url(https://github.com/Mottie/gist-to-dabblet/raw/master/images/dabblet';
		if (gist.length) {
			b += '.png)"></span>dabblet</a></li>'; // use black icon
			dab = '<li><a href="http://dabblet.com/gist/' + loc.pathname.match(/\d+$/) + '" class="minibutton dabblet">' + b;
			$('.pagehead-actions').prepend(dab);
		} else {
			b += '-g.png)"></span> dabblet</a></li>'; // use grey icon
			list.each(function(){
				dab = '<li><a href="' + $(this).parent().attr('href') + '" class="dabblet" title="Open at dabblet.com">' + b;
				$(this).closest('.byline').prev().css('z-index',1).prepend(dab);
			});
			$('.dabblet').tipsy({ gravity: 'n' });
		}
	}
};

// Inject our main script
// Chrome seems to inject the script on all pages, so lets check first
if (/gist\.github\.com/.test(window.location.href)) {
	var script = document.createElement('script');
	script.textContent = '(' + main.toString() + ')();';
	document.body.appendChild(script);
}