mirror of
https://github.com/yuukiwww/taiko-web.git
synced 2024-06-27 14:59:30 +02:00
- Add a "Browse..." button to the plugin menu - Remove the "Unload All" button from the plugin menu if there are no imported plugins to unload - Add a new search filter: random:yes - Resolution settings now affects the results screen assets - Pixelate more assets with lowest resolution setting - Fix loading error message not appearing sometimes - Remove img.css from img assets, the background selectors have been moved to assets.js - Separate the search logic from SongSelect to its own js file - Load all image assets with crossorigin=anonymous, this could allow making assets low resolution or programatically taking screenshots at a later time - If EditFunction in a plugin tries to edit something that is not a function, it will give a better error message - Disallow search engine bots from indexing images and adding a translate link, which cannot load the game
152 lines
3.0 KiB
JavaScript
152 lines
3.0 KiB
JavaScript
function readFile(file, arrayBuffer, encoding){
|
|
var reader = new FileReader()
|
|
var promise = pageEvents.load(reader).then(event => event.target.result)
|
|
reader[arrayBuffer ? "readAsArrayBuffer" : "readAsText"](file, encoding)
|
|
return promise
|
|
}
|
|
function filePermission(file){
|
|
return file.queryPermission().then(response => {
|
|
if(response === "granted"){
|
|
return file
|
|
}else{
|
|
return file.requestPermission().then(response => {
|
|
if(response === "granted"){
|
|
return file
|
|
}else{
|
|
return Promise.reject(strings.accessNotGrantedError)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
class RemoteFile{
|
|
constructor(...args){
|
|
this.init(...args)
|
|
}
|
|
init(url){
|
|
this.url = url
|
|
try{
|
|
this.path = new URL(url).pathname
|
|
}catch(e){
|
|
this.path = url
|
|
}
|
|
if(this.path.startsWith("/")){
|
|
this.path = this.path.slice(1)
|
|
}
|
|
if(this.url.startsWith("data:")){
|
|
this.name = "datauri"
|
|
if(this.url.startsWith("data:audio/ogg")){
|
|
this.name += ".ogg"
|
|
}
|
|
}else{
|
|
this.name = this.path
|
|
var index = this.name.lastIndexOf("/")
|
|
if(index !== -1){
|
|
this.name = this.name.slice(index + 1)
|
|
}
|
|
}
|
|
}
|
|
arrayBuffer(){
|
|
return loader.ajax(this.url, request => {
|
|
request.responseType = "arraybuffer"
|
|
})
|
|
}
|
|
read(encoding){
|
|
if(encoding){
|
|
return this.blob().then(blob => readFile(blob, false, encoding))
|
|
}else{
|
|
return loader.ajax(this.url)
|
|
}
|
|
}
|
|
blob(){
|
|
return loader.ajax(this.url, request => {
|
|
request.responseType = "blob"
|
|
})
|
|
}
|
|
}
|
|
class LocalFile{
|
|
constructor(...args){
|
|
this.init(...args)
|
|
}
|
|
init(file, path){
|
|
this.file = file
|
|
this.path = path || file.webkitRelativePath
|
|
this.url = this.path
|
|
this.name = file.name
|
|
}
|
|
arrayBuffer(){
|
|
return readFile(this.file, true)
|
|
}
|
|
read(encoding){
|
|
return readFile(this.file, false, encoding)
|
|
}
|
|
blob(){
|
|
return Promise.resolve(this.file)
|
|
}
|
|
}
|
|
class FilesystemFile{
|
|
constructor(...args){
|
|
this.init(...args)
|
|
}
|
|
init(file, path){
|
|
this.file = file
|
|
this.path = path
|
|
this.url = this.path
|
|
this.name = file.name
|
|
}
|
|
arrayBuffer(){
|
|
return this.blob().then(blob => blob.arrayBuffer())
|
|
}
|
|
read(encoding){
|
|
return this.blob().then(blob => readFile(blob, false, encoding))
|
|
}
|
|
blob(){
|
|
return filePermission(this.file).then(file => file.getFile())
|
|
}
|
|
}
|
|
class GdriveFile{
|
|
constructor(...args){
|
|
this.init(...args)
|
|
}
|
|
init(fileObj){
|
|
this.path = fileObj.path
|
|
this.name = fileObj.name
|
|
this.id = fileObj.id
|
|
this.url = gpicker.filesUrl + this.id + "?alt=media"
|
|
}
|
|
arrayBuffer(){
|
|
return gpicker.downloadFile(this.id, "arraybuffer")
|
|
}
|
|
read(encoding){
|
|
if(encoding){
|
|
return this.blob().then(blob => readFile(blob, false, encoding))
|
|
}else{
|
|
return gpicker.downloadFile(this.id)
|
|
}
|
|
}
|
|
blob(){
|
|
return gpicker.downloadFile(this.id, "blob")
|
|
}
|
|
}
|
|
class CachedFile{
|
|
constructor(...args){
|
|
this.init(...args)
|
|
}
|
|
init(contents, oldFile){
|
|
this.contents = contents
|
|
this.oldFile = oldFile
|
|
this.path = oldFile.path
|
|
this.name = oldFile.name
|
|
this.url = oldFile.url
|
|
}
|
|
arrayBuffer(){
|
|
return Promise.resolve(this.contents)
|
|
}
|
|
read(encoding){
|
|
return this.arrayBuffer()
|
|
}
|
|
blob(){
|
|
return this.arrayBuffer()
|
|
}
|
|
}
|