-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 1.1 KB
/
index.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
39
40
var user = document.getElementById("user");
var repo = document.getElementById("repo");
var branch = document.getElementById("branch");
var from = document.getElementById("from");
var to = document.getElementById("to");
var link = document.getElementById("link");
function addListener(...objects) {
for(const object of objects) {
object.addEventListener('input', updateUrl);
object.addEventListener('propertychange', updateUrl); // for IE8
}
}
function getUrl(user, repo, branch, from, to) {
return "https://github.com/" + user + "/" + repo + "/commits/" + branch + "?since=" + from + "&until=" + to;
}
function anyEmpty(...strings) {
for(const str of strings) {
if (str == null || str === "")
return true;
}
return false;
}
function updateUrl() {
if (anyEmpty(user.value, repo.value, branch.value, from.value, to.value)) {
link.removeAttribute("href");
link.innerHTML = "Please, fill in all the fields.";
return;
}
let url = getUrl(user.value, repo.value, branch.value, from.value, to.value);
link.setAttribute("href", url);
link.innerHTML = url;
}
addListener(user, repo, branch, from, to);