Skip to content

Commit 25d3edc

Browse files
committed
Fix consistency, simplify code.
1 parent 393a5ed commit 25d3edc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ var injector = require('connect-injector');
55

66
module.exports = function injectBrowserSync(browserSync, options) {
77
var snippet = '';
8-
var options = options || {}
9-
var tag = '</body>'
10-
var regex = /<\s*\/\s*body\s*>(?!(.|\n)*<\s*\/\s*body\s*>)/gi
8+
var options = options || {};
119

1210
if (options.injectHead === true) {
13-
tag = '</head>'
14-
regex = /<\/head>/gi
11+
var tag = '</head>';
12+
var find = /<\/head>/gi;
13+
} else {
14+
var tag = '</body>';
15+
var find = /<\/body>(?!(.|\n)*<\/body>)/gi;
1516
}
1617

1718
browserSync.emitter.on('service:running', function(data) {
@@ -25,8 +26,7 @@ module.exports = function injectBrowserSync(browserSync, options) {
2526
return contentType && (contentType.toLowerCase().indexOf('text/html') >= 0);
2627
}, function converter(content, req, res, callback) {
2728
function inject() {
28-
var lastBody = regex
29-
var injected = content.toString().replace(lastBody, snippet + tag);
29+
var injected = content.toString().replace(find, snippet + tag);
3030
callback(null, injected);
3131
};
3232

0 commit comments

Comments
 (0)