Created
February 10, 2012 20:58
-
-
Save rlemon/1792841 to your computer and use it in GitHub Desktop.
SE Chat Emoticons userscript
This file contains 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
// ==UserScript== | |
// @name SE Chat Emoticons | |
// @author Robert Lemon | |
// @namespace http://rlemon.com | |
// @description Replaces frequently used emoticons with images in the chat system. | |
// @include http://chat.stackexchange.com/rooms/* | |
// @include http://chat.stackoverflow.com/rooms/* | |
// ==/UserScript== | |
/* RIGHT NOW I LAGG REALLY BAD */ | |
function EmbedCodeOnPage(type, kode) { | |
var elm = document.createElement(type); | |
elm.textContent = kode; | |
document.head.appendChild(elm); | |
} | |
function EmbedFunctionOnPageAndExecute(fn) { | |
EmbedCodeOnPage("script", "(" + fn.toString() + ")()"); | |
} | |
var css = ".emoticon{background-image:url(http://i.stack.imgur.com/QZvZ0.png);height:16px;width:16px;display:inline-block}.emoticon.e0{background-position:0px 0px}.emoticon.e1{background-position:-16px 0px}.emoticon.e2{background-position:-32px 0px}.emoticon.e3{background-position:-48px 0px}.emoticon.e4{background-position:-64px 0px}.emoticon.e5{background-position:-80px 0px}.emoticon.e6{background-position:-96px 0px}.emoticon.e7{background-position:-112px 0px}.emoticon.e8{background-position:0px -16px}.emoticon.e9{background-position:-16px -16px}.emoticon.e10{background-position:-32px -16px}.emoticon.e11{background-position:-48px -16px}.emoticon.e12{background-position:-64px -16px}.emoticon.e13{background-position:-80px -16px}.emoticon.e14{background-position:-96px -16px}.emoticon.e15{background-position:-112px -16px}.emoticon.e16{background-position:0px -32px}.emoticon.e17{background-position:-16px -32px}.emoticon.e18{background-position:-32px -32px}"; | |
EmbedCodeOnPage("style", css); | |
EmbedFunctionOnPageAndExecute(function() { | |
var map = [ | |
[/\:\(/g, "e0"], | |
[/\:\'\(/g, "e1"], | |
[/\:\)/g, "e2"], | |
[/\:D/g, "e3"], | |
[/\:P/g, "e4"], | |
[/\;P/g, "e5"], | |
[/\;\)/g, "e6"], | |
[/T\_T/, "e7"], | |
[/\>\:\(/g, "e8"], | |
[/\ಠ\_\ಠ/g, "e9"], | |
[/XD/g, "e10"], | |
[/XP/g, "e11"], | |
[/D\:/g, "e12"], | |
[/\;D/g, "e13"], | |
[/\:d/g, "e14"], | |
[/Xd/g, "e15"], | |
[/\^\_\^/g, "e16"], | |
[/\:S/g, "e17"], | |
[/\:\|/g, "e18"] | |
]; | |
var elm = $('#chat'); | |
var parseText = function() { | |
$.each(map, function(i, e) { | |
elm.html(elm.html().replace(e[0], "<span class='emoticon " + e[1] + "'></span>")); | |
}); | |
}; | |
var tmp = $.scrollTo; | |
$.scrollTo = function() { | |
tmp.apply($, arguments); | |
parseText(); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment