Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Script] Note To Tooltip

1650472340
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I don't know if anyone will have much use for this, but I thought I'd share. I have a whole bunch of NPC tokens that have GMnotes on them that need to be made into tooltips for reasons. This script copies the contents of the token gmnotes to the tooltips field. The biggest side benefit to this is that it allows you to exceed the character limit of the tooltips field. Notes: command is !notetotool It will run on multiple tokens in one go It allows you to exceed the character limit of tooltips. The extra text will not be manually editable. This is a limitation of the tooltip field. It strips out any html tags from styled text, but it would be best to avoid styled text if possible It strips out any coding for API buttons or markdown images. Basically anything that follows the [text](code) format. If you don't know what this is, you probably aren't using it. If you do know what this is and want it to stay, remove  .replace(/\[[^\)]*\)?/gm, '')  from the end of line 29. Because many of my gmnotes use Supernotes, I use the Supernotes trick of not reporting to players anything after "-----" in the gmnotes field. If you need this copy to transfer, remove the if statement in lines 30-32. It automatically turns on show tooltip on the token. If you need to leave the setting as-is remove line 34:  t.set("show_tooltip", true); The code: var API_Meta = API_Meta || {}; API_Meta.NoteToTooltip = {     offset: Number.MAX_SAFE_INTEGER,     lineCount: -1 }; {     try {         throw new Error('');     } catch (e) {         API_Meta.NoteToTooltip.offset = (parseInt(e.stack.split(/\n/)[1].replace(/^.*:(\d+):.*$/, '$1'), 10) - (4));     } } on('ready', () => {     const version = '0.0.0';     log('NoteToTooltip v' + version + ' is ready! --offset ' + API_Meta.Faces.offset + ' -- Use the command !notetotooltip to send token note to tooltip'); }); on('chat:message', (msg_orig) => {     let msg = _.clone(msg_orig);     if (!/^!notetotool/.test(msg.content)) {         return;     }     if (undefined !== msg.selected) {         tokens = msg.selected             .map(o => getObj('graphic', o._id))             .filter(o => undefined !== o)         tokens.forEach(t => {             if (t.get("type") === 'graphic') {                 newNote = unescape(t.get("gmnotes")).replace(/<[^>]*>?/gm, '').replace(/\[[^\)]*\)?/gm, '');                 if (newNote.includes('-----')) {                     newNote = newNote.split('-----')[0];                 }                 t.set("tooltip", newNote);                 t.set("show_tooltip", true); //not supported by API yet             }         });     } });
:-)