Skip to content

Instantly share code, notes, and snippets.

@kms70847
Last active September 25, 2019 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kms70847/38b97c1d81ddce8cec751e5e47531382 to your computer and use it in GitHub Desktop.
Save kms70847/38b97c1d81ddce8cec751e5e47531382 to your computer and use it in GitHub Desktop.
Emoticon Adder Userscript
// ==UserScript==
// @name Emoticon Adder
// @version 1
// @include http://chat.stackoverflow.com/rooms/*
// @include https://chat.stackoverflow.com/rooms/*
// @grant none
// ==/UserScript==
//note: emoticons with slash characters, for example ¯\_(ツ)_/¯, must be quadruple-escaped. Once for javascript, and again for markdown.
var choices = ["---", "(◕‿◕)", "(╯°□°)╯︵ ┻━┻", "( ͡° ͜ʖ ͡°)", "ಠ_ಠ", " ¯\\\\_(ツ)_/¯", "👍", "🐍"];
var buttonArea = document.getElementById("chat-buttons");
var select = document.createElement("select");
buttonArea.appendChild(select)
for(var choice of choices){
option = document.createElement("option");
option.value = choice;
option.innerHTML = choice;
select.appendChild(option);
}
function selected(){
if (select.selectedIndex <= 0){
return;
}
var choice = choices[select.selectedIndex];
select.selectedIndex = 0;
insert_text_at_cursor(choice);
}
function insert_text_at_cursor(text){
var input = document.getElementById("input");
var left = input.value.slice(0, input.selectionStart);
var middle = text;
var right = input.value.slice(input.selectionEnd);
input.value = left + middle + right;
input.setSelectionRange(left.length + middle.length, left.length + middle.length);
input.focus();
}
select.onchange = selected;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment