Skip to content

Commit 05a8467

Browse files
authored
Merge pull request #29 from mlsof21/fix-transfer-name-issues
Fix transfer name issues
2 parents 0f3f05a + e6f3632 commit 05a8467

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### 1.2.3 - 2022-11-25 - Parsing Issues
2+
3+
- Weapons with periods in their name (IKELOS weapons, a few others) are now parsed correctly
4+
- Slight optimization for transferring weapons by name (no longer populates the search bar with `name:"<weapon>"`)
5+
16
### 1.2.2 - 2022-10-04 - Activation Phrase Fix
27

38
- Added fix for capital letter in activation phrase by trimming/lowercasing everywhere

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "voice-dim",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "Perform common DIM actions by using speech recognition.",
55
"main": "dist/chrome/js/voice-dim.js",
66
"scripts": {

public/manifest.chrome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Voice DIM",
33
"description": "Control DIM with your voice.",
4-
"version": "1.2.2",
4+
"version": "1.2.3",
55
"manifest_version": 3,
66
"background": {
77
"service_worker": "js/background.js"

public/manifest.firefox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Voice DIM",
33
"description": "Control DIM with your voice.",
4-
"version": "1.2.2",
4+
"version": "1.2.3",
55
"manifest_version": 2,
66
"background": {
77
"scripts": ["js/background.js"]

scripts/update_version.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def write_new_version(file_path: str, new_version: str, dry_run: bool = False):
4545
data['version'] = f"{new_version}"
4646

4747
if dry_run:
48+
print("Not writing to file since dry run")
4849
return
4950

5051
with open(file_path, 'w') as f:
@@ -63,6 +64,7 @@ def write_changelog_update(file_path: str, new_version: str, dry_run: bool = Fal
6364
print(data)
6465

6566
if dry_run:
67+
print("Not writing to file since dry run")
6668
return
6769

6870
with open(file_path, 'w') as f:
@@ -107,7 +109,9 @@ def main():
107109
print(current_version)
108110

109111
next_version = get_next_version(current_version, part)
110-
print(next_version)
112+
113+
print("New version:", next_version)
114+
print("Dry run:", dry_run)
111115

112116
for file in files:
113117
write_new_version(file, next_version, dry_run)

src/ts/voiceDim.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
480492
async 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

Comments
 (0)