Skip to content

Commit c97eb59

Browse files
committed
stacks
1 parent 6f1607c commit c97eb59

2 files changed

Lines changed: 68 additions & 23 deletions

File tree

.idea/workspace.xml

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GitHub_Commit_Compare/GitHub_Commit_Compare.user.js

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,8 @@
4343
checkboxEnable.type = 'checkbox';
4444
checkboxEnable.addEventListener('change',
4545
function () {
46-
const compareRadioGroup = document.querySelectorAll('.GitHubCommitCompareButtonAB');
47-
if (this.checked) {
48-
// add or show radios
49-
if (compareRadioGroup.length === 0) {
50-
addCompareRadios();
51-
} else {
52-
$('.GitHubCommitCompareToggle').show();
53-
}
54-
} else {
55-
// hide radios
56-
$('.GitHubCommitCompareToggle').hide();
57-
}
58-
const compareButton = document.getElementById('GitHubCommitCompareButton');
59-
if (compareButton) compareButton.classList.remove('disabled');
60-
});
46+
toggleVisibility(this.checked);
47+
});
6148

6249
const label = document.createElement('label');
6350
label.classList.add('tooltipped', 'tooltipped-n');
@@ -117,6 +104,24 @@
117104
}
118105
}
119106

107+
function toggleVisibility(visible) {
108+
if (visible) {
109+
const compareRadioGroup = document.querySelectorAll('.GitHubCommitCompareButtonAB');
110+
// add or show things
111+
if (compareRadioGroup.length === 0) {
112+
addCompareRadios();
113+
addStackLinks();
114+
} else {
115+
$('.GitHubCommitCompareToggle').show();
116+
}
117+
} else {
118+
// hide things
119+
$('.GitHubCommitCompareToggle').hide();
120+
}
121+
const compareButton = document.getElementById('GitHubCommitCompareButton');
122+
if (compareButton) compareButton.classList.remove('disabled');
123+
}
124+
120125
function updateRadioButtons() {
121126
let compareAdisabled = true;
122127
let compareBdisabled = false;
@@ -143,21 +148,60 @@
143148
updateCompareButton();
144149
}
145150

146-
function updateCompareButton() {
151+
function rangeHref(hashBase, hashHead) {
147152
const repo = document.querySelector('meta[property="og:url"]').content;
153+
return `${repo}/files/` + (hashBase ? `${hashBase}..` : '') + hashHead;
154+
}
148155

156+
function updateCompareButton() {
149157
const compareA = document.querySelector('.GitHubCommitCompareButtonAB [name="GitHubCommitCompareButtonA"]:checked');
150158
const hashA = compareA.parentNode.parentNode.parentNode.querySelector('clipboard-copy').value;
151159
const compareB = document.querySelector('.GitHubCommitCompareButtonAB [name="GitHubCommitCompareButtonB"]:checked');
152160
const clipboardCopyB = compareB.parentNode.parentNode.parentNode.querySelector('clipboard-copy');
153161
const hashB = clipboardCopyB == null ? null : clipboardCopyB.value;
154162

155163
const a = document.getElementById('GitHubCommitCompareButton');
156-
const href = `${repo}/files/` + (hashB ? `${hashB}..` : '') + hashA;
164+
const href = rangeHref(hashB, hashA);
157165
a.setAttribute('href', href);
158166
a.querySelector('span').textContent = `${hashB ? hashB.substring(0, 7) : 'base'}..${hashA.substring(0, 7)}`;
159167
}
160168

169+
function addStackLinks() {
170+
const commits = [];
171+
$('#commits_bucket .commits-list-item .commit-title>a').each((index, commitTitleA) => {
172+
const title = $(commitTitleA).text();
173+
174+
const stackMatch = /^(\d+):.*$/.exec(title);
175+
const stackId = stackMatch ? stackMatch[1] : null;
176+
177+
const hrefSplit = $(commitTitleA).prop("href").split("/");
178+
const sha = hrefSplit[hrefSplit.length - 1];
179+
180+
commits.push({
181+
title: title,
182+
sha: sha,
183+
stackId: stackId,
184+
titleA: commitTitleA
185+
});
186+
});
187+
188+
let hashBase = null;
189+
let stackTitleA = commits[0].titleA;
190+
for (let i =0; i<commits.length; i++) {
191+
const commit = commits[i];
192+
if (i === commits.length - 1 || commits[i+1].stackId) {
193+
const href = rangeHref(hashBase, commit.sha);
194+
$(stackTitleA).after(`<a class="GitHubCommitCompareToggle" href="${href}"> (stack)</a>`);
195+
console.log($(stackTitleA).text());
196+
console.log(href);
197+
hashBase = commit.sha;
198+
if (i<commits.length -1) {
199+
stackTitleA = commits[i+1].titleA;
200+
}
201+
}
202+
}
203+
}
204+
161205
function addCompareRadios() {
162206
$('#commits_bucket .commits-listing').prepend(
163207
`<ol class="commit-group table-list table-list-bordered GitHubCommitCompareToggle">

0 commit comments

Comments
 (0)