跳转到内容

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]
标签由机器人或全自动脚本执行的操作
第9行: 第9行:


"use strict";
"use strict";
/**
(() => {
* Generated by scripts/generatePolyfill/index.js
     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;
* Options:
     const validate = (uuid) => "string" === typeof uuid && REGEX.test(uuid);
*    polyfillFeature: crypto.randomUUID
     const rnds8 = new Uint8Array(16);
*    polyfillAliases: default
     const rng = () => crypto.getRandomValues(rnds8);
*    targetChromiumVersion: 86.0.0
     const byteToHex = [];
*    polyfillVersionRange: <92.0.0-0 (<92)
     for (let i = 0; i < 256; ++i) {
*/ (function() {
     // Polyfill crypto.randomUUID start
    /**
* 引自 uuid@9.0.0
*/ /**
* @source https://github.com/uuidjs/uuid/blob/v9.0.0/src/regex.js
*/ var 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;
     /**
* @source https://github.com/uuidjs/uuid/blob/v9.0.0/src/validate.js
*/ var validate = function(uuid) {
        return "string" === typeof uuid && REGEX.test(uuid);
     };
    /**
* @source https://github.com/uuidjs/uuid/blob/v9.0.0/src/rng-browser.js
*/ var rnds8 = new Uint8Array(16);
     var rng = function() {
        return crypto.getRandomValues(rnds8);
     };
    /**
* @source https://github.com/uuidjs/uuid/blob/v9.0.0/src/stringify.js
*/ var byteToHex = [];
     for(var i = 0; i < 256; ++i){
         byteToHex.push((i + 256).toString(16).substring(1));
         byteToHex.push((i + 256).toString(16).substring(1));
     }
     }
     var unsafeStringify = function(arr) {
     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();
        var offset = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
     const v4 = (options = {}, buf, offset = 0) => {
        return "".concat(byteToHex[arr[offset + 0]]).concat(byteToHex[arr[offset + 1]]).concat(byteToHex[arr[offset + 2]]).concat(byteToHex[arr[offset + 3]], "-").concat(byteToHex[arr[offset + 4]]).concat(byteToHex[arr[offset + 5]], "-").concat(byteToHex[arr[offset + 6]]).concat(byteToHex[arr[offset + 7]], "-").concat(byteToHex[arr[offset + 8]]).concat(byteToHex[arr[offset + 9]], "-").concat(byteToHex[arr[offset + 10]]).concat(byteToHex[arr[offset + 11]]).concat(byteToHex[arr[offset + 12]]).concat(byteToHex[arr[offset + 13]]).concat(byteToHex[arr[offset + 14]]).concat(byteToHex[arr[offset + 15]]).toLowerCase();
         const rnds = options.random || (options.rng || rng)();
     };
    /**
* @source https://github.com/uuidjs/uuid/blob/v9.0.0/src/v4.js
*/ var v4 = function() {
        var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, buf = arguments.length > 1 ? arguments[1] : void 0, offset = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
         var rnds = options.random || (options.rng || rng)();
         rnds[6] = rnds[6] & 0x0f | 0x40;
         rnds[6] = rnds[6] & 0x0f | 0x40;
         rnds[8] = rnds[8] & 0x3f | 0x80;
         rnds[8] = rnds[8] & 0x3f | 0x80;
         if (buf) {
         if (buf) {
             for(var i = 0; i < 16; ++i){
             for (let i = 0; i < 16; ++i) {
                 buf[offset + i] = rnds[i];
                 buf[offset + i] = rnds[i];
             }
             }
第59行: 第31行:
         return unsafeStringify(rnds);
         return unsafeStringify(rnds);
     };
     };
     /**
     try {
* main polyfill
*/ try {
         if (!validate(crypto.randomUUID())) {
         if (!validate(crypto.randomUUID())) {
             throw void 0;
             throw void 0;
         }
         }
    } catch (e) {
        crypto.randomUUID = function() {
            return v4();
        };
     }
     }
// Polyfill crypto.randomUUID end
    catch {
        crypto.randomUUID = () => v4();
    }
})();  
})();  


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

2025年7月24日 (四) 20:57的版本

/**
 * -------------------------------------------------------------------------
 * !!! 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 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> */