From 6cfff0274d2334463c6f497479bee52c94ce4db6 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:42:09 +0700 Subject: [PATCH] Replace forEach() with for() --- src/modules/controller-shortcut.ts | 5 +++-- src/modules/game-bar/game-bar.ts | 4 +++- src/modules/patcher.ts | 4 ++-- src/modules/stream/stream-badges.ts | 7 ++++--- src/modules/stream/stream-ui.ts | 7 ++++--- src/modules/ui/dialog/navigation-dialog.ts | 7 ++++--- src/utils/html.ts | 7 +++++-- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/modules/controller-shortcut.ts b/src/modules/controller-shortcut.ts index 13acace..533a2c2 100644 --- a/src/modules/controller-shortcut.ts +++ b/src/modules/controller-shortcut.ts @@ -73,7 +73,8 @@ export class ControllerShortcut { const pressed: boolean[] = []; let otherButtonPressed = false; - gamepad.buttons.forEach((button, index) => { + const entries = gamepad.buttons.entries(); + for (const [index, button] of entries) { // Only add the newly pressed button to the array (holding doesn't count) if (button.pressed && index !== GamepadKey.HOME) { otherButtonPressed = true; @@ -84,7 +85,7 @@ export class ControllerShortcut { setTimeout(() => ControllerShortcut.runAction(actions[index]!), 0); } } - }); + }; ControllerShortcut.buttonsStatus[gamepadIndex] = pressed; return otherButtonPressed; diff --git a/src/modules/game-bar/game-bar.ts b/src/modules/game-bar/game-bar.ts index ba0037d..c934424 100644 --- a/src/modules/game-bar/game-bar.ts +++ b/src/modules/game-bar/game-bar.ts @@ -130,6 +130,8 @@ export class GameBar { // Reset all states reset() { - this.actions.forEach(action => action.reset()); + for (const action of this.actions) { + action.reset(); + } } } diff --git a/src/modules/patcher.ts b/src/modules/patcher.ts index 51793bd..5e97d34 100644 --- a/src/modules/patcher.ts +++ b/src/modules/patcher.ts @@ -835,10 +835,10 @@ true` + text; [UiSection.MOST_POPULAR]: GamePassCloudGallery.MOST_POPULAR, }; - PREF_HIDE_SECTIONS.forEach(section => { + for (const section of PREF_HIDE_SECTIONS) { const galleryId = sections[section]; galleryId && siglIds.push(galleryId); - }); + }; const checkSyntax = siglIds.map(item => `siglId === "${item}"`).join(' || '); diff --git a/src/modules/stream/stream-badges.ts b/src/modules/stream/stream-badges.ts index ac341c5..f9ee7ab 100644 --- a/src/modules/stream/stream-badges.ts +++ b/src/modules/stream/stream-badges.ts @@ -219,9 +219,10 @@ export class StreamBadges { ]; const $container = CE('div', {class: 'bx-badges'}); - BADGES.forEach(item => { + + for (const item of BADGES) { if (!item) { - return; + continue; } let $badge: HTMLElement; @@ -232,7 +233,7 @@ export class StreamBadges { } $container.appendChild($badge); - }); + }; this.$container = $container; await this.start(); diff --git a/src/modules/stream/stream-ui.ts b/src/modules/stream/stream-ui.ts index a8ab54a..376ef8a 100644 --- a/src/modules/stream/stream-ui.ts +++ b/src/modules/stream/stream-ui.ts @@ -221,9 +221,10 @@ export class StreamUiHandler { } const observer = new MutationObserver(mutationList => { - mutationList.forEach(item => { + let item: MutationRecord; + for (item of mutationList) { if (item.type !== 'childList') { - return; + continue; } item.addedNodes.forEach(async $node => { @@ -263,7 +264,7 @@ export class StreamUiHandler { // Handle System Menu bar StreamUiHandler.handleSystemMenu($elm); }); - }); + }; }); observer.observe($screen, {subtree: true, childList: true}); diff --git a/src/modules/ui/dialog/navigation-dialog.ts b/src/modules/ui/dialog/navigation-dialog.ts index 8de771a..90d40ea 100644 --- a/src/modules/ui/dialog/navigation-dialog.ts +++ b/src/modules/ui/dialog/navigation-dialog.ts @@ -177,8 +177,9 @@ export class NavigationDialogManager { } calculateSelectBoxes($root: HTMLElement) { - const $selects = $root.querySelectorAll('.bx-select:not([data-calculated]) select'); - $selects.forEach($select => { + const selects = Array.from($root.querySelectorAll('.bx-select:not([data-calculated]) select')); + + for (const $select of selects) { const $parent = $select.parentElement! as HTMLElement; // Don't apply to select.bx-full-width elements @@ -205,7 +206,7 @@ export class NavigationDialogManager { // Set min-width $label.style.minWidth = width + 'px'; $parent.dataset.calculated = 'true'; - }); + }; } handleEvent(event: Event) { diff --git a/src/utils/html.ts b/src/utils/html.ts index 2d2800b..c35ae76 100644 --- a/src/utils/html.ts +++ b/src/utils/html.ts @@ -121,9 +121,12 @@ export function createButton(options: BxButton): T { } const style = (options.style || 0) as number; - style && ButtonStyleIndices.forEach((index: keyof typeof ButtonStyleClass) => { + if (style) { + let index: keyof typeof ButtonStyleClass; + for (index of ButtonStyleIndices) { (style & index) && $btn.classList.add(ButtonStyleClass[index] as string); - }); + } + } options.classes && $btn.classList.add(...options.classes);