File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -11,17 +11,18 @@ function getNameRegex(name) {
11
11
return new RegExp ( '\b' + name + '\b' ) ;
12
12
}
13
13
14
- function getNewString ( date ) {
15
- return date . name + ', ' + date . texts [ Math . floor ( date . texts . length * Math . random ( ) ) ] ;
14
+ function getNewString ( date , isEndOfSentence ) {
15
+ return date . name + ', ' + date . texts [ Math . floor ( date . texts . length * Math . random ( ) ) ] + ( isEndOfSentence ? '' : ',' ) ;
16
16
}
17
17
18
18
// extend text content with extension sentences
19
19
function extendText ( ) {
20
20
findTextNodes ( document . body ) . forEach ( function ( node ) {
21
21
data . forEach ( function ( date ) {
22
22
var parts = node . textContent . split ( getNameRegex ( date . name ) ) ;
23
- for ( var i = 1 ; i < parts . length ; i ++ ) {
24
- parts . splice ( i , 0 , getNewString ( date ) ) ;
23
+ for ( var i = parts . length - 1 ; i > 0 ; i -- ) {
24
+ var isEndOfSentence = / \s * [ ^ a - z 0 - 9 ] / i. test ( parts [ i ] ) ;
25
+ parts . splice ( i , 0 , getNewString ( date , isEndOfSentence ) ) ;
25
26
}
26
27
node . textContent = parts . join ( '' ) ;
27
28
} ) ;
You can’t perform that action at this time.
0 commit comments