This repository has been archived by the owner on Sep 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 340
/
rustup.js
153 lines (132 loc) · 4.96 KB
/
rustup.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
var platform_override = null;
function detect_platform() {
"use strict";
if (platform_override) {
return platform_override;
}
var os = "unknown";
if (navigator.platform == "Linux x86_64") {os = "unix";}
if (navigator.platform == "Linux i686") {os = "unix";}
if (navigator.platform == "Linux i686 on x86_64") {os = "unix";}
if (navigator.platform == "Linux aarch64") {os = "unix";}
if (navigator.platform == "Linux armv6l") {os = "unix";}
if (navigator.platform == "Linux armv7l") {os = "unix";}
if (navigator.platform == "Linux armv8l") {os = "unix";}
if (navigator.platform == "Linux ppc64") {os = "unix";}
if (navigator.platform == "Linux mips") {os = "unix";}
if (navigator.platform == "Linux mips64") {os = "unix";}
if (navigator.platform == "Mac") {os = "unix";}
if (navigator.platform == "Win32") {os = "win";}
if (navigator.platform == "FreeBSD x86_64") {os = "unix";}
if (navigator.platform == "FreeBSD amd64") {os = "unix";}
if (navigator.platform == "NetBSD x86_64") {os = "unix";}
if (navigator.platform == "NetBSD amd64") {os = "unix";}
// I wish I knew by now, but I don't. Try harder.
if (os == "unknown") {
if (navigator.appVersion.indexOf("Win")!=-1) {os = "win";}
if (navigator.appVersion.indexOf("Mac")!=-1) {os = "unix";}
// rust-www/#692 - FreeBSD epiphany!
if (navigator.appVersion.indexOf("FreeBSD")!=-1) {os = "unix";}
}
// Firefox Quantum likes to hide platform and appVersion but oscpu works
if (navigator.oscpu) {
if (navigator.oscpu.indexOf("Windows")!=-1) {os = "win";}
if (navigator.oscpu.indexOf("Mac")!=-1) {os = "unix";}
if (navigator.oscpu.indexOf("Linux")!=-1) {os = "unix";}
if (navigator.oscpu.indexOf("FreeBSD")!=-1) {os = "unix";}
if (navigator.oscpu.indexOf("NetBSD")!=-1) {os = "unix";}
}
return os;
}
function adjust_for_platform() {
"use strict";
var platform = detect_platform();
var unix_div = document.getElementById("platform-instructions-unix");
var win_div = document.getElementById("platform-instructions-win");
var unknown_div = document.getElementById("platform-instructions-unknown");
var default_div = document.getElementById("platform-instructions-default");
unix_div.style.display = "none";
win_div.style.display = "none";
unknown_div.style.display = "none";
default_div.style.display = "none";
if (platform == "unix") {
unix_div.style.display = "block";
} else if (platform == "win") {
win_div.style.display = "block";
} else if (platform == "unknown") {
unknown_div.style.display = "block";
} else {
default_div.style.display = "block";
}
var platform_specific = document.getElementsByClassName("platform-specific");
for (var el of platform_specific) {
var el_is_not_win = el.className.indexOf("not-win") !== -1;
var el_is_inline = el.tagName.toLowerCase() == "span";
var el_visible_style = "block";
if (el_is_inline) {
el_visible_style = "inline";
}
if (platform == "win") {
if (el_is_not_win) {
el.style.display = "none";
} else {
el.style.display = el_visible_style;
}
} else {
if (el_is_not_win) {
el.style.display = el_visible_style;
} else {
el.style.display = "none";
}
}
}
}
function cycle_platform() {
if (platform_override == null) {
platform_override = "default";
} else if (platform_override == "default") {
platform_override = "unknown";
} else if (platform_override == "unknown") {
platform_override = "win";
} else if (platform_override == "win") {
platform_override = "unix";
} else if (platform_override == "unix") {
platform_override = "default";
}
adjust_for_platform();
}
function set_up_cycle_button() {
var cycle_button = document.getElementById("platform-button");
cycle_button.onclick = cycle_platform;
var key="test";
var idx=0;
var unlocked=false;
document.onkeypress = function(event) {
if (event.key == "n" && unlocked) {
cycle_platform();
}
if (event.key == key[idx]) {
idx += 1;
if (idx == key.length) {
cycle_button.style.display = "block";
unlocked = true;
cycle_platform();
}
} else if (event.key == key[0]) {
idx = 1;
} else {
idx = 0;
}
};
}
function fill_in_bug_report_values() {
var nav_plat = document.getElementById("nav-plat");
var nav_app = document.getElementById("nav-app");
nav_plat.textContent = navigator.platform;
nav_app.textContent = navigator.appVersion;
}
(function () {
adjust_for_platform();
set_up_cycle_button();
fill_in_bug_report_values();
}());