UNPKG

@gby/uniqueid

Version:

uniqueid 无任何依赖,提供了获取唯一标识相关的工具,比如:UUID、UCID、Fingerprint、浏览器指纹、唯一标识符 等等

2 lines (1 loc) 2.1 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).uniqueid={})}(this,(function(e){"use strict";function t(){var e=document.createElement("canvas"),t=e.getContext("2d");return t&&(t.textBaseline="alphabetic",t.font="14px Arial",t.fillStyle="#ccc",t.fillText("?! 科研者 GuoBinYong abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~1!2@3#4$5%6^7&8*9(0)-_=+[{]}|;:',<.>/?!",2,3)),e.toDataURL("image/jpeg").replace("data:image/jpeg;base64,","")}var a="_?!_";var n="_uuid";function r(){return Date.now().toString()+String(Math.random()).slice(1)}var o="_ucid";function i(e){for(var t,a,n,r=3&e.length,o=e.length-r,i=3432918353,c=461845907,l=0;l<o;l++)n=255&e.charCodeAt(l)|(255&e.charCodeAt(++l))<<8|(255&e.charCodeAt(++l))<<16|(255&e.charCodeAt(++l))<<24,++l,t=27492+(65535&(a=5*(65535&(t=(t^=n=(65535&(n=(n=(65535&n)*i+(((n>>>16)*i&65535)<<16)&4294967295)<<15|n>>>17))*c+(((n>>>16)*c&65535)<<16)&4294967295)<<13|t>>>19))+((5*(t>>>16)&65535)<<16)&4294967295))+((58964+(a>>>16)&65535)<<16);var u=o-1;switch(n=0,r){case 3:n^=(255&e.charCodeAt(u+2))<<16;break;case 2:n^=(255&e.charCodeAt(u+1))<<8;break;case 1:n^=255&e.charCodeAt(u)}return t^=n=(65535&(n=(n=(65535&n)*i+(((n>>>16)*i&65535)<<16)&4294967295)<<15|n>>>17))*c+(((n>>>16)*c&65535)<<16)&4294967295,t^=e.length,t=2246822507*(65535&(t^=t>>>16))+((2246822507*(t>>>16)&65535)<<16)&4294967295,t=3266489909*(65535&(t^=t>>>13))+((3266489909*(t>>>16)&65535)<<16)&4294967295,(t^=t>>>16)>>>0}e.createUniqueIdentifier=r,e.getCanvasFingerprint=t,e.getUCID=function(){var e=a+o,t=localStorage.getItem(e);return t||(t=r(),localStorage.setItem(e,t)),t},e.getUUID=function(){var e=a+n,r=localStorage.getItem(e);if(!r){var o=t();r=String(i(o)),localStorage.setItem(e,r)}return r},e.murmurhash3_32_gc=i,e.setKeyPrefix=function(e){a=e},e.setUCID=function(e){var t=a+o;localStorage.setItem(t,e)},e.setUUID=function(e){var t=a+n;localStorage.setItem(t,e)},Object.defineProperty(e,"__esModule",{value:!0})}));