Skip to content

Instantly share code, notes, and snippets.

@sillvva
Last active December 28, 2018 23:45
Show Gist options
  • Save sillvva/fb71a80864f75b951e83b4fce4266f77 to your computer and use it in GitHub Desktop.
Save sillvva/fb71a80864f75b951e83b4fce4266f77 to your computer and use it in GitHub Desktop.
FVTT mod: showto

You could also probably accomplish that with a simple styles module like this:

<div>Everyone sees this part of the message</div>
<div showto="gm Sillvva">Only the GM and Sillvva see this part.</div>
Hooks.on('ready', () => {
    let style = document.createElement('style');
    
    style.type = 'text/css';
    style.innerHTML += '[showto] { display: none; }\n';
    // GM
    if (game.user.isGM) style.innerHTML += '[showto~="gm"], [showto~="GM"] { display: initial; }';
    // Player Name
    style.innerHTML += game.user.name
    	.replace(/[^a-z0-9\- ]/gi,' ').replace(/ {2,}/g,' ').split(' ')
	.reduce((string, word) => string+'[showto~="'+word+'"]', '')+' { display: initial; }\n';
    // Character Name
    style.innerHTML += game.user.character.name
        .replace(/[^a-z0-9\- ]/gi,' ').replace(/ {2,}/g,' ').split(' ')
        .reduce((string, word) => string+'[showto~="'+word+'"]', '')+' { display: initial; }\n';
    
    document.getElementsByTagName('head')[0].appendChild(style);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment