PluginProbe ʕ •ᴥ•ʔ
Presto Player / trunk
Presto Player vtrunk
4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / src / admin / blocks / util.js
presto-player / src / admin / blocks Last commit date
blocks 1 week ago hooks 9 months ago plugins 9 months ago scripts 9 months ago shared 1 week ago store 2 years ago blocks.js 1 week ago util.js 1 year ago
util.js
117 lines
1 const { useRef, useEffect } = wp.element;
2
3 export function usePrevious(value) {
4 const ref = useRef();
5 useEffect(() => {
6 ref.current = value;
7 });
8 return ref.current;
9 }
10
11 export function snackbarNotice({ status = "success", message }) {
12 wp.data.dispatch("core/notices").createNotice(
13 status, // Can be one of: success, info, warning, error.
14 message, // Text string to display.
15 { type: "snackbar" }
16 );
17 }
18
19 export const bytesToSize = (bytes) => {
20 var sizes = ["Bytes", "KB", "MB", "GB", "TB"];
21 if (bytes == 0) return "0 Byte";
22 var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
23 return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i];
24 };
25
26 export const toDate = (d) => {
27 d = new Date(d);
28 var hours = d.getHours();
29 var minutes = d.getMinutes();
30 var ampm = hours >= 12 ? "pm" : "am";
31 hours = hours % 12;
32 hours = hours ? hours : 12;
33 minutes = minutes < 10 ? "0" + minutes : minutes;
34
35 return (
36 d.getDate() +
37 "-" +
38 (d.getMonth() + 1) +
39 "-" +
40 d.getFullYear() +
41 " at " +
42 hours +
43 ":" +
44 minutes +
45 ampm
46 );
47 };
48
49 export function timeToSeconds(time) {
50 let pieces = time.split(":");
51 let seconds;
52 if (pieces.length > 1) {
53 seconds = parseInt(pieces[0]) * 60;
54 }
55 return parseInt(pieces[1]) + parseInt(seconds);
56 }
57
58 export function secondsToTime(number) {
59 let seconds = parseInt(number, 10);
60 let minutes = Math.floor(seconds / 60);
61 if (seconds < 10) {
62 seconds = "0" + seconds;
63 }
64 return minutes + ":" + seconds;
65 }
66
67 export function sanitizeTime(time) {
68 let draft = time;
69 // remove any letters
70 draft = draft.replace(/[^\d\d:\d\d.-]/g, "");
71 // make sure we have :
72 if (!draft.includes(":")) {
73 return `${draft}:00`;
74 }
75
76 // must have something before :00
77 if (draft.substr(0, draft.indexOf(":")).length === 0) {
78 draft = `0${draft}`;
79 }
80
81 // only allow 2 characters after :
82 let index = draft.indexOf(":");
83 draft = draft.substring(0, index + 3);
84 return draft;
85 }
86
87 export function getProvider(src) {
88 const provider = "self-hosted";
89
90 if (src) {
91 const yt_rx = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=|shorts\/))((\w|-){11})(?:\S+)?$/;
92 const has_match_youtube = src.match(yt_rx);
93
94 if (has_match_youtube) {
95 return "youtube";
96 }
97
98 const vm_rx =
99 /(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([‌​0-9]{6,11})[?]?.*/;
100 const has_match_vimeo = src.match(vm_rx);
101
102 if (has_match_vimeo) {
103 return "vimeo";
104 }
105
106 if (src.indexOf("https://vz-") > -1 && src.indexOf("b-cdn.net") > -1) {
107 return "bunny";
108 }
109
110 if (src.indexOf(".mp3") > -1) {
111 return "audio";
112 }
113 }
114 return provider;
115 }
116
117