-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptInPage.js
More file actions
136 lines (107 loc) · 3.75 KB
/
scriptInPage.js
File metadata and controls
136 lines (107 loc) · 3.75 KB
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
console.log("running in page script")
const disablePrStatus = JSON.parse(localStorage.getItem('disablePrStatus'));
const disableLabels = JSON.parse(localStorage.getItem('disableLabels'));
console.log("disablePrStatus =",disablePrStatus);
console.log("disableLabels =",disableLabels);
let issues;
let issueCounter = -1;
setTimeout(() => {
issues = $('.issue-card');
issues.each((_index, issue) => {
const prInfo=$("<div class='pr-info'></div>");
$(issue).append(prInfo);
});
nextIssue();
nextIssue();
nextIssue();
nextIssue();
nextIssue();
}, 1000);
setTimeout(() => {
setInterval(() => {
processNewIssues();
}, 500)
}, 2000);
function processNewIssues() {
newIssues = $('.issue-card').not(":has(.pr-info)");
newIssues.each((_index, issue) => {
console.log()
const prInfo=$("<div class='pr-info'></div>");
$(issue).append(prInfo);
const issueLink = getIssueLink(issue);
if (issueLink) {
console.log('new issue detected', issueLink);
getPRForIssue(issueLink, issue);
}
});
}
function getPRForIssue(url, issue) {
$.get( url, function( data ) {
const issuePage = $.parseHTML(data);
const allURLs = $(issuePage).find("a").map(function() {
return this.href;
}).get();
const prUrls = allURLs.filter(link => {
return link.includes('/pull/');
});
const firstPR = prUrls[0]
const prInfo = $(issue).find('.pr-info');
$(prInfo).append(getLabels(issuePage));
if (firstPR) {
getTitleForPR(firstPR, prInfo);
} else {
nextIssue();
}
});
}
function getTitleForPR(url, issue) {
$.get( url, function( data ) {
const html = $.parseHTML(data);
const repo = $(html).find('*[data-pjax="#js-repo-pjax-container"]').html();
const title = $(html).find(".js-issue-title").html();
const prContent = $("<div class='pr-info-content'></div>");
$(prContent).append("<div class='pr-link'>"+repo+": <a href='"+url+"'>"+title+"</a></div>");
const statuses = $(html).find(".js-details-container.Details .branch-action-item");
const prStatusContainer = $(`<div class='pr-status-content ${disablePrStatus ? 'disable-pr-status' : ''}'></div>`);
if (statuses) {
statuses.each((_index, status) => {
const statusIcon = $(status).find(".completeness-indicator");
const statusText = $(status).find(".status-heading")[0];
if ($(statusIcon).length && $(statusText).length) {
const statusHTML = $("<div class='details'></div>");
$(statusHTML).append(statusIcon);
$(statusHTML).append(statusText);
$(prStatusContainer).append(statusHTML);
}
});
}
$(prContent).append(prStatusContainer);
$(issue).append(prContent);
nextIssue();
});
}
function nextIssue() {
if (issueCounter < issues.length - 1) {
const issue = issues[++issueCounter];
const issueLink = getIssueLink(issue);
if (issueLink) {
getPRForIssue(issueLink, issue);
} else {
nextIssue();
}
}
}
function getIssueLink(issue) {
const issueLink = $(issue).find("a.h5")
if($(issueLink).length) {
return issueLink[0].href;
} else {
return undefined;
}
}
function getLabels(issuePage) {
const labels = $(issuePage).find('.discussion-sidebar-item:eq(1)');
const labelsContainer = $(`<div class='labels-container ${disableLabels ? 'disable-lables' : ''}'></div>`);
$(labelsContainer).append(labels);
return labelsContainer
}