Support browsers without crypto randomUUID
This commit is contained in:
+15
-1
@@ -118,7 +118,21 @@
|
||||
toast.textContent = message; toast.className = `show${error ? ' error' : ''}`;
|
||||
clearTimeout(notify.timer); notify.timer = setTimeout(() => toast.className = '', 4500);
|
||||
};
|
||||
const id = (prefix) => `${prefix}-${crypto.randomUUID()}`;
|
||||
const uuid = () => {
|
||||
if (window.crypto && typeof window.crypto.randomUUID === 'function') return window.crypto.randomUUID();
|
||||
const bytes = new Uint8Array(16);
|
||||
if (window.crypto && typeof window.crypto.getRandomValues === 'function') {
|
||||
window.crypto.getRandomValues(bytes);
|
||||
} else {
|
||||
for (let i=0; i<bytes.length; i++) bytes[i]=Math.floor(Math.random()*256);
|
||||
const time=Date.now();
|
||||
for (let i=0; i<6; i++) bytes[i]^=(time/(2**(i*8)))&255;
|
||||
}
|
||||
bytes[6]=(bytes[6]&15)|64; bytes[8]=(bytes[8]&63)|128;
|
||||
const hex=Array.from(bytes, value=>value.toString(16).padStart(2,'0')).join('');
|
||||
return `${hex.slice(0,8)}-${hex.slice(8,12)}-${hex.slice(12,16)}-${hex.slice(16,20)}-${hex.slice(20)}`;
|
||||
};
|
||||
const id = (prefix) => `${prefix}-${uuid()}`;
|
||||
const repoName = (repoId) => state.config.repositories.find(r => r.id === repoId)?.name || repoId;
|
||||
const volatileLocation = (repo) => repo.type === 'local' && (/^\/tmp(?:\/|$)/.test(repo.location) || /^\/run(?:\/|$)/.test(repo.location));
|
||||
const tipAttr = (text) => text ? ` data-tooltip="${esc(text)}"` : '';
|
||||
|
||||
Reference in New Issue
Block a user