Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1872,14 +1872,19 @@ const chatgpt = { // eslint-disable-line no-redeclare
unminify() { chatgpt.code.unminify(); },

uuidv4() {
let d = new Date().getTime(); // get current timestamp in ms (to ensure UUID uniqueness)
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = ( // generate random nibble
( d + (window.crypto.getRandomValues(new Uint32Array(1))[0] / (Math.pow(2, 32) - 1))*16)%16 | 0 );
d = Math.floor(d/16); // correspond each UUID digit to unique 4-bit chunks of timestamp
return ( c == 'x' ? r : (r&0x3|0x8) ).toString(16); // generate random hexadecimal digit
});
return uuid;
try {
// use native secure uuid generator when available
return crypto.randomUUID();
} catch(_e) {
let d = new Date().getTime(); // get current timestamp in ms (to ensure UUID uniqueness)
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = ( // generate random nibble
( d + (window.crypto.getRandomValues(new Uint32Array(1))[0] / (Math.pow(2, 32) - 1))*16)%16 | 0 );
d = Math.floor(d/16); // correspond each UUID digit to unique 4-bit chunks of timestamp
return ( c == 'x' ? r : (r&0x3|0x8) ).toString(16); // generate random hexadecimal digit
});
return uuid;
}
},

writeCode() { chatgpt.code.write(); }
Expand Down