-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgetDownloads.js
159 lines (138 loc) · 6.41 KB
/
getDownloads.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
var osType, osName, osVersion, userAgent, appVersion;
var releases = {'src': {'name': 'texworks-release-0.6.9.zip', 'type': 'application/zip', 'size': 12960929, 'url': 'https://github.com/TeXworks/texworks/archive/release-0.6.9.zip', 'timestamp': '2024-02-12T08:36:40Z', 'version': '0.6.9'}, 'linux': {'name': 'TeXworks-0.6.9-x86_64-202402120650-git_68a2e99.AppImage', 'type': 'application/vnd.appimage', 'size': 39400640, 'url': 'https://github.com/TeXworks/texworks/releases/download/release-0.6.9/TeXworks-0.6.9-x86_64-202402120650-git_68a2e99.AppImage', 'timestamp': '2024-02-12T08:36:04Z', 'minOSversion': '0', 'version': '0.6.9'}, 'mac': {'name': 'TeXworks-macos11-0.6.9-202402120642-git_68a2e99.dmg', 'type': 'application/x-apple-diskimage', 'size': 37970025, 'url': 'https://github.com/TeXworks/texworks/releases/download/release-0.6.9/TeXworks-macos11-0.6.9-202402120642-git_68a2e99.dmg', 'timestamp': '2024-02-12T08:35:57Z', 'minOSversion': '11', 'version': '0.6.9'}, 'win': {'name': 'TeXworks-win10-setup-0.6.9-202402120657-git_68a2e99.exe', 'type': 'application/x-ms-dos-executable', 'size': 23907915, 'url': 'https://github.com/TeXworks/texworks/releases/download/release-0.6.9/TeXworks-win10-setup-0.6.9-202402120657-git_68a2e99.exe', 'timestamp': '2024-02-12T08:35:48Z', 'minOSversion': '10', 'version': '0.6.9'}}
userAgent = navigator.userAgent;
appVersion = navigator.appVersion;
///////////////////////////// DEBUG
//appVersion = "Mac";
//userAgent = "Mac OS X 10.8"
//
//appVersion = "Win";
//
//appVersion = "";
//userAgent = "arch";
///////////////////////////// DEBUG
if (appVersion.indexOf("Win") > -1) {
osName = "Windows";
osType = "Windows";
} else if (appVersion.indexOf("Mac") > -1) {
osType = "Mac";
osName = "macOS";
var m = userAgent.match(/Mac\ OS\ X\ (\d+)(?:\.|_)(\d+)/);
if (m && m.length >= 3) {
osVersion = m[1] + "." + m[2];
}
} else {
if (userAgent.toLowerCase().indexOf('ubuntu') > -1) {
osType = "Linux";
osName = "Ubuntu";
} else if (userAgent.toLowerCase().indexOf('opensuse') > -1) {
osType = "Linux";
osName = "openSUSE";
} else if (userAgent.toLowerCase().indexOf('debian') > -1) {
osType = "Linux";
osName = "Debian";
} else if (userAgent.toLowerCase().indexOf('fedora') > -1) {
osType = "Linux";
osName = "Fedora";
} else if (navigator.platform.toLowerCase().indexOf('linux') > -1) {
osType = "Linux";
}
}
///////////////////////////// DEBUG
// osType = "Windows";
// osName = "macOS";
// osVersion = "10.10";
///////////////////////////// DEBUG
function humanReadableFilesize(filesize) {
"use strict";
var prefixes = ['', 'k', 'M', 'G', 'T'], humanReadable = filesize, i;
for (i = 0; i < prefixes.length; i += 1) {
if (humanReadable < 1000) {
break;
}
humanReadable /= 1000;
}
// If we've run out of prefixes, i will have been incremented one additional time
if (i >= prefixes.length) {
i = prefixes.length - 1;
}
return Math.round(10 * humanReadable) / 10 + " " + prefixes[i] + "B";
}
function formatDate(d) {
"use strict";
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
return d.getDate() + ' ' + months[d.getMonth()] + ' ' + d.getFullYear();
}
function makeDownloadLink(release, osName, label) {
"use strict";
var html, m, info;
if (label === undefined) {
label = "Get TeXworks for " + osName;
}
html = '<a href="' + release.url + '" class="link">'; // TODO: safeguard
html += label;
info = [];
info[info.length] = 'version ' + release.version;
// if (release.timestamp) {
// info[info.length] = formatDate(new Date(release.timestamp));
// }
if (release.size > 0) {
info[info.length] = humanReadableFilesize(release.size);
}
if (info.length > 0) {
html += '<div class="info">' + info.join(', ') + '</div>';
}
if (release.minOSversion && release.minOSversion !== '0') {
html += '<div class="info">requires ' + osName + ' ≥ ' + release.minOSversion + '</div>';
}
html += '</a>';
return html;
}
function updateUi() {
"use strict";
var m, html, el;
html = '';
if (osType === "Windows" && releases.win !== undefined) {
html = makeDownloadLink(releases.win, "Windows");
}
if (osType === "Mac" && releases.mac !== undefined) {
html = makeDownloadLink(releases.mac, "macOS");
}
if (osType === "Linux") {
if (osName === 'Ubuntu') {
html = '<a href="https://launchpad.net/~texworks/+archive/stable/" class="link">Get TeXworks for Ubuntu</a>';
}
else if (osName === 'openSUSE') {
html = '<a href="http://software.opensuse.org/search?q=texworks&baseproject=ALL&lang=en&exclude_debug=true" class="link">Get TeXworks for openSUSE</a>';
}
else if (osName === 'Debian') {
html = '<a href="http://packages.debian.org/de/sid/texworks" class="link">Get TeXworks for Debian</a>';
}
else if (osName === 'Fedora') {
html = '<a href="https://admin.fedoraproject.org/pkgdb/package/texworks/" class="link">Get TeXworks for Fedora</a>';
}
else {
html = makeDownloadLink(releases.linux, "Linux", "Get TeXworks AppImage");
}
}
if (html === '' && osType !== "Windows" && osType !== "Mac" && releases.src !== undefined) {
// Fallback: Sources
html = makeDownloadLink(releases.src, "", "Get TeXworks Sources");
}
if (html !== '') {
if (osType === "Windows") {
html += '<div class="other_ways">Alternatively, your TeX distribution may offer a TeXworks package.</div>';
} else if (osType === "Linux") {
html += '<div class="other_ways">Alternatively, your Linux distribution may already offer a TeXworks package.</div>';
}
} else {
// Final fallback: Redirect the user to GitHub
// (should not happen)
html = '<a href="https://github.com/TeXworks/texworks/releases" class="link">Get TeXworks</a>';
}
html += '<div class="other_ways">Not what you are looking for? Check <a href="#Getting_TeXworks">Getting TeXworks</a> for other versions and other ways to obtain TeXworks.</div>';
el = document.getElementById("tw_downloads");
el.innerHTML = html;
el.parentNode.style.display = 'block';
}
updateUi();