Created
November 19, 2011 22:56
-
-
Save TeMPOraL/1379492 to your computer and use it in GitHub Desktop.
Nyan Cat emoticon bindings for Conkeror.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Google now uses "~=[,,_,,]:3" as an emoticon for Nyan Cat animation | |
on Google Plus. It's handy to have this character sequence bound to | |
a key. Thanks to Benjamin Slade for the idea. | |
Nyan Cat is bound by default to "N". As it is to be used when | |
editing a text field, you'll need to use "C-z" first, so the | |
sequence is: "C-z N". | |
Quick hack based on Conkeror source code; namely, | |
edit_field_in_external_editor from econtent-buffer-input.js. | |
Copyleft (<C) 2011-Eternity, Jacek "TeMPOraL" Zlydach. | |
(Technically, this code is on either Mozilla Public License v. 1.1, | |
GPL v. 2 or LGPL v. 2.1; see COPYING from Conkeror's source code for | |
details.) | |
*/ | |
function insert_nyancat_into_field (buffer, elem, doc) { | |
if (! doc) { | |
if (elem instanceof Ci.nsIDOMHTMLInputElement) { | |
var type = (elem.getAttribute("type") || "").toLowerCase(); | |
if (type == "hidden" || type == "checkbox" || type == "radio") | |
throw interactive_error("Element is not a text field."); | |
} else if (!(elem instanceof Ci.nsIDOMHTMLTextAreaElement)) | |
throw interactive_error("Element is not a text field."); | |
} | |
if (elem instanceof Ci.nsIDOMHTMLInputElement || | |
elem instanceof Ci.nsIDOMHTMLTextAreaElement) | |
{ | |
elem.value = elem.value + "~=[,,_,,]:3"; //insert Nyan Cat here... | |
} else { | |
elem.innerHTML = elem.innerHTML + "~=[,,_,,]:3"; //...and here. | |
} | |
} | |
interactive("insert-nyan-cat", | |
"Inserts Nyan Cat into currently focused textfield. Nyanyanyanyanyanyan!", | |
function (I) { | |
var b = I.buffer; | |
var e = b.focused_element; | |
var frame = b.focused_frame; | |
var doc = null; | |
if (e) { | |
if (e.contentEditable == 'true') | |
doc = e.ownerDocument; | |
} else if (frame && frame.document.designMode && | |
frame.document.designMode == "on") { | |
doc = frame.document; | |
e = frame.document.body; | |
} | |
yield insert_nyancat_into_field(b, e, doc); | |
}); | |
define_key(default_global_keymap, "N", "insert-nyan-cat"); //change your binding here. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment