Created
March 17, 2022 21:45
-
-
Save treetop1500/95525fadd5a09f206526e9fbab9ac3f0 to your computer and use it in GitHub Desktop.
Recaptcha and Mapkit Dark Mode swapping with Javascript
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
// Recaptcha HTML: <div class="g-recaptcha" data-sitekey="{{ site_key }}" data-theme="dark" id="recaptcha"></div> | |
// MapKit HTML: <div id="map" class="h-full"></div> | |
// (also requires installation of mapkit.js and recaptcha.js scripts) | |
var recpatcha = document.getElementById('recaptcha') | |
var mapKitColorMode = "light"; | |
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { | |
recpatcha.setAttribute('data-theme', 'dark'); | |
mapKitColorMode = "dark" | |
} else { | |
recpatcha.setAttribute('data-theme', 'light'); | |
} | |
var map = new mapkit.Map("map", { | |
colorScheme: mapKitColorMode | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment