Created
April 25, 2022 18:26
-
-
Save Pross/8ef63a3204524bb20739e94f341fff93 to your computer and use it in GitHub Desktop.
Adds nice-select support to pi-star web admin with Tampermonkey.
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 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'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions for use:
http://pi-star.local/admin/*
yours may be different.