-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.js
More file actions
105 lines (86 loc) · 3.21 KB
/
update.js
File metadata and controls
105 lines (86 loc) · 3.21 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
function build_table(data, filter) {
let old_font_list = document.getElementById("font_list");
let new_font_list = document.createElement("tbody");
new_font_list.id = "font_list";
for (let i = 0; i < data.familyVersions.length; i++) {
let family = data.familyVersions[i];
if (!family.upstreamCommit &&
(!family.fontVersions.length || !family.fontVersions[0].version)) {
continue;
}
if (filter && family.name.indexOf(filter) == -1) {
continue;
}
let row = document.createElement("tr");
let name = document.createElement("td");
let version = document.createElement("td");
let commit = document.createElement("td");
name.innerText = family.name;
if (family.upstreamCommit) {
let link = document.createElement("a");
link.href = "https://github.com/google/fonts/commit/" + family.upstreamCommit;
link.innerText = family.upstreamCommit;
commit.appendChild(link);
} else {
commit.innerText = "N/A";
}
if (family.fontVersions.length > 0) {
version.innerText = family.fontVersions[0].version;
} else {
version.innerText = "N/A";
}
row.appendChild(name);
row.appendChild(version);
row.appendChild(commit);
new_font_list.appendChild(row);
}
old_font_list.parentNode.replaceChild(new_font_list, old_font_list);
}
async function update_table(sandbox, filter=null) {
url = sandbox ? "https://fonts.sandbox.google.com/metadata/versions" : "https://fonts.google.com/metadata/versions";
let active = document.getElementById(sandbox ? "sandbox" : "prod");
let inactive = document.getElementById(!sandbox ? "sandbox" : "prod");
active.classList.add("active")
inactive.classList.remove("active");
let text_promise = fetch(url).then(response => response.text());
text_promise.then(async (text) => {
build_table(JSON.parse(text.substring(4)), filter);
}).catch(e => {
console.log("Failed to load the version metadata: ", e);
let old_font_list = document.getElementById("font_list");
let new_font_list = document.createElement("tbody");
new_font_list.id = "font_list";
let row = document.createElement("tr");
let cell = document.createElement("td");
cell.innerText = "Failed to load the version metadata.";
row.appendChild(cell);
new_font_list.appendChild(row);
old_font_list.parentNode.replaceChild(new_font_list, old_font_list);
});
}
let filter = "";
let show_sandbox = true;
window.addEventListener('DOMContentLoaded', function() {
update_table(show_sandbox);
let sandbox = document.getElementById("sandbox");
sandbox.addEventListener("click", function() {
show_sandbox = true;
update_table(show_sandbox, filter);
});
let prod = document.getElementById("prod");
prod.addEventListener("click", function() {
show_sandbox = false;
update_table(show_sandbox, filter);
});
let filter_box = document.getElementById("filter");
filter_box.addEventListener("change", function() {
filter = filter_box.value;
update_table(show_sandbox, filter);
});
let clear = document.getElementById("clear");
clear.addEventListener("click", function() {
filter = null;
filter_box.value = "";
update_table(show_sandbox, filter);
});
});