diff --git a/src/init.js b/src/init.js index 81bd888..0bd9d66 100644 --- a/src/init.js +++ b/src/init.js @@ -1,6 +1,9 @@ /* global wikipediapreview_init_options */ +import { getColorScheme } from './link/utils'; + wikipediaPreview.init( { root: document, /* eslint-disable-next-line camelcase */ detectLinks: !! wikipediapreview_init_options.detectLinks, + prefersColorScheme: getColorScheme(), } ); diff --git a/src/link/utils.js b/src/link/utils.js index 2e4d703..c4c15ca 100644 --- a/src/link/utils.js +++ b/src/link/utils.js @@ -11,3 +11,10 @@ export const isTextNearTheEdge = ( anchor ) => { ( scrollWidth - anchorXPosition.right ) / scrollWidth < 0.2 ); }; + +export const getColorScheme = () => { + if ( window.matchMedia( '(prefers-color-scheme: dark)' ).matches ) { + return 'dark'; + } + return 'detect'; +};