Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let originalFont;
- let currentFontSize = 0;
- function setFont(font) {
- document.body.style.fontFamily = font;
- localStorage.setItem('font', font);
- }
- function setFontSize(size) {
- currentFontSize = parseInt(window.getComputedStyle(document.body).getPropertyValue('font-size'));
- currentFontSize += size;
- document.body.style.fontSize = currentFontSize + 'px';
- localStorage.setItem('fontSize', currentFontSize + 'px');
- }
- document.addEventListener('DOMContentLoaded', () => {
- originalFont = window.getComputedStyle(document.body).getPropertyValue('font-family');
- localStorage.setItem('originalFont', originalFont);
- let font = localStorage.getItem('font');
- if (!font) {
- font = originalFont;
- }
- document.body.style.fontFamily = font;
- let fontSize = localStorage.getItem('fontSize');
- if (!fontSize) {
- fontSize = '16px';
- }
- document.body.style.fontSize = fontSize;
- const fontButtonContainer = document.createElement('div');
- fontButtonContainer.style.display = 'flex';
- fontButtonContainer.style.justifyContent = 'center';
- fontButtonContainer.style.alignItems = 'center';
- const standardFontButton = document.createElement('a');
- standardFontButton.classList.add('font-button');
- standardFontButton.textContent = 'Fuente estándar';
- standardFontButton.addEventListener('click', () => setFont(originalFont));
- fontButtonContainer.appendChild(standardFontButton);
- const dyslexicFontButton = document.createElement('a');
- dyslexicFontButton.classList.add('font-button');
- dyslexicFontButton.textContent = 'OpenDyslexic';
- dyslexicFontButton.addEventListener('click', () => setFont('OpenDyslexic, sans-serif'));
- fontButtonContainer.appendChild(dyslexicFontButton);
- const hyperlegibleFontButton = document.createElement('a');
- hyperlegibleFontButton.classList.add('font-button');
- hyperlegibleFontButton.textContent = 'Atkinson Hyperlegible';
- hyperlegibleFontButton.addEventListener('click', () => setFont('Atkinson Hyperlegible, sans-serif'));
- fontButtonContainer.appendChild(hyperlegibleFontButton);
- const increaseFontButton = document.createElement('button');
- increaseFontButton.classList.add('font-button');
- increaseFontButton.textContent = '+';
- increaseFontButton.addEventListener('click', () => setFontSize(3));
- fontButtonContainer.appendChild(increaseFontButton);
- const decreaseFontButton = document.createElement('button');
- decreaseFontButton.classList.add('font-button');
- decreaseFontButton.textContent = '-';
- decreaseFontButton.addEventListener('click', () => setFontSize(-3));
- fontButtonContainer.appendChild(decreaseFontButton);
- document.body.insertBefore(fontButtonContainer, document.body.firstChild);
- const infoLink = document.createElement('a');
- infoLink.textContent = '+Info';
- infoLink.href = 'https://bilateria.org/fuente/';
- infoLink.target = '_blank';
- infoLink.style.marginLeft = '8px';
- infoLink.style.fontSize = '12px';
- fontButtonContainer.appendChild(infoLink);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement