-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
71 lines (71 loc) · 2.13 KB
/
Copy pathutil.js
File metadata and controls
71 lines (71 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var Util = {
LoadScript: (src, callback) => {
let done = false;
let head = document.getElementsByTagName('head')[0];
let script = document.createElement('script');
script.src = src;
head.appendChild(script);
script.onload = script.onreadystatechange = () => {
if (!done && (!script.readyState || script.readyState === "loaded" || script.readyState === "complete")) {
done = true;
callback();
script.onload = script.onreadystatechange = null;
if (head && script.parentNode) {
head.removeChild(script);
}
}
};
},
URLtoObject: () => {
let arg = {};
let pair = location.search.substring(1).split('&');
pair.forEach((V) => {
let kv = V.split('=');
arg[kv[0]] = kv[1];
});
return arg;
},
Polyfill: () => {
window.performance = window.performance || {};
window.performance.now = window.performance.now || (() => new Date().getTime());
(function () {
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
window.requestAnimationFrame = requestAnimationFrame;
})();
},
DateFormat: (date) => {
var y = date.getFullYear();
var m = date.getMonth() + 1;
var d = date.getDate();
var h = date.getHours();
var min = date.getMinutes();
var s = date.getSeconds();
return `${y}/${m}/${d} ${h}:${min}:${s}`;
},
Download: (filename, text) => {
var a = document.createElement('a');
a.href = window.URL.createObjectURL(new Blob([text], {
type: 'text/plain'
}));
a.download = filename;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
},
LoadFile: (callBack) => {
var input = document.createElement("input");
input.type = "file";
input.addEventListener("change", (e) => {
var file = e.target.files[0];
if (!file) return;
var reader = new FileReader();
reader.onload = (e) => callBack(e.target.result);
reader.readAsText(file);
});
document.body.appendChild(input);
input.click();
document.body.removeChild(input);
}
};