From bf02ec7359bb6dc048bcac928ee47b8d230f8a73 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 26 Aug 2021 14:30:51 +0530 Subject: [PATCH] animal emojis in color-by-author 'written by' tooltips --- www/code/markers.js | 18 +++++++++++++++--- www/common/inner/common-mediatag.js | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/www/code/markers.js b/www/code/markers.js index b070e68fc..b8a53bdd9 100644 --- a/www/code/markers.js +++ b/www/code/markers.js @@ -3,7 +3,8 @@ define([ '/common/sframe-common-codemirror.js', '/customize/messages.js', '/bower_components/chainpad/chainpad.dist.js', -], function (Util, SFCodeMirror, Messages, ChainPad) { + '/common/inner/common-mediatag.js', +], function (Util, SFCodeMirror, Messages, ChainPad, MT) { var Markers = {}; /* TODO Known Issues @@ -38,7 +39,17 @@ define([ }); } uid = Number(uid); - var name = Util.fixHTML(author.name || Messages.anonymous); + var name = Util.fixHTML((author.name || "").trim()); + var animal; + if ((!name || name === Messages.anonymous) && typeof(author.uid) === 'string') { + animal = MT.getPseudorandomAnimal(author.uid); + if (animal) { + name = animal + ' ' + Messages.anonymous; + } else { + name = Messages.anonymous; + } + } + var col = Util.hexToRGB(author.color); var rgba = 'rgba('+col[0]+','+col[1]+','+col[2]+','+Env.opacity+');'; return Env.editor.markText(from, to, { @@ -520,7 +531,8 @@ define([ Env.authormarks.authors[Env.myAuthorId] = { name: userData.name, curvePublic: userData.curvePublic, - color: userData.color + color: userData.color, + uid: userData.uid, }; if (!old || (old.name === userData.name && old.color === userData.color)) { return; } return true; diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index 5e091a83c..db15d83d4 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -92,7 +92,7 @@ define([ return ANIMALS[Math.floor(Math.random() * ANIMALS.length)]; }; - var getPseudorandomAnimal = function (seed) { + var getPseudorandomAnimal = MT.getPseudorandomAnimal = function (seed) { if (typeof(seed) !== 'string') { return getRandomAnimal(); } seed = seed.replace(/\D/g, '').slice(0, 10); seed = parseInt(seed);