Hey everyone,
I've been working on a fun little side project that I reckon could be a real time-saver for us all. It's a JavaScript script that I cooked up to automatically enable mobile view for all components on any Retool page.
You can F12 and paste this script in the console, and then just call enableAll() or disableAll() when you're in desktop view.
I've found it super handy in my own workflow and thought it'd be cool to share it with the community. So, check it out! And if you've got any questions or feedback, just give me a shout.
Cheers,
Guy
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function getComponentsMenu() {
return document.querySelector('div[data-testid="Explorer::ComponentTree"]');
}
function getComponentListItems() {
const menu = getComponentsMenu();
return menu.querySelectorAll("li");
}
async function enableMobile(header) {
console.log(`Enabling mobile for ${header.textContent}`);
header.children[0].click();
await sleep(500);
appearanceIcon = document.getElementById(
`EditorFormSectionV2::${header.textContent.trim()}::Appearance::AdvancedButton`
);
if (!appearanceIcon) {
console.log(`No appearance icon for ${header.textContent}`);
return;
}
appearanceIcon.scrollIntoViewIfNeeded();
appearanceIcon.click();
await sleep(500);
showOnMobileInput = document.getElementById("EditorForm::ShowOnMobileToggle");
if (showOnMobileInput.checked) {
console.log(`Mobile already enabled for ${header.textContent}`);
return;
}
showOnMobileInput.click();
}
async function disableMobile(header) {
console.log(`Disabling mobile for ${header.textContent}`);
header.children[0].click();
await sleep(500);
appearanceIcon = document.getElementById(
`EditorFormSectionV2::${header.textContent.trim()}::Appearance::AdvancedButton`
);
if (!appearanceIcon) {
console.log(`No appearance icon for ${header.textContent}`);
return;
}
appearanceIcon.scrollIntoViewIfNeeded();
appearanceIcon.click();
await sleep(500);
showOnMobileInput = document.getElementById("EditorForm::ShowOnMobileToggle");
if (!showOnMobileInput.checked) {
console.log(`Mobile already disabled for ${header.textContent}`);
return;
}
showOnMobileInput.click();
}
async function disableAll() {
for (const x of getComponentListItems()) {
await disableMobile(x);
await sleep(500);
}
}
async function enableAll() {
for (const x of getComponentListItems()) {
await enableMobile(x);
await sleep(500);
}
}