@@ -11,74 +11,71 @@ export default {
1111
1212 // Code extracted from https://chrome.google.com/webstore/detail/detect-zero-width-charact/icibkhaehdofmcbfjfpppogioidkilib
1313 onDocumentIdle : ( ) => {
14- ( function ( ) {
15- var unicodeCode ;
16- const zeroWidthCharacterCodes = [ 8203 , 8204 , 8205 , 8288 ] ;
14+ var unicodeCode ;
15+ const zeroWidthCharacterCodes = [ 8203 , 8204 , 8205 , 8288 ] ;
1716
18- let elementsWithZWCC = [ ] ;
19- const highlightCharacters = function ( element ) {
20- const zeroWidthCharacters = String . fromCodePoint (
21- ...zeroWidthCharacterCodes
22- ) ;
23- const regExp = new RegExp ( `([${ zeroWidthCharacters } ])` , "g" ) ;
24- element . innerHTML = element . innerHTML . replace (
25- regExp ,
26- '$1<span class="zero-width-character"></span>'
27- ) ;
28- } ;
29- // From: https://jsfiddle.net/tim333/np874wae/13/
30- const checkElement = function ( element ) {
31- const text = textWithoutChildren ( element ) ;
32- [ ...text ] . forEach ( function ( character ) {
33- unicodeCode = character . codePointAt ( 0 ) ;
34- if (
35- zeroWidthCharacterCodes . includes ( unicodeCode ) &&
36- ! elementsWithZWCC . includes ( element )
37- ) {
38- elementsWithZWCC . push ( element ) ;
39- }
40- } ) ;
41- } ;
42- // From: https://stackoverflow.com/a/9340862/535363
43- const textWithoutChildren = function ( element ) {
44- let child = element . firstChild ,
45- texts = [ ] ;
46- while ( child ) {
47- if ( child . nodeType == 3 ) {
48- texts . push ( child . data ) ;
49- }
50- child = child . nextSibling ;
17+ let elementsWithZWCC = [ ] ;
18+ const highlightCharacters = function ( element ) {
19+ const zeroWidthCharacters = String . fromCodePoint (
20+ ...zeroWidthCharacterCodes
21+ ) ;
22+ const regExp = new RegExp ( `([${ zeroWidthCharacters } ])` , "g" ) ;
23+ element . innerHTML = element . innerHTML . replace (
24+ regExp ,
25+ '$1<span class="zero-width-character"></span>'
26+ ) ;
27+ } ;
28+ // From: https://jsfiddle.net/tim333/np874wae/13/
29+ const checkElement = function ( element ) {
30+ const text = textWithoutChildren ( element ) ;
31+ [ ...text ] . forEach ( function ( character ) {
32+ unicodeCode = character . codePointAt ( 0 ) ;
33+ if (
34+ zeroWidthCharacterCodes . includes ( unicodeCode ) &&
35+ ! elementsWithZWCC . includes ( element )
36+ ) {
37+ elementsWithZWCC . push ( element ) ;
5138 }
52- return texts . join ( "" ) ;
53- } ;
54- const checkPage = function ( ) {
55- const allElements = document . getElementsByTagName ( "*" ) ;
56- [ ...allElements ] . forEach ( checkElement ) ;
57- elementsWithZWCC . forEach ( function ( element ) {
58- element . classList . add ( "zero-width-characters" ) ;
59- highlightCharacters ( element ) ;
60- } ) ;
61- } ;
62-
63- var readyStateCheckInterval = setInterval ( function ( ) {
64- if ( document . readyState === "complete" ) {
65- clearInterval ( readyStateCheckInterval ) ;
66- // Check Page
67- checkPage ( ) ;
68- // Check page again when any input field is changed
69- const inputs = document . querySelectorAll ( "input" ) ;
70- [ ...inputs ] . forEach ( function ( input ) {
71- input . addEventListener ( "change" , checkPage ) ;
72- } ) ;
39+ } ) ;
40+ } ;
41+ // From: https://stackoverflow.com/a/9340862/535363
42+ const textWithoutChildren = function ( element ) {
43+ let child = element . firstChild ,
44+ texts = [ ] ;
45+ while ( child ) {
46+ if ( child . nodeType == 3 ) {
47+ texts . push ( child . data ) ;
7348 }
74- } , 10 ) ;
75- } ) ( ) ;
49+ child = child . nextSibling ;
50+ }
51+ return texts . join ( "" ) ;
52+ } ;
53+ const checkPage = function ( ) {
54+ const allElements = document . getElementsByTagName ( "*" ) ;
55+ [ ...allElements ] . forEach ( checkElement ) ;
56+ console . log ( elementsWithZWCC ) ;
57+ elementsWithZWCC . forEach ( function ( element ) {
58+ element . classList . add ( "zero-width-characters" ) ;
59+ highlightCharacters ( element ) ;
60+ } ) ;
61+ } ;
7662
77- UsefulScriptGlobalPageContext . DOM . injectCssFile (
78- UsefulScriptGlobalPageContext . Extension . getURL (
79- "scripts/detect_zeroWidthCharacters.css"
80- )
81- ) ;
63+ ( async ( ) => {
64+ // inject css
65+ UsefulScriptGlobalPageContext . DOM . injectCssFile (
66+ await UsefulScriptGlobalPageContext . Extension . getURL (
67+ "scripts/detect_zeroWidthCharacters.css"
68+ )
69+ ) ;
70+
71+ // Check Page
72+ checkPage ( ) ;
73+ // Check page again when any input field is changed
74+ const inputs = document . querySelectorAll ( "input" ) ;
75+ [ ...inputs ] . forEach ( function ( input ) {
76+ input . addEventListener ( "change" , checkPage ) ;
77+ } ) ;
78+ } ) ( ) ;
8279 } ,
8380
8481 onClickExtension : ( ) =>
0 commit comments