Skip to content

Instantly share code, notes, and snippets.

@bgmort
Last active December 21, 2015 15:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgmort/6324127 to your computer and use it in GitHub Desktop.
Save bgmort/6324127 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
(function($){
var matches = location.pathname.match(/browse\/([A-Z]+-[0-9]+)/);
if (matches) {
$(document).ready(function() {
/*
* Add diffs to change logs
*/
var script = document.createElement('script');
script.src = 'https://google-diff-match-patch.googlecode.com/svn/trunk/javascript/diff_match_patch.js';
var para = /&para;/g, description = /\s*Description\s*/, brs = /<br><br>/g;
script.onload = function() {
var dmp = new diff_match_patch;
dmp.Diff_Timeout = 1;
dmp.Diff_EditCost = 6;
$('.changehistory').each(function(){
var row = $(this);
if (!description.test(row.find('.activity-name').text())) return;
var oldContainer = row.find('.activity-old-val'),
newContainer = row.find('.activity-new-val'),
oldVal = oldContainer.text(),
newVal = newContainer.text();
//create diff
var diff = dmp.diff_main(oldVal, newVal);
dmp.diff_cleanupEfficiency(diff);
var diffHtml = dmp.diff_prettyHtml(diff).replace(para, '').replace(brs, '<br>');
newContainer.html(diffHtml);
});
};
document.documentElement.appendChild(script);
});
}
})(jQuery);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment