@ -137,8 +137,15 @@ TABS.auxiliary.initialize = function (callback) {
var channelList = $ ( rangeTemplate ) . find ( '.channel' ) ;
var channelOptionTemplate = $ ( channelList ) . find ( 'option' ) ;
channelOptionTemplate . remove ( ) ;
//add value to autodetect channel
let channelOption = channelOptionTemplate . clone ( ) ;
channelOption . text ( chrome . i18n . getMessage ( 'auxiliaryAutoChannelSelect' ) ) ;
channelOption . val ( - 1 ) ;
channelList . append ( channelOption ) ;
for ( var channelIndex = 0 ; channelIndex < auxChannelCount ; channelIndex ++ ) {
var channelOption = channelOptionTemplate . clone ( ) ;
channelOption = channelOptionTemplate . clone ( ) ;
channelOption . text ( 'CH ' + ( channelIndex + 5 ) ) ;
channelOption . val ( channelIndex ) ;
channelList . append ( channelOption ) ;
@ -444,11 +451,51 @@ TABS.auxiliary.initialize = function (callback) {
}
}
auto _select _channel ( RC . channels , RC . active _channels , MISC . rssi _channel ) ;
$ ( ".modeSection" ) . each ( function ( ) {
$ ( this ) . toggle ( ! hideUnused ) ;
} ) ;
}
/ * *
* Autodetect channel based on maximum deference with previous value
* minimum value to autodetect is 100
* /
function auto _select _channel ( RC _channels , activeChannels , RSSI _channel ) {
const auto _option = $ ( '.tab-auxiliary select.channel option[value="-1"]:selected' ) ;
if ( auto _option . length === 0 ) {
prevChannelsValues = null ;
return ;
}
const fillPrevChannelsValues = function ( ) {
prevChannelsValues = RC _channels . slice ( 0 ) ; //clone array
} ;
if ( ! prevChannelsValues || RC _channels . length === 0 ) return fillPrevChannelsValues ( ) ;
let diff _array = RC _channels . map ( function ( currentValue , index ) {
return Math . abs ( prevChannelsValues [ index ] - currentValue ) ;
} ) ;
diff _array = diff _array . slice ( 0 , activeChannels ) ;
const largest = diff _array . reduce ( function ( x , y ) {
return ( x > y ) ? x : y ;
} , 0 ) ;
//minimum change to autoselect is 100
if ( largest < 100 ) return fillPrevChannelsValues ( ) ;
const indexOfMaxValue = diff _array . indexOf ( largest ) ;
if ( indexOfMaxValue >= 4 && indexOfMaxValue != RSSI _channel - 1 ) { //set channel
auto _option . parent ( ) . val ( indexOfMaxValue - 4 ) ;
}
return fillPrevChannelsValues ( ) ;
}
let hideUnusedModes = false ;
chrome . storage . local . get ( 'hideUnusedModes' , function ( result ) {
$ ( "input#switch-toggle-unused" )