feat: close #887 import masks

This commit is contained in:
Yidadaa
2023-05-04 22:33:13 +08:00
parent 40223e6b3f
commit 596c9b1d27
2 changed files with 41 additions and 3 deletions

View File

@@ -42,6 +42,26 @@ export function downloadAs(text: string, filename: string) {
document.body.removeChild(element);
}
export function readFromFile() {
return new Promise<string>((res, rej) => {
const fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.accept = "application/json";
fileInput.onchange = (event: any) => {
const file = event.target.files[0];
const fileReader = new FileReader();
fileReader.onload = (e: any) => {
res(e.target.result);
};
fileReader.onerror = (e) => rej(e);
fileReader.readAsText(file);
};
fileInput.click();
});
}
export function isIOS() {
const userAgent = navigator.userAgent.toLowerCase();
return /iphone|ipad|ipod/.test(userAgent);