@@ -64,23 +64,6 @@ const insertIndentCSSRule = (scrapboxIndentOptions) => {
6464 } ) ;
6565} ;
6666
67- const makerAttachment = ( ) => {
68- chrome . storage . local . get ( 'scrapboxIndentOption' , ( result ) => {
69- const scrapboxIndentOptions = result . scrapboxIndentOption ;
70- insertIndentCSSRule ( scrapboxIndentOptions ) ;
71- } ) ;
72- } ;
73-
74- // update
75- chrome . runtime . onMessage . addListener ( ( request ) => {
76- if ( request === 'scrapbox_list_maker' ) {
77- makerAttachment ( ) ;
78- }
79- } ) ;
80-
81- // initialize
82- makerAttachment ( ) ;
83-
8467const indentColorCSS = [
8568 `.indent-mark .char-index{
8669 --scrapbox-indent-maker-opacity: 0.2;
@@ -97,12 +80,57 @@ const indentColorCSS = [
9780 `.app:not(.presentation) .indent-mark .char-index:nth-last-child(1) { background-color: transparent !important; }` ,
9881] ;
9982
100- const insertIndentColorCSSRule = ( ) => {
83+ const insertIndentColorCSSRule = ( isColoring ) => {
84+ // delete existing rules
85+ const cssRules = document . styleSheets [ 0 ] . cssRules ;
86+ const cssRulesNum = cssRules . length ;
87+ for ( let i = cssRulesNum - 1 ; i >= 0 ; i -- ) {
88+ const cssRule = cssRules [ i ] ;
89+ const cssSelector = cssRule . selectorText ;
90+
91+ if ( cssSelector === undefined ) continue ;
92+
93+ if (
94+ cssSelector . match (
95+ / ^ \. a p p : n o t \( .p r e s e n t a t i o n \) \. i n d e n t - m a r k \. c h a r - i n d e x : n t h - c h i l d .* /
96+ )
97+ ) {
98+ document . styleSheets [ 0 ] . deleteRule ( i ) ;
99+ }
100+ }
101+
101102 // insert new rules
102- indentColorCSS . map ( ( css ) => {
103- console . log ( css ) ;
104- document . styleSheets [ 0 ] . insertRule ( css ) ;
103+ if ( isColoring ) {
104+ indentColorCSS . map ( ( css ) => {
105+ document . styleSheets [ 0 ] . insertRule ( css ) ;
106+ } ) ;
107+ }
108+ } ;
109+
110+ const makerAttachment = ( ) => {
111+ chrome . storage . local . get ( 'scrapboxIndentOption' , ( result ) => {
112+ const scrapboxIndentOptions = result . scrapboxIndentOption ;
113+ insertIndentCSSRule ( scrapboxIndentOptions ) ;
105114 } ) ;
106115} ;
107116
108- insertIndentColorCSSRule ( ) ;
117+ const coloringAttachment = ( ) => {
118+ chrome . storage . local . get ( 'scrapboxIndentColoring' , ( result ) => {
119+ const isColoring = result . scrapboxIndentColoring ;
120+ insertIndentColorCSSRule ( isColoring ) ;
121+ } ) ;
122+ } ;
123+
124+ // update
125+ chrome . runtime . onMessage . addListener ( ( request ) => {
126+ if ( request === 'scrapbox_list_maker' ) {
127+ makerAttachment ( ) ;
128+ }
129+ if ( request === 'scrapbox_indent_coloring' ) {
130+ coloringAttachment ( ) ;
131+ }
132+ } ) ;
133+
134+ // initialize
135+ makerAttachment ( ) ;
136+ coloringAttachment ( ) ;
0 commit comments