Skip to content

Commit 1c18ffa

Browse files
committed
fix(popup): resolve custom select init timing issue and improve UX
- Use `await` for `chrome.tabs.query` to ensure active platform is set before initializing the custom select. - Initialize custom select only after platform value is resolved. - Remove `e.isTrusted` check in `custom-select.ts` to allow programmatic change events. - Update `updateUITexts` to dynamically translate `<select>` options. - Add `youtubeShorts` translation key to i18n (ar, en, types). - Enable save button as a trigger when no platform is selected. - Stop event propagation on save click to prevent dropdown from instantly closing. - Adjust custom select header spacing in `styles.css` for better alignment.
1 parent 5a98356 commit 1c18ffa

6 files changed

Lines changed: 38 additions & 27 deletions

File tree

src/i18n/locales/ar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const ar: LocaleStrings = {
1717
reason_bypass: 'السبب: محاولة تحايل',
1818
lockedBtn: 'مقفول!',
1919
selectPlatform: 'اختر المنصة...',
20+
youtubeShorts: 'يوتيوب شورتس',
2021
},
2122
dashboard: {
2223
title: 'مركز قيادة ليمترا',

src/i18n/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const en: LocaleStrings = {
1717
reason_bypass: 'Triggered by: Anti-Bypass System',
1818
lockedBtn: 'Locked!',
1919
selectPlatform: 'Select Platform...',
20+
youtubeShorts: 'YouTube Shorts',
2021
},
2122
dashboard: {
2223
title: 'Limitra Command Center',

src/i18n/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface LocaleStrings {
1717
reason_bypass: string;
1818
lockedBtn: string;
1919
selectPlatform: string;
20+
youtubeShorts: string;
2021
};
2122
dashboard: {
2223
title: string;

src/ui/components/custom-select.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ export function initCustomSelects(): void {
8080
select.parentNode.insertBefore(wrapper, select.nextSibling);
8181
}
8282

83-
select.addEventListener('change', (e: Event) => {
84-
if (!e.isTrusted) return;
83+
select.addEventListener('change', () => {
8584
const newActive = Array.from(select.options).find((opt) => opt.value === select.value);
8685
if (newActive) {
8786
selectedText.textContent = newActive.text;

src/ui/popup/index.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ function updateUITexts() {
3636
'lbl-usage-videos': t.popup.videosUnit,
3737
'lbl-usage-time': t.popup.timeTitle,
3838
};
39-
4039
Object.entries(map).forEach(([id, value]) => setText(id, value));
4140

42-
btnSave.textContent = t.popup.saveBtn;
41+
const ytOption = platformSelector.querySelector('option[value="youtube_shorts"]');
42+
if (ytOption) ytOption.textContent = t.popup.youtubeShorts;
4343

44-
document.body.dir = i18n.language === 'ar' ? 'rtl' : 'ltr';
44+
const placeholderOption = platformSelector.querySelector('option[value=""]');
45+
if (placeholderOption) placeholderOption.textContent = t.popup.selectPlatform;
4546

47+
btnSave.textContent = t.popup.saveBtn;
48+
document.body.dir = i18n.language === 'ar' ? 'rtl' : 'ltr';
4649
updateProgressBar();
4750
}
48-
4951
function updateProgressBar() {
5052
const isLimitEnabled = toggleLimit.checked;
5153
const isTimeEnabled = toggleTime.checked;
@@ -103,7 +105,7 @@ function lockUIForSelection() {
103105
timeInput.disabled = true;
104106
toggleLimit.disabled = true;
105107
toggleTime.disabled = true;
106-
btnSave.disabled = true;
108+
btnSave.disabled = false;
107109
btnSave.textContent = i18n.t.popup.selectPlatform;
108110

109111
setText('stats-videos', `- / -`);
@@ -165,20 +167,19 @@ async function init() {
165167
await i18n.init();
166168
updateUITexts();
167169

168-
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
169-
const currentTab = tabs[0];
170-
const currentUrl = currentTab?.url || '';
170+
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
171+
const currentTab = tabs[0];
172+
const currentUrl = currentTab?.url || '';
171173

172-
if (currentUrl.includes('youtube.com') && currentUrl.includes('/shorts/')) {
173-
activePlatform = 'youtube_shorts';
174-
platformSelector.value = activePlatform;
175-
void loadPlatformData();
176-
} else {
177-
activePlatform = null;
178-
platformSelector.value = '';
179-
lockUIForSelection();
180-
}
181-
});
174+
if (currentUrl.includes('youtube.com') && currentUrl.includes('/shorts/')) {
175+
activePlatform = 'youtube_shorts';
176+
platformSelector.value = activePlatform;
177+
await loadPlatformData();
178+
} else {
179+
activePlatform = null;
180+
platformSelector.value = '';
181+
lockUIForSelection();
182+
}
182183

183184
initCustomSelects();
184185

@@ -221,11 +222,18 @@ const systemThemeQuery = window.matchMedia('(prefers-color-scheme: dark)');
221222
updateActionIcon(systemThemeQuery.matches);
222223
systemThemeQuery.addEventListener('change', (event) => updateActionIcon(event.matches));
223224

224-
btnSave.onclick = async () => {
225-
if (!activePlatform) return;
225+
btnSave.onclick = async (e: MouseEvent) => {
226+
if (!activePlatform) {
227+
e.stopPropagation();
226228

227-
clickCount++;
229+
const trigger = document.querySelector('.custom-brutal-trigger') as HTMLElement;
230+
if (trigger) {
231+
trigger.click();
232+
}
233+
return;
234+
}
228235

236+
clickCount++;
229237
if (spamResetTimer) clearTimeout(spamResetTimer);
230238
spamResetTimer = window.setTimeout(() => (clickCount = 0), 2000);
231239

styles.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,13 @@ button#save:disabled {
347347
display: flex;
348348
align-items: center;
349349
justify-content: space-between;
350-
height: 20px;
351-
min-height: 20px;
352-
max-height: 20px;
350+
height: 22px;
351+
min-height: 22px;
352+
max-height: 22px;
353353
padding: 0 8px;
354354
border-width: 1.5px !important;
355-
box-shadow: 2px 2px 0px 0px;
355+
box-shadow: none;
356+
margin-top: 3px;
356357
background-color: var(--bg-surface);
357358
transition:
358359
transform 0.1s ease,

0 commit comments

Comments
 (0)