-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblame.js
35 lines (28 loc) · 1.19 KB
/
blame.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
let container;
function set_dom(html) {
const div = document.createElement("DIV");
div.style.display = "none";
div.id = "blameHTML";
document.querySelector("body").appendChild(div);
document.querySelector("#blameHTML").innerHTML = html;
blames = div.getElementsByClassName("blame-container");
if (blames.length == 1) {
container = blames[0];
} else {
console.error("Multiple 'blame-container's");
}
}
function getBlameDetails(line_id) {
let super_parent = container.querySelector("#"+line_id).parentNode.parentNode.parentNode;
blame_commit = super_parent.querySelector(".blame-commit");
avatar = blame_commit.querySelector(".avatar");
user_link = "https://github.com" + avatar.getAttribute("href");
avatar_src = avatar.querySelector("img").getAttribute("src");
content = blame_commit.querySelector(".message");
commit_msg = content.innerText;
commit_link = "https://github.com" + content.getAttribute("href");
time = blame_commit.querySelector("time-ago").innerText;
name = user_link.replace("https://github.com/", "");
let data = { avatar_src, user_link, commit_msg, commit_link, time, name }
return data
}