Skip to content

Instantly share code, notes, and snippets.

@heptal
Last active May 2, 2016 16:04
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 heptal/0b269e74a962371017444b6ea89b87a8 to your computer and use it in GitHub Desktop.
Save heptal/0b269e74a962371017444b6ea89b87a8 to your computer and use it in GitHub Desktop.
Smilie autocomplete search box
// ==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