Revisions for ⁨Longer emoticon shortcodes⁩

View the changes made to this paste.

public ⁨1⁩ ⁨file⁩ 2020-11-22 21:04:12 UTC

plugin.js

@@ -1,3 +1,13 @@

+// How to use:
+// -----------
+// 1. Enter the names of your emoticons in the variable ´emoticons´.
+// 2. Reload the plugin.
+// 3. Check the debug log for the converted shortcode.
+// 4. Open the Emoticons dialog in Windows Live Messenger.
+// 5. Select the emoticon you want a longer shortcode of, click on "Edit" and change the shortcode to the text you copied.
+//
+// (optional) 6. Change the unicode if it interferes with your messages.
+
 // Unused Unicode used for emoticon short codes.
 var characters = [ "◃", "◂" ];
 

plugin.js

@@ -0,0 +1,81 @@

+// Unused Unicode used for emoticon short codes.
+var characters = [ "◃", "◂" ];
+
+// The names of the emoticons you're going to use.
+var emoticons = [
+	"blobcat",
+	"kiss"
+];
+
+function OnEvent_Initialize(MessengerStart) {
+	printEmoticonList();
+}
+function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
+	return replaceEmoticons(Message);
+}
+
+function printEmoticonList() {
+	for (var i = 0; i < emoticons.length; i++) {
+		var emoticonName = emoticons[i];
+		var encoded = encodeIndex(i);
+		Debug.Trace("Secret unicode for emoticon \"" + emoticonName + "\" is \"" + encoded + "\"");
+	}
+}
+function replaceEmoticons(Message) {
+	var readingEmoji = false;
+	var startIndex = null;
+	var emojiBuffer = "";
+	
+	for (var i = 0; i < Message.length; i++) {
+		var char = Message.charAt(i);
+		
+		if (char === ":") {
+			if (readingEmoji) {
+				var emojiIndex = indexOf(emoticons, emojiBuffer);
+				
+				Debug.Trace("Searching for emoji called " + emojiBuffer);
+				
+				if (emojiIndex == -1) {
+					// clear emoji buffer
+					emojiBuffer = "";
+				} else {
+					// emoji found, replacing Message.
+					Debug.Trace("Replacing emoji at " + i);
+					var prefix = Message.substring(0, startIndex);
+					var suffix = Message.substring(i + 1);
+					Message = prefix + encodeIndex(emojiIndex) + suffix;
+					readingEmoji = false;
+				}
+			} else {
+				Debug.Trace("Started reading emoji");
+				startIndex = i;
+				readingEmoji = true;
+			}
+		} else if (readingEmoji) {
+			emojiBuffer = emojiBuffer + char;
+		}
+	}
+	
+	return Message;
+}
+function encodeIndex(idx1) {
+	var oldBits = idx1.toString(2);
+	var newBits = "";
+	
+	for (var idx2 = 0; idx2 < oldBits.length; idx2++) {
+		var oldChar = oldBits.charAt(idx2);
+		var pos = parseInt(oldChar);
+		var newChar = characters[pos];
+		newBits = newBits + newChar;
+	}
+	
+	return newBits;
+}
+function indexOf(array, element) {
+	for (var i = 0; i < array.length; i++) {
+		if (array[i] == element)
+			return i;
+	}
+	
+	return -1;
+}
\ No newline at end of file