-
Notifications
You must be signed in to change notification settings - Fork 0
/
content-script.js
38 lines (30 loc) · 1.27 KB
/
content-script.js
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
let nextUrl;
let prevUrl;
const leftElement = document.createElement("div")
const leftTextNode = document.createTextNode("<");
leftElement.classList.add("next-button")
leftElement.classList.add("left-position")
leftElement.appendChild(leftTextNode);
leftElement.onclick = () => {
window.location = prevUrl.html_url
}
const rightElement = document.createElement("div")
const rightTextNode = document.createTextNode(">");
rightElement.classList.add("next-button")
rightElement.classList.add("right-position")
rightElement.appendChild(rightTextNode);
rightElement.onclick = () => {
window.location = nextUrl.html_url
}
document.body.append(leftElement)
document.body.append(rightElement)
fetch("https://api.github.com/repos/diffgram/diffgram/issues?per_page=100")
.then((response) => response.json())
.then((data) => {
const withPRsRemoved = data.filter(item => !item.html_url.includes('/pull/'))
const currentIssueNumber = window.location.pathname.split('/issues/')[1]
const currentItem = withPRsRemoved.find(item => item.number === parseInt(currentIssueNumber))
const indexOfCurrentIssue = withPRsRemoved.indexOf(currentItem)
nextUrl = withPRsRemoved[indexOfCurrentIssue + 1]
prevUrl = withPRsRemoved[indexOfCurrentIssue - 1]
});