|
| 1 | +var platform_override = null; |
| 2 | + |
| 3 | +function detect_platform() { |
| 4 | + "use strict"; |
| 5 | + |
| 6 | + if (platform_override) { |
| 7 | + return platform_override; |
| 8 | + } |
| 9 | + |
| 10 | + var os = "unknown"; |
| 11 | + |
| 12 | + if (navigator.platform == "Linux x86_64") {os = "unix";} |
| 13 | + if (navigator.platform == "Linux i686") {os = "unix";} |
| 14 | + if (navigator.platform == "Linux i686 on x86_64") {os = "unix";} |
| 15 | + if (navigator.platform == "Linux aarch64") {os = "unix";} |
| 16 | + if (navigator.platform == "Linux armv6l") {os = "unix";} |
| 17 | + if (navigator.platform == "Linux armv7l") {os = "unix";} |
| 18 | + if (navigator.platform == "Mac") {os = "unix";} |
| 19 | + if (navigator.platform == "Win32") {os = "win";} |
| 20 | + if (navigator.platform == "FreeBSD x86_64") {os = "unix";} |
| 21 | + if (navigator.platform == "FreeBSD amd64") {os = "unix";} |
| 22 | + |
| 23 | + if (navigator.platform == "Linux armv7l" |
| 24 | + && navigator.appVersion.indexOf("Android") != -1 ) { |
| 25 | + os = "android"; |
| 26 | + } |
| 27 | + |
| 28 | + // I wish I knew by now, but I don't. Try harder. |
| 29 | + if (os == "unknown") { |
| 30 | + if (navigator.appVersion.indexOf("Win")!=-1) {os = "win";} |
| 31 | + if (navigator.appVersion.indexOf("Mac")!=-1) {os = "unix";} |
| 32 | + } |
| 33 | + |
| 34 | + return os; |
| 35 | +} |
| 36 | + |
| 37 | +function adjust_for_platform() { |
| 38 | + "use strict"; |
| 39 | + |
| 40 | + var platform = detect_platform(); |
| 41 | + |
| 42 | + var unix_div = document.getElementById("platform-instructions-unix"); |
| 43 | + var win_div = document.getElementById("platform-instructions-win"); |
| 44 | + var android_div = document.getElementById("platform-instructions-android"); |
| 45 | + var unknown_div = document.getElementById("platform-instructions-unknown"); |
| 46 | + var default_div = document.getElementById("platform-instructions-default"); |
| 47 | + |
| 48 | + unix_div.style.display = "none"; |
| 49 | + win_div.style.display = "none"; |
| 50 | + android_div.style.display = "none"; |
| 51 | + unknown_div.style.display = "none"; |
| 52 | + default_div.style.display = "none"; |
| 53 | + |
| 54 | + if (platform == "unix") { |
| 55 | + unix_div.style.display = "block"; |
| 56 | + } else if (platform == "win") { |
| 57 | + win_div.style.display = "block"; |
| 58 | + } else if (platform == "android") { |
| 59 | + android_div.style.display = "block"; |
| 60 | + } else if (platform == "unknown") { |
| 61 | + unknown_div.style.display = "block"; |
| 62 | + } else { |
| 63 | + default_div.style.display = "block"; |
| 64 | + } |
| 65 | + |
| 66 | + var platform_specific = document.getElementsByClassName("platform-specific"); |
| 67 | + for (var el of platform_specific) { |
| 68 | + var el_is_not_win = el.className.indexOf("not-win") !== -1; |
| 69 | + var el_is_inline = el.tagName.toLowerCase() == "span"; |
| 70 | + var el_visible_style = "block"; |
| 71 | + if (el_is_inline) { |
| 72 | + el_visible_style = "inline"; |
| 73 | + } |
| 74 | + if (platform == "win") { |
| 75 | + if (el_is_not_win) { |
| 76 | + el.style.display = "none"; |
| 77 | + } else { |
| 78 | + el.style.display = el_visible_style; |
| 79 | + } |
| 80 | + } else { |
| 81 | + if (el_is_not_win) { |
| 82 | + el.style.display = el_visible_style; |
| 83 | + } else { |
| 84 | + el.style.display = "none"; |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +function cycle_platform() { |
| 91 | + if (platform_override == null) { |
| 92 | + platform_override = "default"; |
| 93 | + } else if (platform_override == "default") { |
| 94 | + platform_override = "unknown"; |
| 95 | + } else if (platform_override == "unknown") { |
| 96 | + platform_override = "win"; |
| 97 | + } else if (platform_override == "win") { |
| 98 | + platform_override = "unix"; |
| 99 | + } else if (platform_override == "unix") { |
| 100 | + platform_override = "android"; |
| 101 | + } else if (platform_override == "android") { |
| 102 | + platform_override = "default"; |
| 103 | + } |
| 104 | + adjust_for_platform(); |
| 105 | +} |
| 106 | + |
| 107 | +function set_up_cycle_button() { |
| 108 | + var cycle_button = document.getElementById("platform-button"); |
| 109 | + cycle_button.onclick = cycle_platform; |
| 110 | + |
| 111 | + var key="test"; |
| 112 | + var idx=0; |
| 113 | + var unlocked=false; |
| 114 | + |
| 115 | + document.onkeypress = function(event) { |
| 116 | + if (event.key == "n" && unlocked) { |
| 117 | + cycle_platform(); |
| 118 | + } |
| 119 | + |
| 120 | + if (event.key == key[idx]) { |
| 121 | + idx += 1; |
| 122 | + |
| 123 | + if (idx == key.length) { |
| 124 | + cycle_button.style.display = "block"; |
| 125 | + unlocked = true; |
| 126 | + cycle_platform(); |
| 127 | + } |
| 128 | + } else if (event.key == key[0]) { |
| 129 | + idx = 1; |
| 130 | + } else { |
| 131 | + idx = 0; |
| 132 | + } |
| 133 | + }; |
| 134 | +} |
| 135 | + |
| 136 | +function fill_in_bug_report_values() { |
| 137 | + var nav_plat = document.getElementById("nav-plat"); |
| 138 | + var nav_app = document.getElementById("nav-app"); |
| 139 | + nav_plat.textContent = navigator.platform; |
| 140 | + nav_app.textContent = navigator.appVersion; |
| 141 | +} |
| 142 | + |
| 143 | +(function () { |
| 144 | + adjust_for_platform(); |
| 145 | + set_up_cycle_button(); |
| 146 | + fill_in_bug_report_values(); |
| 147 | +}()); |
0 commit comments