1- import { Timeline , type Tweet , getColorScheme } from "twi-ext" ;
1+ import { type ColorScheme , Timeline , type Tweet , getColorScheme , onColorSchemeChange } from "twi-ext" ;
22import { asyncQuerySelector , asyncQuerySelectorAll } from "async-query" ;
33import { isNonEmptyArray } from "@robot-inventor/ts-utils" ;
44
5+ const textColorName = "--rlc-color" ;
6+
57interface LinkCardProps {
68 children : {
79 props : {
@@ -20,7 +22,7 @@ const getReactProps = (element: HTMLElement): LinkCardProps | null => {
2022 return isNonEmptyArray ( reactPropsName ) ? ( element [ reactPropsName [ 0 ] ] as unknown as LinkCardProps ) : null ;
2123} ;
2224
23- const onNewTweet = async ( tweet : Tweet , colorScheme : "dark" | "light" ) : Promise < void > => {
25+ const onNewTweet = async ( tweet : Tweet ) : Promise < void > => {
2426 const linkCards = [
2527 ...( await asyncQuerySelectorAll < HTMLElement > ( `[data-testid='card.layoutLarge.media']` , tweet . element ) )
2628 ] ;
@@ -53,7 +55,7 @@ const onNewTweet = async (tweet: Tweet, colorScheme: "dark" | "light"): Promise<
5355 anchor . style . display = "block" ;
5456
5557 const textContainer = document . createElement ( "div" ) ;
56- textContainer . style . color = colorScheme === "dark" ? "white" : "black" ;
58+ textContainer . style . color = `var( ${ textColorName } )` ;
5759 textContainer . style . padding = "0.75rem 0.9rem 0.9rem 0.9rem" ;
5860 textContainer . style . fontFamily = "'Segoe UI',Meiryo,system-ui,-apple-system,BlinkMacSystemFont,sans-serif" ;
5961
@@ -71,12 +73,20 @@ const onNewTweet = async (tweet: Tweet, colorScheme: "dark" | "light"): Promise<
7173 }
7274} ;
7375
76+ const updateTextColor = ( colorScheme : ColorScheme ) : void => {
77+ const darkOrLight = colorScheme === "light" ? "light" : "dark" ;
78+ document . body . style . setProperty ( textColorName , darkOrLight === "dark" ? "white" : "black" ) ;
79+ } ;
80+
7481const main = ( ) : void => {
7582 const timeline = new Timeline ( ) ;
7683
77- const colorScheme = getColorScheme ( ) === "light" ? "light" : "dark" ;
84+ const colorScheme = getColorScheme ( ) ;
85+ updateTextColor ( colorScheme ) ;
86+ onColorSchemeChange ( updateTextColor ) ;
87+
7888 timeline . onNewTweet ( ( tweet ) => {
79- void onNewTweet ( tweet , colorScheme ) ;
89+ void onNewTweet ( tweet ) ;
8090 } ) ;
8191} ;
8292
0 commit comments