55// each testing is wrapped by a settimeout timmer to make it async
66// because the testing can be a long time if too many.
77
8- var debugMode = false ;
8+ var debugMode = process . env . NODE_ENV !== 'production' ;
99const cssHelper = require ( './cssHelper' ) ;
1010
1111// may match accoding to interaction
12- const pseudocls = '((-(webkit|moz|ms|o)-)?(full-screen|fullscreen))|-o-prefocus|active|checked|disabled|empty|enabled|focus|hover|in-range|invalid|link|out-of-range|target|valid|visited' ,
13- pseudoele = '((-(webkit|moz|ms|o)-)?(focus-inner|input-placeholder|placeholder|selection|resizer|scrollbar(-(button|thumb|corner|track(-piece)?))?))|-ms-(clear|reveal|expand)|-moz-(focusring)|-webkit-(details-marker)|after|before|first-letter|first-line' ;
12+ const PseudoClass = '((-(webkit|moz|ms|o)-)?(full-screen|fullscreen))|-o-prefocus|active|checked|disabled|empty|enabled|focus|hover|in-range|invalid|link|out-of-range|target|valid|visited' ,
13+ PseudoElement = '((-(webkit|moz|ms|o)-)?(focus-inner|input-placeholder|placeholder|selection|resizer|scrollbar(-(button|thumb|corner|track(-piece)?))?))|-ms-(clear|reveal|expand)|-moz-(focusring)|-webkit-(details-marker)|after|before|first-letter|first-line' ,
14+ MaxPossiblePseudoLength = 30 ,
15+ REG0 = new RegExp ( '^(:(' + PseudoClass + ')|::?(' + PseudoElement + '))+$' , '' ) ,
16+ REG1 = new RegExp ( '( |^)(:(' + PseudoClass + ')|::?(' + PseudoElement + '))+( |$)' , 'ig' ) ,
17+ REG2 = new RegExp ( '\\((:(' + PseudoClass + ')|::?(' + PseudoElement + '))+\\)' , 'ig' ) ,
18+ REG3 = new RegExp ( '(:(' + PseudoClass + ')|::?(' + PseudoElement + '))+' , 'ig' ) ;
1419
1520function filterRules ( $0 , objCss , taskTimerRecord ) {
1621 var promises = [ ] ;
@@ -29,7 +34,7 @@ function filterRules($0, objCss, taskTimerRecord) {
2934 objCss . normRule . forEach ( function ( rule , idx ) {
3035 promises . push ( new Promise ( function ( res , rej ) {
3136 var timer = setTimeout ( function ( ) {
32- if ( idx % 100 === 0 ) {
37+ if ( idx % 1000 === 0 ) {
3338 chrome . runtime . sendMessage ( {
3439 dom : domlist . length - 1 ,
3540 rule : objCss . normRule . length ,
@@ -53,21 +58,21 @@ function filterRules($0, objCss, taskTimerRecord) {
5358 // but wont apply now
5459 // eg. :active{xxx}
5560 // only works when clicked on and actived
56- if ( sel . match ( new RegExp ( '^(:(' + pseudocls + ')|::?(' + pseudoele + '))+$' , '' ) ) ) {
61+ if ( sel . length < MaxPossiblePseudoLength && sel . match ( REG0 ) ) {
5762 selMatched . push ( sel ) ;
5863 } else {
5964 let count = [ ] ;
60- let replacedSel = sel . replace ( new RegExp ( '( |^)(:(' + pseudocls + ')|::?(' + pseudoele + '))+( |$)' , 'ig' ) , ' * ') ;
61- replacedSel = replacedSel . replace ( new RegExp ( '\\((:(' + pseudocls + ')|::?(' + pseudoele + '))+\\)' , 'ig' ) , ' (*)') ;
62- replacedSel = replacedSel . replace ( new RegExp ( '(:(' + pseudocls + ')|::?(' + pseudoele + '))+' , 'ig' ) , '' ) ;
63- try {
64- if ( $0 . matches ( sel ) || $0 . querySelectorAll ( sel ) . length !== 0 ) {
65- selMatched . push ( sel ) ;
66- }
67- } catch ( e ) {
68- count . push ( sel ) ;
69- count . push ( e ) ;
70- }
65+ let replacedSel = sel . replace ( REG1 , ' * ' )
66+ . replace ( REG2 , '(*)' )
67+ . replace ( REG3 , '' ) ;
68+ // try {
69+ // if ($0.matches(sel) || $0.querySelectorAll(sel).length !== 0) {
70+ // selMatched.push(sel);
71+ // }
72+ // } catch (e) {
73+ // count.push(sel);
74+ // count.push(e);
75+ // }
7176 try {
7277 if ( $0 . matches ( replacedSel ) || $0 . querySelectorAll ( replacedSel ) . length !== 0 ) {
7378 selMatched . push ( sel ) ;
0 commit comments