Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user preferences blocks to Navigator #759

Merged
merged 4 commits into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions extensions/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,35 @@
blockType: Scratch.BlockType.REPORTER,
text: "device memory in GB",
},
{
opcode: "getPreferredColorScheme",
blockType: Scratch.BlockType.BOOLEAN,
text: "user prefers [THEME] color scheme?",
arguments: {
THEME: {
type: Scratch.ArgumentType.STRING,
menu: "THEME",
defaultValue: "dark",
},
},
},
{
opcode: "getPreferredReducedMotion",
blockType: Scratch.BlockType.BOOLEAN,
text: "user prefers reduced motion?",
},
{
opcode: "getPreferredContrast",
blockType: Scratch.BlockType.BOOLEAN,
text: "user prefers more contrast?",
},
],
menus: {
THEME: {
acceptReporters: true,
items: ["light", "dark"],
},
},
};
}

Expand Down Expand Up @@ -73,6 +101,21 @@
return navigator.deviceMemory;
}
}

getPreferredColorScheme(args) {
return (
window.matchMedia("(prefers-color-scheme: dark)").matches ===
(args.THEME === "dark")
);
}

getPreferredReducedMotion() {
return !!window.matchMedia("(prefers-reduced-motion: reduce)").matches;
}

getPreferredContrast() {
return !!window.matchMedia("(prefers-contrast: more)").matches;
}
}

Scratch.extensions.register(new NavigatorInfo());
Expand Down