@@ -92,6 +92,13 @@ export async function archiveConversation(browser: Browser, id: string) {
9292 // Script tags
9393 const scriptTags = document . getElementsByTagName ( "script" )
9494 while ( scriptTags . length > 0 ) scriptTags [ 0 ] ! . remove ( )
95+
96+ // Remove inline CSS variables to make the later step of removing unused CSS variables easier
97+ // <div style="--a: 0px"> ...
98+ // <div style='--a: 0px'> ...
99+ for ( const elWithStyleAttribute of document . querySelectorAll ( "[style]" ) ) {
100+ if ( elWithStyleAttribute . getAttribute ( "style" ) ! . includes ( "--" ) ) elWithStyleAttribute . removeAttribute ( "style" )
101+ }
95102 } )
96103
97104 // https://github.com/gildas-lormeau/single-file-cli/blob/v2.0.75/single-file-cli-api.js#L258
@@ -115,24 +122,21 @@ export async function archiveConversation(browser: Browser, id: string) {
115122 )
116123
117124 const fileContent = pageData . content
118- // Remove Google Sans family and Google Symbol font face
125+ // Remove fonts
119126 . replaceAll ( / @ f o n t - f a c e \s * { [ ^ } ] * } / g, ( fontFaceRule : string ) => {
120127 const fontFamilyMatch = fontFaceRule . match ( / f o n t - f a m i l y : \s * (?< quote > [ ' " ] ? ) (?< fontFamily > [ ^ ' " ] + ) \k<quote > / )
121128 const fontFamily = fontFamilyMatch ?. groups ?. [ "fontFamily" ] ?. trim ( ) ?? ""
122129
123130 if ( includesKatex && fontFamily . startsWith ( "KaTeX" ) ) return fontFaceRule
124131 else return ""
125132 } )
133+ // Remove unused CSS variables
126134 . replaceAll (
127135 // --a: 0px; } .class { ...
128- // <div style="--a: 0px"> ...
129- // <div style='--a: 0px'> ...
130- / (?< variableName > - - [ a - z A - Z 0 - 9 \- ] + ) \s * : \s * (?< value > [ ^ ; \n \} ] + ) \s * [ ; \n ] ? (?< curlyBrace > \} ) ? (?< quote > [ " ' ] ) ? / gm,
131- ( _match , variableName : string , value : string , curlyBrace : string | undefined , quote : string | undefined ) => {
132- const suffix = `${ curlyBrace ?? "" } ${ quote ?? "" } `
133- console . log ( _match , suffix )
134- if ( variablesUsedInDocument . has ( variableName ) ) return `${ variableName } :${ value } ;${ suffix } `
135- return suffix
136+ / (?< variableName > - - [ a - z A - Z 0 - 9 \- ] + ) \s * : \s * (?< value > [ ^ ; \n \} ] + ) \s * [ ; \n ] ? (?< curlyBrace > \} ) ? / gm,
137+ ( _match , variableName : string , value : string , curlyBrace : string | undefined = "" ) => {
138+ if ( variablesUsedInDocument . has ( variableName ) ) return `${ variableName } :${ value } ;${ curlyBrace } `
139+ return curlyBrace
136140 }
137141 )
138142
0 commit comments