跳转到内容

MediaWiki:Gadget-libPolyfill-crypto.randomUUID.js:修订间差异

来自萌娘共享
代码变动:103d1a56 - feat: rename (#594) by U:AnnAngela, co-authored-by: GH:github-actions[bot]
标签由机器人或全自动脚本执行的操作
代码变动:103d1a56 - feat: rename (#594) by U:AnnAngela, co-authored-by: GH:github-actions[bot]
标签由机器人或全自动脚本执行的操作
 
第8行: 第8行:
/* <pre> */
/* <pre> */


"use strict";
"use strict";(()=>{const t=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,$=new Uint8Array(16),rng=()=>crypto.getRandomValues($),r=[];for(let t=0;t<256;++t)r.push((t+256).toString(16).substring(1));const v4=(t={},$,o=0)=>{const f=t.random||(t.rng||rng)();if(f[6]=15&f[6]|64,f[8]=63&f[8]|128,$){for(let t=0;t<16;++t)$[o+t]=f[t];return $}return((t,$=0)=>`${r[t[$+0]]}${r[t[$+1]]}${r[t[$+2]]}${r[t[$+3]]}-${r[t[$+4]]}${r[t[$+5]]}-${r[t[$+6]]}${r[t[$+7]]}-${r[t[$+8]]}${r[t[$+9]]}-${r[t[$+10]]}${r[t[$+11]]}${r[t[$+12]]}${r[t[$+13]]}${r[t[$+14]]}${r[t[$+15]]}`.toLowerCase())(f)};try{if("string"!=typeof(o=crypto.randomUUID())||!t.test(o))throw void 0}catch{crypto.randomUUID=()=>v4()}var o})();  
(() => {
    const REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
    const validate = (uuid) => "string" === typeof uuid && REGEX.test(uuid);
    const rnds8 = new Uint8Array(16);
    const rng = () => crypto.getRandomValues(rnds8);
    const byteToHex = [];
    for (let i = 0; i < 256; ++i) {
        byteToHex.push((i + 256).toString(16).substring(1));
    }
    const unsafeStringify = (arr, offset = 0) => `${byteToHex[arr[offset + 0]]}${byteToHex[arr[offset + 1]]}${byteToHex[arr[offset + 2]]}${byteToHex[arr[offset + 3]]}-${byteToHex[arr[offset + 4]]}${byteToHex[arr[offset + 5]]}-${byteToHex[arr[offset + 6]]}${byteToHex[arr[offset + 7]]}-${byteToHex[arr[offset + 8]]}${byteToHex[arr[offset + 9]]}-${byteToHex[arr[offset + 10]]}${byteToHex[arr[offset + 11]]}${byteToHex[arr[offset + 12]]}${byteToHex[arr[offset + 13]]}${byteToHex[arr[offset + 14]]}${byteToHex[arr[offset + 15]]}`.toLowerCase();
    const v4 = (options = {}, buf, offset = 0) => {
        const rnds = options.random || (options.rng || rng)();
        rnds[6] = rnds[6] & 0x0f | 0x40;
        rnds[8] = rnds[8] & 0x3f | 0x80;
        if (buf) {
            for (let i = 0; i < 16; ++i) {
                buf[offset + i] = rnds[i];
            }
            return buf;
        }
        return unsafeStringify(rnds);
    };
    try {
        if (!validate(crypto.randomUUID())) {
            throw void 0;
        }
    }
    catch {
        crypto.randomUUID = () => v4();
    }
})();  


/* </pre> */
/* </pre> */

2025年7月26日 (六) 00:14的最新版本

/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * -------------------------------------------------------------------------
 */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/libPolyfill/Gadget-libPolyfill-crypto.randomUUID.js|user=[[U:AnnAngela]]|co-authors=GH:github-actions[bot]|longId=103d1a563ea4ccc8ff29fb55c9bcd88329a56eb5|shortId=103d1a56|summary=feat: rename (#594)|body=<nowiki>Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com></nowiki>}}'; 

/* <pre> */

"use strict";(()=>{const t=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,$=new Uint8Array(16),rng=()=>crypto.getRandomValues($),r=[];for(let t=0;t<256;++t)r.push((t+256).toString(16).substring(1));const v4=(t={},$,o=0)=>{const f=t.random||(t.rng||rng)();if(f[6]=15&f[6]|64,f[8]=63&f[8]|128,$){for(let t=0;t<16;++t)$[o+t]=f[t];return $}return((t,$=0)=>`${r[t[$+0]]}${r[t[$+1]]}${r[t[$+2]]}${r[t[$+3]]}-${r[t[$+4]]}${r[t[$+5]]}-${r[t[$+6]]}${r[t[$+7]]}-${r[t[$+8]]}${r[t[$+9]]}-${r[t[$+10]]}${r[t[$+11]]}${r[t[$+12]]}${r[t[$+13]]}${r[t[$+14]]}${r[t[$+15]]}`.toLowerCase())(f)};try{if("string"!=typeof(o=crypto.randomUUID())||!t.test(o))throw void 0}catch{crypto.randomUUID=()=>v4()}var o})(); 

/* </pre> */