Browse Source

Merge pull request #93 from sindresorhus/collapse-all-buttons-remove

Remove minimise/maximise all buttons
master
Sindre Sorhus 9 years ago
parent
commit
1b1e6145b0
  1. 5
      extension/content.css
  2. 56
      extension/content.js

5
extension/content.css

@ -186,10 +186,7 @@
opacity: 1; opacity: 1;
} }
/* style for minimize/maximize button group */ /* indicate collapsible file headers with zoom cursor */
.btn-group.refined-github-btn-group {
margin-right: 25px;
}
.file-header[data-path], .file-header[data-path] .diffstat { .file-header[data-path], .file-header[data-path] .diffstat {
cursor: zoom-out !important; cursor: zoom-out !important;
} }

56
extension/content.js

@ -6,7 +6,6 @@ const repoName = path.split('/')[2];
const isDashboard = () => location.pathname === '/' || /(^\/(dashboard))/.test(location.pathname) || /(^\/(orgs)\/)(\w|-)+\/(dashboard)/.test(location.pathname); const isDashboard = () => location.pathname === '/' || /(^\/(dashboard))/.test(location.pathname) || /(^\/(orgs)\/)(\w|-)+\/(dashboard)/.test(location.pathname);
const isRepo = () => /^\/[^/]+\/[^/]+/.test(location.pathname); const isRepo = () => /^\/[^/]+\/[^/]+/.test(location.pathname);
const isRepoRoot = () => location.pathname.replace(/\/$/, '') === `/${ownerName}/${repoName}` || /(\/tree\/)(\w|\d|\.)+(\/$|$)/.test(location.href); const isRepoRoot = () => location.pathname.replace(/\/$/, '') === `/${ownerName}/${repoName}` || /(\/tree\/)(\w|\d|\.)+(\/$|$)/.test(location.href);
const isCompare = () => /^\/[^/]+\/[^/]+\/compare/.test(location.pathname);
const isPR = () => /^\/[^/]+\/[^/]+\/pull\/\d+/.test(location.pathname) || /^\/[^/]+\/[^/]+\/pull\/\d+\/commits\/[0-9a-f]{5,40}/.test(location.pathname); const isPR = () => /^\/[^/]+\/[^/]+\/pull\/\d+/.test(location.pathname) || /^\/[^/]+\/[^/]+\/pull\/\d+\/commits\/[0-9a-f]{5,40}/.test(location.pathname);
const isCommit = () => /^\/[^/]+\/[^/]+\/commit\/[0-9a-f]{5,40}/.test(location.pathname) || /^\/[^/]+\/[^/]+\/pull\/\d+\/commits\/[0-9a-f]{5,40}/.test(location.pathname); const isCommit = () => /^\/[^/]+\/[^/]+\/commit\/[0-9a-f]{5,40}/.test(location.pathname) || /^\/[^/]+\/[^/]+\/pull\/\d+\/commits\/[0-9a-f]{5,40}/.test(location.pathname);
const isIssue = () => /^\/[^/]+\/[^/]+\/issues\/\d+$/.test(location.pathname); const isIssue = () => /^\/[^/]+\/[^/]+\/issues\/\d+$/.test(location.pathname);
@ -33,41 +32,6 @@ function linkifyBranchRefs() {
}); });
} }
function addMinimizeMaximize() {
if ($('#toc .refined-github-btn-group').length) {
return;
}
const buttonGroup = $('<div>').addClass('btn-group right refined-github-btn-group');
const buttonHideAll = $('<a>').addClass('btn btn-sm').text('Minimize All').attr('id', 'hide_all');
const buttonShowAll = $('<a>').addClass('btn btn-sm').text('Maximize All').attr('id', 'show_all');
buttonHideAll.on('click', e => {
e.preventDefault();
e.stopPropagation();
$('.file-header').parent().addClass('refined-github-minimized');
});
buttonShowAll.on('click', e => {
e.preventDefault();
e.stopPropagation();
$('.file-header').parent().removeClass('refined-github-minimized');
});
buttonGroup
.append(buttonHideAll)
.append(buttonShowAll)
.insertAfter('#toc .btn-group');
$('.file-header .file-actions').on('click', e => {
e.stopPropagation();
});
$('.file-header').on('click', e => {
$(e.target).closest('.js-details-container').toggleClass('refined-github-minimized');
});
}
function commentIsUseless(type, el) { function commentIsUseless(type, el) {
if (uselessContent[type].text.includes(el.innerText)) { if (uselessContent[type].text.includes(el.innerText)) {
return true; return true;
@ -284,12 +248,13 @@ function addPatchDiffLinks() {
// Prompt user to confirm erasing a comment with the Cancel button // Prompt user to confirm erasing a comment with the Cancel button
$(document).on('click', event => { $(document).on('click', event => {
// Check event.target instead of using a delegate, because Sprint doesn't support them // Check event.target instead of using a delegate, because Sprint doesn't support them
if (!event.target.classList.contains('js-hide-inline-comment-form')) { const $target = $(event.target);
if (!$target.hasClass('js-hide-inline-comment-form')) {
return; return;
} }
// Do not prompt if textarea is empty // Do not prompt if textarea is empty
const text = $(event.target).closest('.js-inline-comment-form').find('.js-comment-field').val(); const text = $target.closest('.js-inline-comment-form').find('.js-comment-field').val();
if (text.length === 0) { if (text.length === 0) {
return; return;
} }
@ -300,6 +265,17 @@ $(document).on('click', event => {
} }
}); });
// Collapse file diffs when clicking the file header
$(document).on('click', event => {
// Check event.target instead of using a delegate, because Sprint doesn't support them
const $target = $(event.target);
if (!($target.closest('.file-header').length > 0 && $target.closest('.file-actions').length === 0)) {
return;
}
$target.closest('.js-details-container').toggleClass('refined-github-minimized');
});
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const username = getUsername(); const username = getUsername();
@ -335,10 +311,6 @@ document.addEventListener('DOMContentLoaded', () => {
linkifyIssuesInTitles(); linkifyIssuesInTitles();
} }
if (isPR() || isCommit() || isCompare()) {
addMinimizeMaximize();
}
if (isBlame()) { if (isBlame()) {
addBlameParentLinks(); addBlameParentLinks();
} }

Loading…
Cancel
Save