From 0989e3b4efc10bd11c4116bd6d8e3fa711b40d98 Mon Sep 17 00:00:00 2001 From: DNin01 <106490990+DNin01@users.noreply.github.com> Date: Mon, 17 Jul 2023 15:23:33 -0700 Subject: [PATCH 1/3] New extension: Preferences --- extensions/DNin/get-user-prefs.js | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 extensions/DNin/get-user-prefs.js diff --git a/extensions/DNin/get-user-prefs.js b/extensions/DNin/get-user-prefs.js new file mode 100644 index 0000000000..a4231ddb25 --- /dev/null +++ b/extensions/DNin/get-user-prefs.js @@ -0,0 +1,49 @@ +(function(Scratch) { + 'use strict'; + + class GetUserPreferences { + getInfo() { + return { + id: 'getuserpreferences', + name: 'Preferences', + blocks: [ + { + opcode: 'prefersColorScheme', + blockType: Scratch.BlockType.BOOLEAN, + text: 'prefers [THEME] color scheme?', + arguments: { + THEME: { type: Scratch.ArgumentType.MENU, menu: 'THEME', defaultValue: 'dark' } + } + }, + { + opcode: 'prefersReducedMotion', + blockType: Scratch.BlockType.BOOLEAN, + text: 'prefers reduced motion?' + }, + { + opcode: 'prefersContrast', + blockType: Scratch.BlockType.BOOLEAN, + text: 'prefers more contrast?' + } + ], + menus: { + THEME: { + acceptReporters: true, + items: ['light', 'dark'] + } + } + }; + } + prefersColorScheme(args) { + return ((window.matchMedia('(prefers-color-scheme: dark)').matches) === (args.THEME === 'dark')); + } + prefersReducedMotion() { + return (window.matchMedia('(prefers-reduced-motion: reduce)').matches); + } + prefersContrast() { + return (window.matchMedia('(prefers-contrast: more)').matches); + } + } + + Scratch.extensions.register(new GetUserPreferences()); +})(Scratch); From 868d0c53e43a73af3919f329b03c0bcca5ce16f6 Mon Sep 17 00:00:00 2001 From: DNin01 <106490990+DNin01@users.noreply.github.com> Date: Fri, 4 Aug 2023 11:24:59 -0700 Subject: [PATCH 2/3] Merge with Navigator --- extensions/DNin/get-user-prefs.js | 49 ------------------------------- extensions/navigator.js | 38 +++++++++++++++++++++++- 2 files changed, 37 insertions(+), 50 deletions(-) delete mode 100644 extensions/DNin/get-user-prefs.js diff --git a/extensions/DNin/get-user-prefs.js b/extensions/DNin/get-user-prefs.js deleted file mode 100644 index a4231ddb25..0000000000 --- a/extensions/DNin/get-user-prefs.js +++ /dev/null @@ -1,49 +0,0 @@ -(function(Scratch) { - 'use strict'; - - class GetUserPreferences { - getInfo() { - return { - id: 'getuserpreferences', - name: 'Preferences', - blocks: [ - { - opcode: 'prefersColorScheme', - blockType: Scratch.BlockType.BOOLEAN, - text: 'prefers [THEME] color scheme?', - arguments: { - THEME: { type: Scratch.ArgumentType.MENU, menu: 'THEME', defaultValue: 'dark' } - } - }, - { - opcode: 'prefersReducedMotion', - blockType: Scratch.BlockType.BOOLEAN, - text: 'prefers reduced motion?' - }, - { - opcode: 'prefersContrast', - blockType: Scratch.BlockType.BOOLEAN, - text: 'prefers more contrast?' - } - ], - menus: { - THEME: { - acceptReporters: true, - items: ['light', 'dark'] - } - } - }; - } - prefersColorScheme(args) { - return ((window.matchMedia('(prefers-color-scheme: dark)').matches) === (args.THEME === 'dark')); - } - prefersReducedMotion() { - return (window.matchMedia('(prefers-reduced-motion: reduce)').matches); - } - prefersContrast() { - return (window.matchMedia('(prefers-contrast: more)').matches); - } - } - - Scratch.extensions.register(new GetUserPreferences()); -})(Scratch); diff --git a/extensions/navigator.js b/extensions/navigator.js index bbb615e75d..238ab3a59e 100644 --- a/extensions/navigator.js +++ b/extensions/navigator.js @@ -21,8 +21,32 @@ opcode: 'getMemory', 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.MENU, 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'] } - ] + } }; } @@ -65,6 +89,18 @@ 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()); From c748cfa463a25aac318bd664d1d7e634d5537cf9 Mon Sep 17 00:00:00 2001 From: Muffin Date: Fri, 25 Aug 2023 01:27:35 -0500 Subject: [PATCH 3/3] format, also ArgumentType.MENU is not a thing --- extensions/navigator.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/extensions/navigator.js b/extensions/navigator.js index 1e1edab807..0896c20a28 100644 --- a/extensions/navigator.js +++ b/extensions/navigator.js @@ -24,33 +24,37 @@ { opcode: "getMemory", blockType: Scratch.BlockType.REPORTER, - text: 'device memory in GB' + text: "device memory in GB", }, { - opcode: 'getPreferredColorScheme', + opcode: "getPreferredColorScheme", blockType: Scratch.BlockType.BOOLEAN, - text: 'user prefers [THEME] color scheme?', + text: "user prefers [THEME] color scheme?", arguments: { - THEME: { type: Scratch.ArgumentType.MENU, menu: 'THEME', defaultValue: 'dark' } - } + THEME: { + type: Scratch.ArgumentType.STRING, + menu: "THEME", + defaultValue: "dark", + }, + }, }, { - opcode: 'getPreferredReducedMotion', + opcode: "getPreferredReducedMotion", blockType: Scratch.BlockType.BOOLEAN, - text: 'user prefers reduced motion?' + text: "user prefers reduced motion?", }, { - opcode: 'getPreferredContrast', + opcode: "getPreferredContrast", blockType: Scratch.BlockType.BOOLEAN, - text: 'user prefers more contrast?' - } + text: "user prefers more contrast?", + }, ], menus: { THEME: { acceptReporters: true, - items: ['light', 'dark'] - } - } + items: ["light", "dark"], + }, + }, }; } @@ -99,15 +103,18 @@ } getPreferredColorScheme(args) { - return ((window.matchMedia('(prefers-color-scheme: dark)').matches) === (args.THEME === 'dark')); + return ( + window.matchMedia("(prefers-color-scheme: dark)").matches === + (args.THEME === "dark") + ); } getPreferredReducedMotion() { - return (!!window.matchMedia('(prefers-reduced-motion: reduce)').matches); + return !!window.matchMedia("(prefers-reduced-motion: reduce)").matches; } getPreferredContrast() { - return (!!window.matchMedia('(prefers-contrast: more)').matches); + return !!window.matchMedia("(prefers-contrast: more)").matches; } }