Skip to content

Instantly share code, notes, and snippets.

@hogashi
Created January 13, 2022 07:34
Show Gist options
  • Select an option

  • Save hogashi/2bfe8cf647a47fb0e7e050189b6ab527 to your computer and use it in GitHub Desktop.

Select an option

Save hogashi/2bfe8cf647a47fb0e7e050189b6ab527 to your computer and use it in GitHub Desktop.
文字を共感覚に沿った色にする
color = {
0: 'black',
1: 'white',
2: 'yellow',
3: 'lightgreen',
4: 'pink',
5: 'blue',
6: 'red',
7: 'lightgreen',
8: 'black',
9: 'brown',
};
newhtml = $0.textContent.split('').map(c => `<span style="color: ${color[c] ? color[c] : 'inherit'}">${c}</span>`).join('');
$0.innerHTML = newhtml;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment