Skip to content

Instantly share code, notes, and snippets.

@Pross
Created April 25, 2022 18:26
Show Gist options
  • Save Pross/8ef63a3204524bb20739e94f341fff93 to your computer and use it in GitHub Desktop.
Save Pross/8ef63a3204524bb20739e94f341fff93 to your computer and use it in GitHub Desktop.
Adds nice-select support to pi-star web admin with Tampermonkey.
// ==UserScript==
// @name Pi-Star Nice Select
// @description Add search to dropdowns
// @version 0.1
// @author Simon
// @match http://pi-star.local/admin/*
// @grant GM_getResourceText
// @grant GM_addStyle
// @require https://bluzky.github.io/nice-select2/dist/js/nice-select2.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.slim.min.js
// @resource niceCSS https://bluzky.github.io/nice-select2/dist/css/nice-select2.css
// ==/UserScript==
(function() {
'use strict';
var $ = $ || window.$;
var niceCSS = GM_getResourceText("niceCSS");
var options = {searchable: true};
var selects = $('select');
GM_addStyle(niceCSS);
$(selects).each(function() {
var select = $(this);
if( select.find('option').length > 30 ) {
var first = select.find('option').first().attr('value');
if ( 'none' == first ) {
select.find('option').first().remove();
}
select.addClass('small selectize');
}
})
var selectize = document.querySelectorAll('select')
selectize.forEach(function(select){
if( select.length > 30 ) {
NiceSelect.bind(select, options);
}
});
$('.nice-select.small').css('height', '24px');
$('.nice-select.small').css('line-height', '24px');
$('.nice-select-dropdown li').css('line-height', '24px');
$('.nice-select-dropdown li').css('min-height', '24px');
})();
@Pross
Copy link
Author

Pross commented Apr 25, 2022

Instructions for use:

  1. Install Tampermonkey extension: https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en
  2. Enable the extension and click the new icon, select "Create new script..."
  3. Replace the template script with the contents of this gist.
  4. Dont forget to add your host url to line 6, mine is http://pi-star.local/admin/* yours may be different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment