Source for "Ctrl+Enter Submits"

By Timothy Babych
Has 2 other scripts.


// Ctrl+Enter Submits
// version 0.4
// 2005-09-26
// home: http://clear.com.ua/projects/firefox/ctrl_enter
// Copyright (c) 2005, Tim Babych
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Ctrl+Enter Submits", and click Uninstall.
//
// --------------------------------------------------------------------
//
// Opera 8 compartible.
//
// To install, download it to some folder and chose this folder in
// Tools > Preferences > Advanced > Content > Javascript Options
// "My Javascript files"
// Restart Opera
//
// To uninstall, remove the file from that folder.
//
// ---------------------------------------------------------------------
//
// ==UserScript==
// @name          Ctrl+Enter Submits
// @description   Allows submitting on Ctrl+Enter in any input and textarea
// @include        *
// ==/UserScript==

function zakavych(text) {
	
	replacements = [
	
	// cyrillic quotes
//	[/(\s+|^)"([^\"]+?)"(\s+|$|\.|\,)/g, '$1\u00ab$2\u00bb$3'],

	// latin quotes "test" becomes smart quotes
	[/(\s+|^)"([^\"]+?)"(\s+|$|\.|\,)/g,  '$1\u201c$2\u201d$3'],

	// ukrainian apostrophe
	[/([\u0406-\u0491])\*([\u0406-\u0491])/g, '$1\u2019$2'],
	
	// trademark (TM) and such
	[/\((tm|TM|\u0422\u041C|\u0442\u043C)\)/g, '\u2122'],
	
	// copyright (C) and such
	[/\([cC\u0421\u0441]\)/g, '\u00a9'],
	
	// registered (R) and such
	[/\([rR\u0420\u0440]\)/g, '\u00ae'],
	
	// mdash -- one or two minuses surrounded by spaces
	[/(\s+|^)--?(\s+)/g, '$1\u2014$2'],
	
	// **bold**	
	[/\*{2}(.*)\*{2}/g, '<b>$1</b>'],
	
	// //italic//
	[/([^\:]|^)\/{2}(.*?)\/{2}/g, '$1<i>$2</i>'],
	
	// --strikeout--
	[/([^\!]|^)-{2}(.*)-{2}/g, '$1<s>$2</s>'],

	// __underlined__
	[/_{2}(.*)_{2}/g, '<u>$1</u>'],
	
	// ndash for number ranges: 1995-2005
	[/(\d+)-(\d+)/g, '$1\u2013$2'],
	
	// ellipsis	
	[/\.\.\./g, '\u2026']
	
	];

	s = text
	for( i=0; i < replacements.length; i++) {
		s = s.replace(replacements[i][0], replacements[i][1])
	}
	
	return s
}

function trigger_submit_on_ctrl_enter(e) {
	if ((e.keyCode==13) && (e.ctrlKey)) {
		p = this.parentNode
		i = 0
		if (this.nodeName == 'TEXTAREA')
			this.value = zakavych(this.value)

		while (p.nodeName != 'FORM' && i++ < 100) 
			p = p.parentNode

		if (p.nodeName == 'FORM') 
			p.submit()
	}
}

if (document.evaluate) { // Firefox
	allInps = document.evaluate("//textarea | //select | //unput", document, null, 
									XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
	for (var i = 0; i < allInps.snapshotLength; i++) {
		t = allInps.snapshotItem(i);
		t.addEventListener("keydown", trigger_submit_on_ctrl_enter, 0);
	}
} else { // Opera does not support XPath
	elemTags = ['textarea', 'select', 'input']
	for(j = 0; j< elemTags.length; j++) {
		inps = document.getElementsByTagName(elemTags[j])
		for (var i = 0; i < inps.length; i++)
			inps[i].addEventListener("keydown", trigger_submit_on_ctrl_enter, 0);
	}
}