taiko-web/public/src/js/browsersupport.js

204 lines
5.3 KiB
JavaScript
Raw Normal View History

2018-11-27 00:05:02 +01:00
function browserSupport(){
var tests = {
"Arrow function": function(){
eval("()=>{}")
return true
},
"AudioContext": function(){
2018-12-13 10:18:52 +01:00
if("AudioContext" in window || "webkitAudioContext" in window){
return typeof (window.AudioContext || window.webkitAudioContext) === "function"
}
return false
2018-11-27 00:05:02 +01:00
},
"Class": function(){
eval("class a{}")
return true
},
Lyrics, search, and other fixes - #LYRIC - Parse #LYRIC commands and apply them to all difficulties that do not have them - #LYRIC command now supports branches - Fix last #LYRIC at the end of the chart getting ignored - Fix the glitchy dragging and dropping of files on the custom song importing page - Fix Ctrl and Shift keys getting stuck on song select when switching tabs with Ctrl(+Shift)+Tab - Search - Fix the search box "random:yes" query to randomize the entire results and not just the first 50 - Add "all:yes" query to the search box to remove the result limit and display all of the results - Fix searching for an invalid query (like "cleared:yes" or ":") unexpectedly returning all the songs - Fix pressing Q then jumping to a song through search not unmuting the sound - Pressing the search key on mobile will hide the keyboard - Fix search tips changing rapidly when the window is resized - Use comments instead of `######` in the issue template so that the warning does not appear in the issue - Fix TJA MAKER: url between angle brackets not working - Add a check for Class field declarations in the browser support warning - Fix gpicker getting stuck if a network error occurs - Fix not being able to replace some assets using a "taiko-web assets" folder - Fix selectable song title not being aligned with the game if the game window is too wide - Allow plugin developers to use the "select" type for the settings options - It uses "options" array and "options_lang" object - Fix plugins not getting removed from the plugin list on syntax error - Fix error messages not working if a default plugin is broken - Fix the start of default plugins not stopping the page from loading on error - Fix not being able to scroll the plugins screen on mobile
2022-07-15 16:00:43 +02:00
"Class field declarations": function(){
eval("class a{a=1}")
return true
},
2018-11-27 00:05:02 +01:00
"Array.find": function(){
return "find" in Array.prototype && "findIndex" in Array.prototype
},
"Path2D SVG": function(){
var canvas = document.createElement("canvas")
canvas.width = 1
canvas.height = 1
var ctx = canvas.getContext("2d")
var path = new Path2D("M0 0H1V1H0")
ctx.fill(path)
return ctx.getImageData(0, 0, 1, 1).data[3] !== 0
},
"Promise": function(){
if("Promise" in window && "resolve" in window.Promise && "reject" in window.Promise && "all" in window.Promise && "race" in window.Promise){
var resolve
new window.Promise(function(r){resolve = r})
return typeof resolve === "function"
}
2018-11-27 00:43:46 +01:00
return false
2018-11-27 00:05:02 +01:00
},
2018-12-02 16:25:42 +01:00
"CSS calc": function(){
2018-11-27 00:05:02 +01:00
var el = document.createElement("a")
el.style.width = "calc(1px)"
return el.style.length !== 0
2018-12-02 16:25:42 +01:00
},
"let statement": function(){
eval("let a")
return true
},
"CSS custom property": function(){
var el = document.createElement("a")
el.style.setProperty("--a", 1)
return el.style.length !== 0
},
"Font Loading API": function(){
return typeof FontFace === "function"
2020-11-09 15:32:36 +01:00
},
"OGG or WebAssembly": function(){
return new Audio().canPlayType("audio/ogg;codecs=vorbis") || "WebAssembly" in window
},
"KeyboardEvent.key": function(){
return "key" in KeyboardEvent.prototype
},
"Module import": function(){
eval("import('data:text/javascript,')")
return true
2018-11-27 00:05:02 +01:00
}
}
2019-01-26 19:29:13 +01:00
failedTests = []
2018-11-27 00:05:02 +01:00
for(var name in tests){
var result = false
try{
result = tests[name]()
}catch(e){}
if(result === false){
2019-01-26 19:29:13 +01:00
failedTests.push(name)
2018-11-27 00:05:02 +01:00
}
}
if(failedTests.length !== 0){
2019-01-26 19:29:13 +01:00
showUnsupported()
}
}
function showUnsupported(strings){
if(!strings){
var lang
try{
if("localStorage" in window && window.localStorage.lang && window.localStorage.lang in allStrings){
lang = window.localStorage.lang
2018-11-27 00:05:02 +01:00
}
2019-01-26 19:29:13 +01:00
if(!lang && "languages" in navigator){
var userLang = navigator.languages.slice()
userLang.unshift(navigator.language)
for(var i in userLang){
for(var j in allStrings){
if(allStrings[j].regex.test(userLang[i])){
lang = j
}
}
}
2018-11-27 00:05:02 +01:00
}
2019-01-26 19:29:13 +01:00
}catch(e){}
if(!lang){
lang = "en"
2018-11-27 00:05:02 +01:00
}
2019-01-26 19:29:13 +01:00
strings = allStrings[lang]
}
var div = document.getElementById("unsupportedBrowser")
if(div){
div.parentNode.removeChild(div)
}
div = document.createElement("div")
div.id = "unsupportedBrowser"
var warn = document.createElement("div")
warn.id = "unsupportedWarn"
warn.innerText = "!"
warn.textContent = "!"
2019-01-26 19:29:13 +01:00
div.appendChild(warn)
var hide = document.createElement("div")
hide.id = "unsupportedHide"
hide.innerText = "x"
hide.textContent = "x"
2019-01-26 19:29:13 +01:00
div.appendChild(hide)
var span = document.createElement("span")
var browserWarning = strings.browserSupport.browserWarning.split("%s")
for(var i = 0; i < browserWarning.length; i++){
if(i !== 0){
var link = document.createElement("a")
link.innerText = strings.browserSupport.details
link.textContent = strings.browserSupport.details
2019-01-26 19:29:13 +01:00
span.appendChild(link)
}
span.appendChild(document.createTextNode(browserWarning[i]))
}
div.appendChild(span)
var details = document.createElement("div")
details.id = "unsupportedDetails"
details.appendChild(document.createTextNode(strings.browserSupport.failedTests))
var ul = document.createElement("ul")
for(var i = 0; i < failedTests.length; i++){
var li = document.createElement("li")
li.innerText = failedTests[i]
li.textContent = failedTests[i]
2019-01-26 19:29:13 +01:00
ul.appendChild(li)
}
details.appendChild(ul)
var supportedBrowser = strings.browserSupport.supportedBrowser.split("%s")
for(var i = 0; i < supportedBrowser.length; i++){
if(i !== 0){
var chrome = document.createElement("a")
chrome.href = "https://www.google.com/chrome/"
chrome.innerText = "Google Chrome"
chrome.textContent = "Google Chrome"
2019-01-26 19:29:13 +01:00
details.appendChild(chrome)
}
details.appendChild(document.createTextNode(supportedBrowser[i]))
}
div.appendChild(details)
document.body.appendChild(div)
var divClick = function(event){
if(event.type === "touchstart"){
event.preventDefault()
getSelection().removeAllRanges()
2018-11-27 00:05:02 +01:00
}
2019-01-26 19:29:13 +01:00
div.classList.remove("hidden")
}
div.addEventListener("click", divClick)
div.addEventListener("touchstart", divClick)
var toggleDetails = function(event){
if(event.type === "touchstart"){
2018-11-27 00:05:02 +01:00
event.preventDefault()
2019-01-26 19:29:13 +01:00
}
if(details.style.display === "block"){
details.style.display = ""
}else{
details.style.display = "block"
}
}
link.addEventListener("click", toggleDetails)
link.addEventListener("touchstart", toggleDetails)
var hideClick = function(event){
if(event.type === "touchstart"){
event.preventDefault()
}
event.stopPropagation()
div.classList.add("hidden")
}
hide.addEventListener("click", hideClick)
hide.addEventListener("touchstart", hideClick)
chrome.addEventListener("touchend", function(event){
event.preventDefault()
chrome.click()
})
2018-11-27 00:05:02 +01:00
}
2019-01-26 19:29:13 +01:00
var failedTests
2018-11-27 00:05:02 +01:00
browserSupport()