logo

blog

My website can't be that messy, right? git clone https://anongit.hacktivis.me/git/blog.git/

font-test.js (2742B)


  1. // Copyright 2023 Haelwenn (lanodan) Monnier <contact+blog@hacktivis.me>
  2. // SPDX-License-Identifier: MIT
  3. 'use strict';
  4. const main = document.getElementsByTagName("main")[0];
  5. main.style.fontSynthesis = 'none';
  6. var fontfamilies = "";
  7. [
  8. "system-ui", "serif", "sans-serif", "monospace", "cursive", "fantasy", "ui-serif", "ui-sans-serif", "ui-monospace", "ui-rounded", "math", "emoji", "fangsong"
  9. ].forEach(function(e) {fontfamilies += `\t\t<option>${e}</option>\n`});
  10. var fontunits = "";
  11. [
  12. "px", "pt"
  13. ].forEach(function(e) {fontunits += `\t\t<option>${e}</option>\n`});
  14. var fontweights = "";
  15. [
  16. "100", "200", "300", "400", "500", "600", "700", "800", "900", "950"
  17. ].forEach(function(e) {fontweights += `\t\t<option>${e}</option>\n`});
  18. var fontstyles = "";
  19. [
  20. "normal", "italic", "oblique", "oblique -14deg", "oblique 90deg", "oblique -90deg"
  21. ].forEach(function(e) {fontstyles += `\t\t<option>${e}</option>\n`});
  22. document.getElementById('fontsel').innerHTML = `
  23. <label>Family:
  24. <input id="fontsel_in" type="text" list="fontfamilies"/>
  25. <datalist id="fontfamilies">${fontfamilies}</datalist>
  26. </label>
  27. <label>Size (<span id="fontsel_size_val">14px</span>):
  28. <input id="fontsel_size" type="range" max="30" min="1" step="1" value="14"/>
  29. <input id="fontsel_unit" type="text" list="fontunits"/>
  30. <datalist id="fontunits">${fontunits}</datalist>
  31. </label>
  32. <label>Weight (<span id="fontsel_weight_val">400</span>):
  33. <input id="fontsel_weight" type="range" max="1000" min="1" step="50" value="400" list="fontweights"/>
  34. <datalist id="fontweights">${fontweights}</datalist>
  35. </label>
  36. <label>Style:
  37. <input id="fontsel_style" type="text" list="fontstyles"/>
  38. <datalist id="fontstyles">${fontstyles}</datalist>
  39. </label>
  40. `;
  41. document.getElementById('fontsel_in').addEventListener('change', (e) => {
  42. main.style.fontFamily = e.target.value;
  43. });
  44. document.getElementById('fontsel_size').addEventListener('change', (e) => {
  45. main.style.fontSize = e.target.value + document.getElementById("fontsel_unit").value;
  46. document.getElementById('fontsel_size_val').innerText = main.style.fontSize;
  47. });
  48. document.getElementById('fontsel_unit').addEventListener('change', (e) => {
  49. main.style.fontSize = document.getElementById("fontsel_size").value + e.target.value;
  50. document.getElementById('fontsel_size_val').innerText = main.style.fontSize;
  51. });
  52. main.style.fontSize = "14px";
  53. main.style.fontWeight = 400; // Normal
  54. document.getElementById('fontsel_weight').addEventListener('change', (e) => {
  55. main.style.fontWeight = e.target.value;
  56. document.getElementById('fontsel_weight_val').innerText = main.style.fontWeight;
  57. });
  58. document.getElementById('fontsel_style').addEventListener('change', (e) => {
  59. main.style.fontStyle = e.target.value;
  60. });