// ==UserScript==
// @name			Betterblogger
// @namespace
// @description		Modifies Blogger post UI for <i>, <b>, and adds CTRL-SHIFT-Q via attribution
// @include			http://www.blogger.com/post-*
// @include			http://blogger.com/post-*
// ==/UserScript==

/** licenced under a Creative Commons Attribution-NonCommercial-ShareAlike 2.0
 ** http://creativecommons.org/licenses/by-nc-sa/2.0/
 **
 ** Code by:
 **
 ** 	Michael Kennan, foobario@yahoo.com
 **
 ** This is a greasemonkey script, for use with the Firefox extension Greasemonkey.
 ** More info: http://greasemonkey.mozdev.org/
 **/

Textbar.Bold = function()
{
	this.wrapSelection('<b>','</b>');
}

Textbar.Italic = function()
{
	this.wrapSelection('<i>','</i>');
}

Textbar.Via = function()
{
	var my_link = prompt("Enter URL:","http://");
	var my_text = prompt("Enter link text:","");
	if (my_link != null && my_text != null) {
		via = "<span class=\"via\">[via <a href=\"" + my_link + "\">" + my_text + "</a>]</span>";
		this.wrapSelection("", via);
	}
}

Textbar.activateKeyCommands = function(e) {
	if (Detect.IE()) e = window.event;

	setKeysetByEvent(e);

	if (!Detect.SAFARI()) {
		CTRL_SHFT_Q = (IE_CTRL_SHIFT_KEYSET) ? isKeyPressedWithCtrlShift(17, e) : isKeyPressedWithCtrlShift(81, e);
		if (CTRL_SHFT_Q) Textbar.Via();
	}

	CTRL_Q = (IE_KEYSET) ? isKeyPressedWithCtrl(81, e) : isKeyPressedWithCtrl(113, e);

	// prevent sidebars or dialogs from opening with reserved keypresses
	if (CTRL_Q) {
		if (Detect.IE()) {
			e.returnValue = false;
		} else {
			e.preventDefault();
		}
	}
	return true;
}