Skip to content

Instantly share code, notes, and snippets.

@billthompson
Last active August 29, 2015 13:56
Show Gist options
  • Save billthompson/8870899 to your computer and use it in GitHub Desktop.
Save billthompson/8870899 to your computer and use it in GitHub Desktop.
// Unable to get around Github's content security policy, so made this a bookmark instead.
// javascript:function GithubUserscript(){var s=$(".toc-diff-stats","#toc");s.append('<a href="#" class="minibutton right us-hide-file-diffs" style="margin-right: 10px;">Collapse File Diffs</a>'),s.append('<a href="#" class="minibutton right us-show-file-diffs" style="margin-right: 10px;">Show File Diffs</a>');var e=$(".us-hide-file-diffs"),i=$(".us-show-file-diffs"),t=$(".file.js-details-container");$("#toc").on("click",".us-hide-file-diffs",function(s){s.preventDefault(),$(this).hide(),i.show(),t.find(".data").addClass("suppressed"),t.find(".render-wrapper").addClass("suppressed data")}),$("#toc").on("click",".us-show-file-diffs",function(s){s.preventDefault(),$(this).hide(),e.show(),$(".file.js-details-container").find(".data").removeClass("suppressed"),$(".file.js-details-container").find(".render-wrapper").removeClass("suppressed data")}),$("#files").on("click",".us-toggle-file-diff",function(){var s=$(this).closest(".js-details-container"),e=s.find(".data"),i=s.data("expanded");i=i||0;var t=e.is(".suppressed");t&&(i+=1,$("html, body").animate({scrollTop:s.offset().top},1400)),s.data("expanded",i),e.toggleClass("suppressed"),s.find(".custom-count",".custom-expanded-count-container").text(i)}),t.length>10&&e.click(),t.find(".show-file-notes").append('<i class="octicon octicon-comment-discussion" style="color: #777; margin-left: 10px; "></i>'),t.find(".file-actions").append('<a class="octicon-btn" href="#"><i class="octicon us-toggle-file-diff octicon-code" style="color: #777; cursor: row-resize;"></i></a>'),t.find(".file-actions").append('<span class="custom-expanded-count-container" style="font-size: 11px; color: #777; line-height: 3; float: right; margin-left: 10px; ">Expanded: <span class="custom-count">0</span></span>')}GithubUserscript();
function GithubUserscript() {
var $tocExplain = $('.toc-diff-stats', '#toc');
$tocExplain.append('<a href="#" class="minibutton right us-hide-file-diffs" style="margin-right: 10px;">Collapse File Diffs</a>');
$tocExplain.append('<a href="#" class="minibutton right us-show-file-diffs" style="margin-right: 10px;">Show File Diffs</a>');
var $hideDiffsButton = $('.us-hide-file-diffs');
var $showDiffsButton = $('.us-show-file-diffs');
var $files = $('.file.js-details-container');
$('#toc').on('click', '.us-hide-file-diffs', function(e) {
e.preventDefault();
$(this).hide();
$showDiffsButton.show();
$files.find('.data').addClass('suppressed');
$files.find('.render-wrapper').addClass('suppressed data');
});
$('#toc').on('click', '.us-show-file-diffs', function(e) {
e.preventDefault();
$(this).hide();
$hideDiffsButton.show();
$('.file.js-details-container').find('.data').removeClass('suppressed');
$('.file.js-details-container').find('.render-wrapper').removeClass('suppressed data');
});
$('#files').on('click', '.us-toggle-file-diff', function(e) {
//js-details-container
var $diffContainer = $(this).closest('.js-details-container');
var $diffData = $diffContainer.find('.data');
var expandedCount = $diffContainer.data('expanded');
expandedCount = expandedCount || 0;
var containerIsSuppressed = $diffData.is('.suppressed');
if(containerIsSuppressed) {
expandedCount += 1;
$('html, body').animate({
scrollTop: $diffContainer.offset().top
}, 1400);
}
$diffContainer.data('expanded', expandedCount);
$diffData.toggleClass('suppressed');
$diffContainer.find('.custom-count', '.custom-expanded-count-container').text(expandedCount);
});
if($files.length > 10) {
$hideDiffsButton.click();
}
$files.find('.show-file-notes').append('<i class="octicon octicon-comment-discussion" style="color: #777; margin-left: 10px; "></i>');
$files.find('.file-actions').append('<a class="octicon-btn" href="#"><i class="octicon us-toggle-file-diff octicon-code" style="color: #777; cursor: row-resize;"></i></a>');
$files.find('.file-actions').append('<span class="custom-expanded-count-container" style="font-size: 11px; color: #777; line-height: 3; float: right; margin-left: 10px; ">Expanded: <span class="custom-count">0</span></span>');
}
GithubUserscript();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment