Last active
May 2, 2016 16:04
-
-
Save heptal/0b269e74a962371017444b6ea89b87a8 to your computer and use it in GitHub Desktop.
Smilie autocomplete search box
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 SASmilieSearch | |
// @namespace forums.somethingawful.com | |
// @version 0.1.5 | |
// @description Smilie autocomplete search box | |
// @author Me | |
// @match http://forums.somethingawful.com/misc.php?action=showsmilies | |
// @match https://forums.somethingawful.com/misc.php?action=showsmilies | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
$('h2').after('<input type="text" id="box" />'); | |
$('#box').autocomplete({ | |
source: $.map($('li.smilie'), function(el) { | |
var code = el.textContent.replace(/\n/g, ''), | |
img = el.lastElementChild.cloneNode(); | |
return { | |
label: code + ' ' + img.title + ' ', | |
value: code, | |
img: img | |
}; | |
}) | |
}).data('ui-autocomplete')._renderItem = function(ul, item) { | |
return $('<li>') | |
.attr('data-value', item.value) | |
.append(item.label) | |
.append(item.img) | |
.appendTo(ul); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment