@@ -217,8 +217,9 @@ async function handleStoreItem(query: string) {
217217 await clearSearchBar ( ) ;
218218 return ;
219219 }
220- await populateSearchBar ( `name:"${ itemToStore ?. match } "` ) ;
221- const itemDiv = availableItems [ itemToStore . match ] ;
220+ // probably not necessary since we're just using the element returned above
221+ // await populateSearchBar(`name:"${itemToStore?.match}"`);
222+ const itemDiv = availableItems [ itemToStore . match ] . item ;
222223 itemDiv ?. dispatchEvent ( uiEvents . singleClick ) ;
223224 const vaultDiv = await waitForElementToDisplay ( '.item-popup [title^="Vault"]' ) ;
224225 vaultDiv ?. dispatchEvent ( uiEvents . singleClick ) ;
@@ -266,13 +267,20 @@ async function getItemToMove(query: string): Promise<Element | null> {
266267 let nonPerkQuery = getGenericQuery ( splitQuery [ 0 ] ) ;
267268
268269 const perkQuery = splitQuery . length > 1 && splitQuery [ 1 ] !== '' ? getPerkQuery ( splitQuery [ 1 ] ) : '' ;
270+
271+ // getting a specific weapon
269272 if ( nonPerkQuery === '' ) {
270273 const availableItems = getAllTransferableItems ( ) ;
271274 const itemToGet = getClosestMatch ( Object . keys ( availableItems ) , splitQuery [ 0 ] ) ;
272- await populateSearchBar ( `${ perkQuery } name:"${ itemToGet ?. match } "` ) ;
275+ if ( ! itemToGet ) return null ;
276+ const fullName = availableItems [ itemToGet . match ] . name ;
277+ debugLog ( 'voice dim' , { itemToGet } ) ;
278+ await populateSearchBar ( `${ perkQuery } name:"${ fullName } "` . trim ( ) ) ;
273279 const visibleItems = getVisibleItems ( ) ;
274280 itemToMove = visibleItems [ 0 ] ;
275- } else {
281+ }
282+ // Getting a generic weapon (solar grenade launcher, kinetic handcannon, etc.)
283+ else {
276284 nonPerkQuery += ` ${ perkQuery } -is:incurrentchar -is:postmaster` ;
277285 await populateSearchBar ( nonPerkQuery ) ;
278286 const filteredItems = getVisibleItems ( ) ;
@@ -287,7 +295,7 @@ async function transferItem(item: Element) {
287295 item . dispatchEvent ( uiEvents . singleClick ) ;
288296 const currentClass = getCurrentCharacterClass ( ) ;
289297 const expandCollapseButton = await waitForElementToDisplay ( 'div[title^="Expand or collapse"]' ) ;
290- if ( ! document . querySelector ( 'div[class ^="ItemMoveLocations "]' ) ) {
298+ if ( ! document . querySelector ( 'div[title ^="Store "]' ) ) {
291299 expandCollapseButton ?. dispatchEvent ( uiEvents . singleClick ) ;
292300 }
293301 const storeDiv = await waitForElementToDisplay ( `[title^="Store"] [data-icon*="${ currentClass } "]` , 500 ) ;
@@ -409,15 +417,15 @@ function checkForGenericTerms(queries: Record<string, string>, query: string) {
409417 return fullQuery ;
410418}
411419
412- function getAllTransferableItems ( ) : Record < string , Element > {
413- const items : Record < string , Element > = { } ;
420+ function getAllTransferableItems ( ) : Record < string , { name : string ; item : Element } > {
421+ const items : Record < string , { name : string ; item : Element } > = { } ;
414422 for ( const labelName of transferableItemAriaLabels ) {
415423 const result = document . querySelectorAll ( `[aria-label="${ labelName } "] .item` ) ;
416424 const filteredItems = getVisibleItems ( result ) ;
417425 filteredItems . forEach ( ( item ) => {
418426 const split = ( < HTMLElement > item ) . title . split ( '\n' ) ;
419427 const sanitized = split [ 0 ] . replaceAll ( '.' , '' ) ;
420- items [ sanitized ] = item ;
428+ items [ sanitized ] = { name : split [ 0 ] , item } ;
421429 } ) ;
422430 }
423431
@@ -467,16 +475,20 @@ async function populateSearchBar(searchInput: string): Promise<void> {
467475 const newValue = `${ searchBar . value } ${ searchInput . trim ( ) } ` . trim ( ) ;
468476 searchBar . value = newValue ;
469477 infoLog ( 'voice dim' , 'Populating search bar with' , searchBar . value ) ;
470- searchBar ?. dispatchEvent ( uiEvents . input ) ;
471- await sleep ( 50 ) ;
472- searchBar ?. focus ( ) ;
473- searchBar ?. dispatchEvent ( uiEvents . enter ) ;
474- searchBar ?. blur ;
478+ await simulateSearchInput ( ) ;
475479
476480 await waitForSearchToUpdate ( count ) ;
477481 }
478482}
479483
484+ async function simulateSearchInput ( ) {
485+ searchBar ?. dispatchEvent ( uiEvents . input ) ;
486+ await sleep ( 50 ) ;
487+ searchBar ?. focus ( ) ;
488+ searchBar ?. dispatchEvent ( uiEvents . enter ) ;
489+ searchBar ?. blur ( ) ;
490+ }
491+
480492async function clearSearchBar ( ) {
481493 infoLog ( 'voice dim' , 'Clearing search bar' ) ;
482494 const clearButton = document . querySelector ( '.filter-bar-button[title^=Clear]' ) ;
@@ -485,9 +497,10 @@ async function clearSearchBar() {
485497 clearButton ?. dispatchEvent ( uiEvents . singleClick ) ;
486498 if ( searchBar && searchBar ?. value !== '' ) {
487499 searchBar . value = '' ;
500+ searchBar ?. dispatchEvent ( uiEvents . escape ) ;
501+ searchBar ?. blur ( ) ;
488502 waitForUpdate = true ;
489503 }
490- searchBar ?. blur ;
491504 if ( waitForUpdate ) await waitForSearchToUpdate ( initialCount ) ;
492505}
493506
@@ -653,8 +666,8 @@ function init() {
653666 getPerks ( ) ;
654667 getCustomCommands ( ) ;
655668 getAlwaysListeningOptions ( ) ;
656- createMicDiv ( ) ;
657- createHelpDiv ( ) ;
669+ if ( ! document . getElementById ( 'voiceDim' ) ) createMicDiv ( ) ;
670+ if ( ! document . getElementById ( 'voiceDimHelp' ) ) createHelpDiv ( ) ;
658671 }
659672}
660673
0 commit comments