Skip to content

Instantly share code, notes, and snippets.

@Icelys
Forked from MegaApuTurkUltra/packageAdder.user.js
Last active November 30, 2015 03:46
Show Gist options
  • Save Icelys/2178f1914f8dc169a428 to your computer and use it in GitHub Desktop.
Save Icelys/2178f1914f8dc169a428 to your computer and use it in GitHub Desktop.
Scratch 📦 adder
// ==UserScript==
// @name :package: adder
// @namespace http://aputurk.tk/
// @version 0.2
// @description Adds the :package: emoticon
// @author MegaApuTurkUltra
// @match https://scratch.mit.edu/discuss/*
// @grant none
// ==/UserScript==
/* jshint -W097 */
var test = document.getElementsByClassName("markItUpEditor");
var icons = []
var newEmoji = function(text, url){
icons.push([RegExp(text), "[img]" + url + "[/img]"]);
}
newEmoji(":package:", "http://i67.tinypic.com/24wsdo6.png");
newEmoji(":octocat:", "https://blog.library.si.edu/redir.php?URL=https://assets-cdn.github.com/images/icons/emoji/octocat.png");
newEmoji(":swag:", "http://imageshack.com/a/img910/4035/dJbljF.png/");
newEmoji(":thinking:", "http://imageshack.com/a/img633/7756/ZQb8BG.png/");
newEmoji(":usa:", "http://imageshack.com/a/img911/7430/KkgA2I.png/");
newEmoji(":uk:", "http://imageshack.com/a/img905/2230/yinKFa.png/");
newEmoji(":ok:", "http://imageshack.com/a/img905/1870/kAkVSj.png/");
if(test.length > 0){
var editor = test[0];
var emoticonFunc = function(){
for(i = 0; i < icons.length; i++){
editor.value = editor.value.replace(icons[i][0], icons[i][1])
}
};
if(editor.onkeyup != null){
var delegate = editor.onkeyup;
editor.onkeyup = function(){
emoticonFunc();
delegate();
};
} else {
editor.onkeyup = emoticonFunc;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment