Created
October 2, 2024 18:18
-
-
Save 32teeth/dbcb43b8a0bc906ef232092c68f6f097 to your computer and use it in GitHub Desktop.
Mynah-UI Console Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const removeAllTabs = () => { | |
const tabs = mynahUI.getAllTabs(); | |
Object.keys(tabs).forEach(key => mynahUI.removeTab(key, mynahUI.lastEventId)); | |
}; | |
const createTabs = (count) => { | |
const addTabButton = document.querySelector('.mynah-ui-icon.mynah-ui-icon-plus'); | |
for (let i = 0; i < count; i++) { | |
addTabButton.click(); | |
} | |
}; | |
const randomTabSelector = () => { | |
const tabs = mynahUI.getAllTabs(); | |
const keys = Object.keys(tabs); | |
const randomKey = keys[Math.floor(Math.random() * keys.length)]; | |
const data = keys.map(tabId => ({ | |
tabId, | |
isSelected: tabs[tabId].isSelected ? 'currently selected' : '', | |
setFocusTab: tabId === randomKey ? 'next to be focused' : '' | |
})); | |
console.table(data); | |
mynahUI.setFocusTab(randomKey); | |
}; | |
const runRandomTabSelector = (maxIterations, interval) => { | |
let iteration = 0; | |
const selectorInterval = setInterval(() => { | |
console.clear(); | |
console.log(`Iteration ${iteration + 1} / ${maxIterations}`); | |
randomTabSelector(); | |
iteration++; | |
if (iteration >= maxIterations) { | |
clearInterval(selectorInterval); | |
} | |
}, interval); | |
}; | |
// Usage | |
removeAllTabs(); | |
createTabs(10); | |
runRandomTabSelector(10, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment