Advertisement
Guest User

random all anki

a guest
Mar 17th, 2021
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1.  
  2.  
  3. <script>
  4. var alignments = ["justify","left","center","right"];
  5.  
  6. var alignmentindex = Math.floor(Math.random()*alignments.length);
  7.  
  8. var size = Math.floor(Math.random()*20)+Math.floor(Math.random()*60)+Math.floor(Math.random()*70)+10;
  9.  
  10. document.getElementById("yomis").style.fontSize = size+"px";
  11. document.getElementById("yomis").style.textAlign = alignments[alignmentindex];
  12.  
  13. </script>
  14.  
  15. <div id="yomis">
  16. <p class="yomis"><p>
  17. <div class="randomfont">{{Expression}}</div>
  18. <div class="randomfont">{{Simplified}}</div>
  19. <div class="randomfont">{{Traditional}}</div>
  20. <div class="shuffle">{{Expression}}</div>
  21. <div class="shuffle">{{Simplified}}</div>
  22. <div class="shuffle">{{Traditional}}</div>
  23. <div id="container"></div>
  24.  
  25. <script>
  26. function shuffleArray(array) {
  27. for (let i = array.length - 1; i > 0; i--) {
  28. const j = Math.floor(Math.random() * (i + 1));
  29. [array[i], array[j]] = [array[j], array[i]];
  30. }
  31. }
  32.  
  33. setTimeout(() => {
  34. const fields = [...document.querySelectorAll(".shuffle")];
  35. shuffleArray(fields);
  36. const container = document.getElementById("container");
  37. fields.forEach((fld, index) => {
  38. if (index !== 0) {
  39. container.appendChild(document.createElement(""));
  40. }
  41. container.appendChild(fld);
  42. });
  43. }, 0);
  44. </script>
  45.  
  46. </p>
  47. </div>
  48.  
  49. <script>
  50. function random_bg_color() {
  51. var x = Math.floor(Math.random() * 256);
  52. var y = Math.floor(Math.random() * 256);
  53. var z = Math.floor(Math.random() * 256);
  54. var bgColor = "rgb(" + x + "," + y + "," + z + ")";
  55. console.log(bgColor);
  56. document.body.style.background = bgColor;
  57. }
  58.  
  59. random_bg_color();
  60.  
  61. </script>
  62.  
  63. <div id="container" hidden>{{Expression}}{{Traditional}}{{Simplified}}</div>
  64. <script>
  65. var fieldID = "container";
  66. var randomHsl = (isNightMode) => {
  67. const hue = (Math.random() * 361) | 0;
  68. const saturation = (Math.random() * 101) | 0;
  69. let lightness = (Math.random() * 51) | 0;
  70. if (isNightMode) {
  71. lightness += 50;
  72. }
  73. return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
  74. };
  75. var colorizeEachChar = (fieldId) => {
  76. const text = document.getElementById(fieldId).textContent;
  77. const nightMode = document.body.classList.contains("night_mode");
  78. const resultArray = [];
  79. for (const char of text) {
  80. if (/\S/.test(char)) {
  81. resultArray.push(
  82. `<span style="color: ${randomHsl(nightMode)};">${char}</span>`
  83. );
  84. } else {
  85. resultArray.push(" ");
  86. }
  87. }
  88. return resultArray.join("");
  89. };
  90. setTimeout(() => {
  91. const ele = document.getElementById(fieldID);
  92. ele.innerHTML = colorizeEachChar(fieldID);
  93. ele.hidden = false;
  94. }, 0);
  95. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement