File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+ window . colorThemes = [ ] ;
2+ const htmlStyles = getComputedStyle ( document . documentElement ) ;
3+ const targetStylesheet = document . querySelector ( ".page_code_color style" ) ;
4+ const regex = / - - ( [ ^ : \s ] + ) : \s * v a r \( - - ( [ ^ ) ] + ) \) ; / g;
5+ window . colorThemes . push ( { } ) ;
6+
7+ if ( targetStylesheet ) {
8+ const rules = targetStylesheet . sheet . cssRules || targetStylesheet . sheet . rules ;
9+ for ( const rule of rules ) {
10+ if ( rule . cssText . includes ( "data-theme=" ) && ! rule . cssText . includes ( `data-theme="inherit"` ) ) {
11+ const styleObject = { } ;
12+ let match ;
13+ while ( ( match = regex . exec ( rule . cssText ) ) !== null ) {
14+ const key = "--" + match [ 1 ] ;
15+ const value = htmlStyles . getPropertyValue ( "--" + match [ 2 ] ) ;
16+ styleObject [ key ] = value ;
17+ }
18+ window . colorThemes . push ( styleObject ) ;
19+ }
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments