mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-02 05:59:21 +03:00
Avatars plugin added other identicon types (needs config settings)
This commit is contained in:
parent
9df052a435
commit
9502fa3f5a
4 changed files with 97 additions and 23 deletions
|
|
@ -386,21 +386,6 @@ function outerShape(index, g, cell) {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a SHA1 hash for any value and returns it as a hexadecimal string.
|
||||
*
|
||||
* This function is optimized for minimal code size and rather short messages.
|
||||
*
|
||||
* @param {string} message
|
||||
*/
|
||||
async function computeHash(message) {
|
||||
const hashArray = Array.from(new Uint8Array(
|
||||
// await crypto.subtle.digest('SHA-256', (new TextEncoder()).encode(message))
|
||||
await crypto.subtle.digest('SHA-1', (new TextEncoder()).encode(message))
|
||||
));
|
||||
return hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a measure to be used as a measure in an SVG path, by
|
||||
* rounding the measure to a single decimal. This reduces the file
|
||||
|
|
@ -597,11 +582,9 @@ class SvgWriter
|
|||
* @param {*} hashOrValue - A hexadecimal hash string or any value that will be hashed by Jdenticon.
|
||||
* @returns {string} SVG string
|
||||
*/
|
||||
window.identiconSvg = async (hashOrValue) => {
|
||||
window.identiconSvg = hash => {
|
||||
const writer = new SvgWriter(50),
|
||||
renderer = new SvgRenderer(writer),
|
||||
hash = (/^[0-9a-f]{11,}$/i.test(hashOrValue) && hashOrValue)
|
||||
|| await computeHash(hashOrValue == null ? "" : "" + hashOrValue),
|
||||
config = {
|
||||
p/*colorSaturation*/: 0.5,
|
||||
H/*grayscaleSaturation*/: 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue