Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit a05849a

Browse files
authored
Merge pull request #6 from kip-13/highlight-zero-width-characters
Highlight zero-width characters
2 parents 7f8f417 + a71916e commit a05849a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/inject/inject.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@
1717
position: absolute;
1818
right: 0;
1919
}
20+
21+
.zero-width-character:after {
22+
color: red;
23+
content: '\25CF';
24+
}

src/inject/inject.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
(function() {
22
let elementsWithZWCC = [];
33

4+
/**
5+
* Highlight zero-width character in DOM element
6+
*
7+
* @param {dom node} element A DOM node.
8+
*/
9+
const highlightCharacters = function(element) {
10+
const zeroWidthCharacters = String.fromCodePoint(...zeroWidthCharacterCodes);
11+
const regExp = new RegExp(`([${zeroWidthCharacters}])`, 'g')
12+
13+
element.innerHTML = element.innerHTML
14+
.replace(regExp, '$1<span class="zero-width-character"></span>');
15+
};
16+
417
/**
518
* Checks DOM element for zero-width character.
619
*
@@ -22,10 +35,6 @@
2235
elementsWithZWCC.push(element)
2336
}
2437
});
25-
26-
elementsWithZWCC.forEach(function( element ) {
27-
element.classList.add('zero-width-characters');
28-
})
2938
}
3039

3140
/**
@@ -59,7 +68,13 @@
5968
*/
6069
const checkPage = function() {
6170
const allElements = document.getElementsByTagName('*');
62-
[...allElements].forEach( checkElement );
71+
72+
[...allElements].forEach(checkElement);
73+
74+
elementsWithZWCC.forEach(function( element ) {
75+
element.classList.add('zero-width-characters');
76+
highlightCharacters(element);
77+
});
6378
}
6479

6580
chrome.extension.sendMessage({}, function(response) {

0 commit comments

Comments
 (0)