Advertisement
sploshajosh

Anki Font Randomizer

Mar 31st, 2020
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. /*I did not write this code, this was written by gakushabaka on reddit. I only added comments, my fonts, and a slight edit. To use this, simply paste this into the Front Template of your deck and follow the comments. After you're done erase all the comments (anything that has "//" before it or "/*" and ends with "*/") so they don't show up on your cards. You also need to make sure you have the fonts installed. The ones I have added don't come with windows by default, so you'll have to install them yourselves if you want to use them. You can check your fonts by typing in "fonts" in the "run" command on windows by pressing "windows key + r" - (keep in mind some fonts do not work if they have spaces between the names or dashes). Also, some fonts show up as "'FontHere' Regular", you do not put the "regular" part in the fonts.*/
  2.  
  3. //Front Template (COPY THIS):
  4. <div id='rand_font' style='line-height:100%; color:white; font-size: 100px;'>{{FrontCard}}</div> //Change "FrontCard" to the field that goes on front. For example, if your front field is "Kanji" you would replace "FrontCard" with "Kanji" (without quotes)
  5.  
  6. <script type="text/javascript">
  7. var typefaces = ["Asobimemogaki","Armedbanana","Sanafon","Arial"], //Put all the fonts you have installed that you want in here. These are the fonts I'm currently using.
  8. typeface = typefaces[Math.floor(Math.random() * typefaces.length)],
  9. el = document.getElementById('rand_font');
  10. el.style.fontFamily = typeface;
  11.  
  12. var txt = el.innerHTML;
  13. var num_kanji = 0, tmp_val = 0;
  14. for ( var i = 0; i < txt.length; i++ ) {
  15. tmp_val = txt.charCodeAt(i);
  16. if (tmp_val >= 0x4e00 && tmp_val <= 0x9fff) {
  17. num_kanji ++;
  18. }
  19. }
  20.  
  21. //Remove this next if statement (between the two comments) if you don't want a 50% chance of verticle text.
  22. if ((num_kanji > 0) && (Math.random(1) > 0.5)) {
  23. txt = txt.split('').join('<br/>');
  24. el.innerHTML = txt;
  25. } //Erase up to here. Don't erase what's below.
  26. </script>
  27.  
  28. //Once you see that the template is working, please erase all the comments since they show up on your front template. Although, if you really want to I guess you can leave them :)
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. /* EXTRA:
  38. You can also paste this into your front template as well (paste it at the very bottom, this has nothing to do with the other script so it shouldn't be in it): */
  39.  
  40. <span style="font-size: 50px">{{hint:FrontCard}}</span> //Change 50px to change the size of your hint (what's hidden). Change FrontCard to the field that has the random font - so change it to the field that you used for the above script.
  41.  
  42. // After doing this, go to Styling and paste this in:
  43.  
  44. a {
  45. font-size: 10px; //This make it so the hint field is always 10px (the button you press)
  46. }
  47.  
  48. //This will make it so you have a hint field to show you the vocab or kanji in arial font.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement