-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdiff-highlighter.js
806 lines (661 loc) · 25.9 KB
/
diff-highlighter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
// Generated by CoffeeScript 1.6.2
(function() {
var DiffProcessor, File, HtmlLineSplitter, HtmlTag, Line, LineMerger, TagStack, addedElements, dropNonexisting, logMessages, longestCommonPrefix, notEmpty, style, unique, urlEncodeFilePath,
__slice = [].slice,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
logMessages = function() {
var messages;
messages = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
};
longestCommonPrefix = function() {
var combinePrefix, firstString, i, prefix, string, strings, _i, _j, _len, _ref, _ref1,
_this = this;
strings = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
prefix = [];
firstString = strings[0];
combinePrefix = function() {
return prefix.join('');
};
if (strings.length < 2) {
return combinePrefix();
}
for (i = _i = 0, _ref = firstString.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
_ref1 = strings.slice(1);
for (_j = 0, _len = _ref1.length; _j < _len; _j++) {
string = _ref1[_j];
if (string[i] !== firstString[i]) {
return combinePrefix();
}
}
prefix.push(firstString[i]);
}
return combinePrefix();
};
dropNonexisting = function(array) {
var element;
return ((function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = array.length; _i < _len; _i++) {
element = array[_i];
if (element != null) {
_results.push(element);
}
}
return _results;
})()) || [];
};
notEmpty = function(array) {
if (array.length > 0) {
return array;
} else {
return null;
}
};
unique = function(array) {
return array.filter(function(value, index, self) {
return self.indexOf(value) === index;
});
};
addedElements = function(oldArray, newArray) {
var element, _i, _len;
for (_i = 0, _len = newArray.length; _i < _len; _i++) {
element = newArray[_i];
if (oldArray.indexOf(element) === -1) {
return true;
}
}
return false;
};
urlEncodeFilePath = function(filePath) {
return encodeURIComponent(filePath).replace(/%2F/g, '/');
};
HtmlTag = (function() {
var tagTypeRegex;
tagTypeRegex = /<(\/?)\s*(\w+).*?(\/?)\w*>/;
function HtmlTag(tag) {
var match;
this.tag = tag;
match = tagTypeRegex.exec(this.tag);
this.isClosing = (match[1] || null) != null;
this.tagType = match[2].toLowerCase();
this.isSelfContained = (match[3] || null) != null;
}
HtmlTag.prototype.isClosingTag = function() {
return this.isClosing;
};
HtmlTag.prototype.isOpeningTag = function() {
return !this.isClosingTag() && !this.isSelfContained;
};
HtmlTag.prototype.canClose = function(otherTag) {
return this.tagType === otherTag.tagType;
};
HtmlTag.prototype.getText = function() {
return this.tag;
};
HtmlTag.prototype.getClosingTagText = function() {
return "</" + this.tagType + ">";
};
return HtmlTag;
})();
TagStack = (function() {
function TagStack() {
this.tagStack = [];
}
TagStack.prototype.addTag = function(tag) {
var openingTag;
if (tag.isClosingTag()) {
openingTag = this.tagStack.pop();
if (!(tag.canClose(openingTag) && openingTag.isOpeningTag())) {
throw 'Tags do not match: ' + tag.tag + " cannot close " + openingTag.tag;
}
} else {
return this.tagStack.push(tag);
}
};
TagStack.prototype.addTagFromStack = function(tag, stack) {
tag.fromStack = stack;
return this.addTag(tag);
};
TagStack.prototype.calculateTagDepth = function(index) {
return this.tagStack.length - index;
};
TagStack.prototype.getPrematurelyClosedTagsIndex = function(closingTag) {
var i, tag, _i, _ref;
if (closingTag.isClosingTag() && this.tagStack.length > 0) {
_ref = this.tagStack;
for (i = _i = _ref.length - 1; _i >= 0; i = _i += -1) {
tag = _ref[i];
if (closingTag.canClose(tag)) {
return i;
}
}
}
return null;
};
TagStack.prototype.getPrematurelyClosedTagsFromIndex = function(index) {
return this.tagStack.slice(index).reverse();
};
TagStack.prototype.getPrematurelyClosedTags = function(tag, notEarlyStack, earlyStack) {
var earlyStackTagIndex, notEarlyStackTagIndex;
if (tag.isClosingTag()) {
earlyStackTagIndex = earlyStack.getPrematurelyClosedTagsIndex(tag);
if (earlyStackTagIndex != null) {
notEarlyStackTagIndex = notEarlyStack.getPrematurelyClosedTagsIndex(tag);
if (notEarlyStackTagIndex != null) {
if (earlyStack.calculateTagDepth(earlyStackTagIndex) >= notEarlyStack.calculateTagDepth(notEarlyStackTagIndex)) {
return earlyStack.getPrematurelyClosedTagsFromIndex(earlyStackTagIndex);
}
}
}
}
return [];
};
return TagStack;
})();
HtmlLineSplitter = (function() {
function HtmlLineSplitter(line) {
this.line = line;
this.tagRegex = /(<[^>]*?>)|([^<]*)/g;
this.advance();
}
HtmlLineSplitter.prototype.advance = function() {
return this.top = this.tagRegex.exec(this.line);
};
HtmlLineSplitter.prototype.getContent = function() {
return this.top[0] || null;
};
HtmlLineSplitter.prototype.setContent = function(content) {
return this.top[0] = content;
};
HtmlLineSplitter.prototype.getTag = function() {
return new HtmlTag(this.getContent());
};
HtmlLineSplitter.prototype.popContent = function(value) {
value = this.getContent();
this.advance();
return value;
};
HtmlLineSplitter.prototype.isTag = function() {
return (this.top[1] || null) != null;
};
HtmlLineSplitter.prototype.isText = function() {
return (this.top[2] || null) != null;
};
HtmlLineSplitter.prototype.hasContent = function() {
return this.getContent() != null;
};
HtmlLineSplitter.prototype.isClosingTag = function() {
return this.isTag() && this.getContent().indexOf('/') !== -1;
};
HtmlLineSplitter.prototype.removeTextPrefix = function(prefix) {
var previous;
previous = this.getContent();
if (previous.length === prefix.length) {
return this.advance();
} else {
return this.setContent(previous.substr(prefix.length));
}
};
return HtmlLineSplitter;
})();
LineMerger = (function() {
function LineMerger(highlightedLine, diffLine) {
this.highlighted = new HtmlLineSplitter(highlightedLine);
this.diff = new HtmlLineSplitter(diffLine);
this.highlightedStack = new TagStack();
this.diffStack = new TagStack();
this.output = [];
}
LineMerger.prototype.appendPopped = function(splitter) {
return this.output.push(splitter.popContent());
};
LineMerger.prototype.mergeTextIntoOutput = function() {
var prefix;
prefix = longestCommonPrefix(this.highlighted.getContent(), this.diff.getContent());
if (prefix.length > 0) {
this.output.push(prefix);
this.highlighted.removeTextPrefix(prefix);
return this.diff.removeTextPrefix(prefix);
} else {
throw 'Could not find prefix:\n' + this.highlighted.getContent() + '\n' + this.diff.getContent() + '\n';
}
};
LineMerger.prototype.mergeTagIntoOutput = function(splitter, stack) {
var otherStack, prematurelyClosedTags, t, tag, _i, _j, _len, _len1, _results;
otherStack = stack !== this.diffStack ? this.diffStack : this.highlightedStack;
tag = splitter.getTag();
prematurelyClosedTags = stack.getPrematurelyClosedTags(tag, stack, otherStack);
stack.addTag(tag);
for (_i = 0, _len = prematurelyClosedTags.length; _i < _len; _i++) {
t = prematurelyClosedTags[_i];
this.output.push(t.getClosingTagText());
}
if (tag.tagType === 'br') {
splitter.popContent();
} else {
this.appendPopped(splitter);
}
_results = [];
for (_j = 0, _len1 = prematurelyClosedTags.length; _j < _len1; _j++) {
t = prematurelyClosedTags[_j];
_results.push(this.output.push(t.getText()));
}
return _results;
};
LineMerger.prototype.combineIntoHtml = function() {
while (this.highlighted.hasContent() || this.diff.hasContent()) {
if (this.highlighted.isTag()) {
this.mergeTagIntoOutput(this.highlighted, this.highlightedStack);
} else if (this.diff.isTag()) {
this.mergeTagIntoOutput(this.diff, this.diffStack);
} else if (this.highlighted.isText() && this.diff.isText()) {
this.mergeTextIntoOutput();
} else if (this.highlighted.hasContent()) {
this.appendPopped(this.highlighted);
} else if (this.diff.hasContent()) {
this.appendPopped(this.diff);
}
}
return this.output.join('');
};
return LineMerger;
})();
File = (function() {
function File(path) {
this.path = path;
this.lines = [];
}
File.prototype.storeLine = function(lineElement, line, lineNumber) {
line = new Line(lineElement, line, lineNumber);
this.lines[lineNumber] = line;
return line;
};
File.prototype.storeDiffLine = function(lineElement, line, lineNumberPrevious, lineNumberCurrent) {
var storedLine;
storedLine = new Line(lineElement, line, lineNumberCurrent || lineNumberPrevious);
storedLine.setIsDiff(lineNumberPrevious);
this.lines.push(storedLine);
return storedLine;
};
File.prototype.getLine = function(index) {
return this.lines[index];
};
return File;
})();
Line = (function() {
var nonBreakingSpaceRegex;
nonBreakingSpaceRegex = / /g;
function Line(lineElement, line, lineNumber) {
this.lineElement = lineElement;
this.line = line;
this.lineNumber = lineNumber;
this.diffMarker = '';
}
Line.prototype.setIsDiff = function(lineNumberPrevious) {
this.lineNumberPrevious = lineNumberPrevious;
this.line = this.line.replace(nonBreakingSpaceRegex, ' ');
this.diffMarker = this.line.substr(0, 1);
return this.line = this.line.substr(1);
};
Line.prototype.diffAdded = function() {
return this.diffMarker === '+';
};
Line.prototype.diffRemoved = function() {
return this.diffMarker === '-';
};
Line.prototype.diffUnchanged = function() {
return !this.diffAdded() && !this.diffRemoved() && this.diffMarker !== '@';
};
return Line;
})();
DiffProcessor = (function() {
var binRegex, endsInShaRegex, permalinkShasRegex;
endsInShaRegex = /[0-9a-fA-F]{40}$/;
binRegex = /bin/i;
permalinkShasRegex = /compare\/[^:]*:([^.]*)...[^:]*:([^\/]*)/;
function DiffProcessor() {
this.refreshDataAndHighlight = __bind(this.refreshDataAndHighlight, this); this.currentRepoPath = '';
this.updateCurrentRepoPath();
this.currentCommitIdentifier = '';
this.parentCommitIdentifiers = '';
this.updateCommitIdentifiers();
this.changedFilePaths = [];
this.updateChangedFilePaths();
this.diffData = this.getRegularDiffData();
this.parentData = {};
this.currentData = {};
this.mutationObserver = this.getMutationObserver();
}
DiffProcessor.prototype.getMutationObserver = function() {
var mutationObserver, observerConfig;
mutationObserver = new MutationObserver(this.refreshDataAndHighlight);
observerConfig = {
childList: true,
characterData: true,
subtree: true
};
mutationObserver.observe(document, observerConfig);
return mutationObserver;
};
DiffProcessor.prototype.getPartialShaFromMergingPermalink = function(index) {
var _ref, _ref1, _ref2;
return (_ref = document.querySelector('a.js-permalink-shortcut')) != null ? (_ref1 = _ref.href) != null ? (_ref2 = _ref1.match(permalinkShasRegex)) != null ? _ref2[index + 1] : void 0 : void 0 : void 0;
};
DiffProcessor.prototype.getMergingBranchCommitIdentifier = function(index) {
var element, _ref;
element = document.querySelectorAll('#js-discussion-header .gh-header-meta span.commit-ref.current-branch span')[index] || document.querySelectorAll('.branch-name span.js-selectable-text')[index];
return element != null ? (_ref = element.textContent) != null ? _ref.trim() : void 0 : void 0;
};
DiffProcessor.prototype.getGuessAtCurrentCommitIdentifier = function() {
var result, _ref, _ref1, _ref2, _ref3;
result = this.getMergingBranchFromFromComment();
result || (result = (_ref = document.querySelector('.commit a')) != null ? (_ref1 = _ref.href) != null ? (_ref2 = _ref1.match(/[a-f0-9]{40}$/)) != null ? _ref2[0] : void 0 : void 0 : void 0);
result || (result = this.getPartialShaFromMergingPermalink(1));
result || (result = this.getMergingBranchCommitIdentifier(1));
return result || ((_ref3 = document.body.innerHTML.match(/commit\/([a-f0-9]{40})/)) != null ? _ref3[1] : void 0);
};
DiffProcessor.prototype.getMergingBranchFromFromComment = function() {
var result, _ref;
return result = (_ref = /head sha1: "([0-9a-fA-F]{40})"/.exec(document.body.innerHTML)) != null ? _ref[1] : void 0;
};
DiffProcessor.prototype.getMergingBranchToFromComment = function() {
var result, _ref;
return result = (_ref = /base sha1: "([0-9a-fA-F]{40})"/.exec(document.body.innerHTML)) != null ? _ref[1] : void 0;
};
DiffProcessor.prototype.getMergingBranchTo = function() {
return this.getMergingBranchToFromComment();
};
DiffProcessor.prototype.getMergingBranchFrom = function() {
return this.getMergingBranchFromFromComment();
};
DiffProcessor.prototype.getParentCommitIdentifiers = function() {
var e;
return notEmpty(dropNonexisting([this.getMergingBranchTo()])) || notEmpty((function() {
var _i, _len, _ref, _ref1, _results;
_ref = document.querySelectorAll('.commit-meta .sha-block a.sha');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
e = _ref[_i];
_results.push((_ref1 = endsInShaRegex.exec(e.href)) != null ? _ref1[0] : void 0);
}
return _results;
})()) || dropNonexisting([this.getPartialShaFromMergingPermalink(0)]) || dropNonexisting([this.getMergingBranchCommitIdentifier(0)]);
};
DiffProcessor.prototype.updateCurrentRepoPath = function() {
var changed, currentRepoPath;
changed = false;
currentRepoPath = window.location.pathname.match(/\/([^\/]*\/[^\/]*)/)[1];
if (currentRepoPath !== this.currentRepoPath) {
this.currentRepoPath = currentRepoPath;
changed = true;
}
return changed;
};
DiffProcessor.prototype.updateCommitIdentifiers = function() {
var changed, currentCommitIdentifier, parentCommitIdentifiers;
changed = false;
currentCommitIdentifier = this.getGuessAtCurrentCommitIdentifier();
if (currentCommitIdentifier !== this.currentCommitIdentifier) {
this.currentCommitIdentifier = currentCommitIdentifier;
changed = true;
}
parentCommitIdentifiers = this.getParentCommitIdentifiers();
if (parentCommitIdentifiers.toString() !== this.parentCommitIdentifiers.toString()) {
this.parentCommitIdentifiers = parentCommitIdentifiers;
changed = true;
}
return changed;
};
DiffProcessor.prototype.updateChangedFilePaths = function() {
var changed, changedFilePaths;
changed = false;
changedFilePaths = this.getChangedFilePaths();
if (addedElements(this.changedFilePaths, changedFilePaths)) {
changed = true;
}
this.changedFilePaths = changedFilePaths;
return changed;
};
DiffProcessor.prototype.getChangedFilePaths = function() {
var changedFileLinks, link, path, _i, _len, _ref, _ref1, _ref2, _ref3, _results;
changedFileLinks = document.querySelectorAll('.file .info span.js-selectable-text');
_results = [];
for (_i = 0, _len = changedFileLinks.length; _i < _len; _i++) {
link = changedFileLinks[_i];
if (binRegex.test((_ref = link.parentElement) != null ? _ref.childNodes[1].textContent : void 0)) {
continue;
}
path = (_ref1 = link.textContent) != null ? _ref1.trim() : void 0;
if ((path != null ? path.indexOf('→') : void 0) !== -1) {
path = (_ref2 = link.parentElement) != null ? (_ref3 = _ref2.parentElement) != null ? _ref3.getAttribute('data-path') : void 0 : void 0;
}
_results.push(path);
}
return _results;
};
DiffProcessor.prototype.getLinesToMerge = function(filePath, line) {
var id, _ref;
if (line.diffAdded() || line.diffUnchanged()) {
return dropNonexisting([(_ref = this.currentData[filePath]) != null ? _ref.getLine(line.lineNumber) : void 0]);
} else if (line.diffRemoved()) {
return dropNonexisting((function() {
var _i, _len, _ref1, _ref2, _ref3, _results;
_ref1 = this.parentCommitIdentifiers;
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
id = _ref1[_i];
_results.push((_ref2 = this.parentData[id]) != null ? (_ref3 = _ref2[filePath]) != null ? _ref3.getLine(line.lineNumberPrevious) : void 0 : void 0);
}
return _results;
}).call(this));
} else {
return [];
}
};
DiffProcessor.prototype.highlight = function() {
return this.highlightDiffData(this.diffData);
};
DiffProcessor.prototype.highlightDiffData = function(diffData) {
var e, file, fileList, filePath, key, line, mergeLine, mergeLineText, _results;
_results = [];
for (filePath in diffData) {
fileList = diffData[filePath];
_results.push((function() {
var _i, _len, _results1;
_results1 = [];
for (_i = 0, _len = fileList.length; _i < _len; _i++) {
file = fileList[_i];
_results1.push((function() {
var _ref, _results2;
_ref = file.lines;
_results2 = [];
for (key in _ref) {
line = _ref[key];
if ((line != null ? line.lineElement.getAttribute('github-diff-highlighter-highlighted') : void 0) != null) {
file[key] = null;
continue;
}
_results2.push((function() {
var _j, _len1, _ref1, _results3;
_ref1 = this.getLinesToMerge(filePath, line);
_results3 = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
mergeLine = _ref1[_j];
try {
mergeLineText = mergeLine.line.replace(/ /g, ' ');
line.lineElement.innerHTML = line.diffMarker + new LineMerger(line.line, mergeLineText).combineIntoHtml();
line.lineElement.setAttribute('github-diff-highlighter-highlighted', true);
break;
} catch (_error) {
e = _error;
}
}
return _results3;
}).call(this));
}
return _results2;
}).call(this));
}
return _results1;
}).call(this));
}
return _results;
};
DiffProcessor.prototype.fetchPageHtml = function(url, callback) {
var xhr,
_this = this;
xhr = new XMLHttpRequest();
xhr.onerror = function() {
return logMessages(xhr.status, xhr);
};
xhr.onload = function() {
if (xhr.status === 200) {
callback(null, xhr.responseText);
return _this.highlight();
} else {
return xhr.onerror(xhr);
}
};
xhr.open("GET", url);
return xhr.send();
};
DiffProcessor.prototype.buildBlobPrefixFromCommitIdentifier = function(sha) {
return "https://github.com/" + this.currentRepoPath + "/tree/" + sha + "/";
};
DiffProcessor.prototype.buildBlobPrefixFromCommitUrl = function(commitUrl) {
return this.buildCommitPathFromSha(this.endsInShaRegex.exec(commitUrl)[0]);
};
DiffProcessor.prototype.fetchCurrentHtml = function() {
var blobPrefix, file, filePath, _i, _len, _ref, _results;
blobPrefix = this.buildBlobPrefixFromCommitIdentifier(this.currentCommitIdentifier);
_ref = this.changedFilePaths;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
filePath = _ref[_i];
this.currentData[filePath] = file = new File(filePath);
_results.push(this.fetchPageHtml(blobPrefix + urlEncodeFilePath(filePath), this.getStoreHtml(file)));
}
return _results;
};
DiffProcessor.prototype.getStoreHtml = function(htmlFile) {
var _this = this;
return function(error, html) {
var file, files, line, lineContents, lineNumber, _i, _len, _results;
if (error) {
return;
}
files = _this.getFilesFromHtmlText(html);
_results = [];
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
_results.push((function() {
var _j, _len1, _ref, _results1;
_ref = file.querySelectorAll('.line');
_results1 = [];
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
line = _ref[_j];
lineNumber = parseInt(line.id.substr(2));
lineContents = line.innerHTML;
_results1.push(htmlFile.storeLine(line, lineContents, lineNumber));
}
return _results1;
})());
}
return _results;
};
};
DiffProcessor.prototype.fetchParentHtml = function() {
var blobPrefix, file, filePath, parent, _base, _i, _len, _ref, _results;
_ref = this.parentCommitIdentifiers;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
parent = _ref[_i];
blobPrefix = this.buildBlobPrefixFromCommitIdentifier(parent);
(_base = this.parentData)[parent] || (_base[parent] = {});
_results.push((function() {
var _j, _len1, _ref1, _results1;
_ref1 = this.changedFilePaths;
_results1 = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
filePath = _ref1[_j];
this.parentData[parent][filePath] = file = new File(filePath);
_results1.push(this.fetchPageHtml(blobPrefix + urlEncodeFilePath(filePath), this.getStoreHtml(file)));
}
return _results1;
}).call(this));
}
return _results;
};
DiffProcessor.prototype.getFilesFromHtmlText = function(htmlText) {
var asHtml;
asHtml = document.createElement('html');
asHtml.innerHTML = htmlText;
return asHtml.querySelectorAll('.file');
};
DiffProcessor.prototype.getRegularDiffData = function() {
return this.getDiffData(document.querySelectorAll('.file'), this.changedFilePaths);
};
DiffProcessor.prototype.getDiffData = function(changedFileElements, changedFilePaths) {
var diffData, e, file, i, line, lineContainer, lineContents, lineNumberCurrent, lineNumberElements, lineNumberPrevious, lines, path, _i, _j, _len, _len1, _ref, _ref1;
diffData = {};
for (i = _i = 0, _len = changedFilePaths.length; _i < _len; i = ++_i) {
path = changedFilePaths[i];
diffData[path] || (diffData[path] = []);
file = new File(path);
diffData[path].push(file);
lines = (_ref = changedFileElements[i]) != null ? _ref.querySelectorAll('.file-diff-line') : void 0;
if (lines != null) {
for (_j = 0, _len1 = lines.length; _j < _len1; _j++) {
line = lines[_j];
lineNumberElements = line.querySelectorAll('.diff-line-num');
_ref1 = (function() {
var _k, _len2, _results;
_results = [];
for (_k = 0, _len2 = lineNumberElements.length; _k < _len2; _k++) {
e = lineNumberElements[_k];
_results.push(parseInt(e.getAttribute('data-line-number')));
}
return _results;
})(), lineNumberPrevious = _ref1[0], lineNumberCurrent = _ref1[1];
lineNumberCurrent || (lineNumberCurrent = parseInt(line.getAttribute('data-line')));
lineContainer = line.querySelector('.diff-line-code');
if (lineContainer) {
lineContents = lineContainer.innerText;
file.storeDiffLine(lineContainer, lineContents, lineNumberPrevious, lineNumberCurrent);
}
}
}
}
return diffData;
};
DiffProcessor.prototype.fetchAndHighlight = function() {
this.fetchCurrentHtml();
return this.fetchParentHtml();
};
DiffProcessor.prototype.refreshDataAndHighlight = function(mutations) {
var changed;
changed = this.updateCurrentRepoPath();
changed || (changed = this.updateChangedFilePaths());
changed || (changed = this.updateCommitIdentifiers());
if (changed) {
this.mutationObserver.disconnect();
window.diffProcessor.constructor();
window.diffProcessor.fetchAndHighlight();
return;
}
this.diffData = this.getRegularDiffData();
return this.highlight();
};
return DiffProcessor;
})();
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '.highlight span.x {\n color: inherit !important;\n}';
document.getElementsByTagName('head')[0].appendChild(style);
window.diffProcessor = new DiffProcessor();
window.diffProcessor.fetchAndHighlight();
}).call(this);
/*
//@ sourceMappingURL=diff-highlighter.map
*/