Skip to content

Instantly share code, notes, and snippets.

@treetop1500
Created March 17, 2022 21:45
Show Gist options
  • Save treetop1500/95525fadd5a09f206526e9fbab9ac3f0 to your computer and use it in GitHub Desktop.
Save treetop1500/95525fadd5a09f206526e9fbab9ac3f0 to your computer and use it in GitHub Desktop.
Recaptcha and Mapkit Dark Mode swapping with Javascript
// 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