Procfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//blob转base64 | |
function blobToDataURI(blob, callback) { | |
let reader = new FileReader(); | |
reader.onload = function(e) { | |
callback(e.target.result); | |
} | |
reader.readAsDataURL(blob); | |
} | |
//base64转blob | |
function dataURItoBlob(dataURI) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//下载文件 | |
// funDownload(JSON.stringify(xxxx),'xxx.json') | |
function funDownload(content, filename) { | |
let eleLink = document.createElement('a'); | |
eleLink.download = filename; | |
eleLink.style.display = 'none'; | |
// 字符内容转变成blob地址 | |
let blob = new Blob([content]); | |
eleLink.href = URL.createObjectURL(blob); | |
// 触发点击 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//提取图片前缀 | |
function findExactlyString(arr) { | |
if (arr.length <= 1) return { | |
leg: 0, | |
str: '', | |
diffArr: arr | |
} | |
let leg = 0 | |
let arr00 = arr[0] | |
for (let i = 0; i < arr00.length; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timeout(ms) { | |
return new Promise((resolve, reject) => { | |
setTimeout(resolve, ms, 'done'); | |
}); | |
} | |
async function f (){ | |
let d = await timeout(100) | |
console.log('100After...') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://developer.mozilla.org/zh-CN/docs/Web/API/Body | |
fetch(`https://xxxxxx`) | |
.then(x=>{ | |
return x.json() | |
//x.text() | |
//x.blob() | |
//x.formData() | |
//x.arrayBuffer() | |
}).then(d=>{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>下载多个文件后打包成ZIP再下载</title> | |
</head> | |
<body> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 获取图片的宽和高 | |
function getImagesWidthHeight(url = "blob | base64 | url") { | |
return new Promise((ret) => { | |
let img = new Image() | |
img.src = url | |
img.onload = function() { | |
ret({ | |
width: this.width, | |
height: this.height, | |
image: this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fileSaveLocal(fileUrl = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/localforage.min.js', | |
name = '未命名', | |
type = 'text/txt') { | |
let blobUrl = null | |
let isHave = localStorage.getItem(name) | |
function getData() { | |
let txtData = localStorage.getItem(name) | |
let u = new Uint8Array(JSON.parse(txtData)) | |
let b = new Blob([u.buffer], { |