Advertisement
jjdeharo

butexe.js

Feb 16th, 2023 (edited)
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let originalFont;
  2.   let currentFontSize = 0;
  3.  
  4.   function setFont(font) {
  5.     document.body.style.fontFamily = font;
  6.     localStorage.setItem('font', font);
  7.   }
  8.  
  9.   function setFontSize(size) {
  10.     currentFontSize = parseInt(window.getComputedStyle(document.body).getPropertyValue('font-size'));
  11.     currentFontSize += size;
  12.     document.body.style.fontSize = currentFontSize + 'px';
  13.     localStorage.setItem('fontSize', currentFontSize + 'px');
  14.   }
  15.  
  16.   document.addEventListener('DOMContentLoaded', () => {
  17.     originalFont = window.getComputedStyle(document.body).getPropertyValue('font-family');
  18.     localStorage.setItem('originalFont', originalFont);
  19.     let font = localStorage.getItem('font');
  20.     if (!font) {
  21.       font = originalFont;
  22.     }
  23.     document.body.style.fontFamily = font;
  24.  
  25.     let fontSize = localStorage.getItem('fontSize');
  26.     if (!fontSize) {
  27.       fontSize = '16px';
  28.     }
  29.     document.body.style.fontSize = fontSize;
  30.  
  31.     const fontButtonContainer = document.createElement('div');
  32.     fontButtonContainer.style.display = 'flex';
  33.     fontButtonContainer.style.justifyContent = 'center';
  34.     fontButtonContainer.style.alignItems = 'center';
  35.  
  36.     const standardFontButton = document.createElement('a');
  37.     standardFontButton.classList.add('font-button');
  38.     standardFontButton.textContent = 'Fuente estándar';
  39.     standardFontButton.addEventListener('click', () => setFont(originalFont));
  40.     fontButtonContainer.appendChild(standardFontButton);
  41.  
  42.     const dyslexicFontButton = document.createElement('a');
  43.     dyslexicFontButton.classList.add('font-button');
  44.     dyslexicFontButton.textContent = 'OpenDyslexic';
  45.     dyslexicFontButton.addEventListener('click', () => setFont('OpenDyslexic, sans-serif'));
  46.     fontButtonContainer.appendChild(dyslexicFontButton);
  47.  
  48.     const hyperlegibleFontButton = document.createElement('a');
  49.     hyperlegibleFontButton.classList.add('font-button');
  50.     hyperlegibleFontButton.textContent = 'Atkinson Hyperlegible';
  51.     hyperlegibleFontButton.addEventListener('click', () => setFont('Atkinson Hyperlegible, sans-serif'));
  52.     fontButtonContainer.appendChild(hyperlegibleFontButton);
  53.  
  54.     const increaseFontButton = document.createElement('button');
  55.     increaseFontButton.classList.add('font-button');
  56.     increaseFontButton.textContent = '+';
  57.     increaseFontButton.addEventListener('click', () => setFontSize(3));
  58.     fontButtonContainer.appendChild(increaseFontButton);
  59.  
  60.     const decreaseFontButton = document.createElement('button');
  61.     decreaseFontButton.classList.add('font-button');
  62.     decreaseFontButton.textContent = '-';
  63.     decreaseFontButton.addEventListener('click', () => setFontSize(-3));
  64.     fontButtonContainer.appendChild(decreaseFontButton);
  65.  
  66.     document.body.insertBefore(fontButtonContainer, document.body.firstChild);
  67.    
  68.     const infoLink = document.createElement('a');
  69.     infoLink.textContent = '+Info';
  70.     infoLink.href = 'https://bilateria.org/fuente/';
  71.     infoLink.target = '_blank';
  72.     infoLink.style.marginLeft = '8px';
  73.     infoLink.style.fontSize = '12px';
  74.     fontButtonContainer.appendChild(infoLink);
  75.   });
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement