Created
March 7, 2024 20:14
-
-
Save nonodev96/a75adb6359e6ba49bc9fb554a93d38d3 to your computer and use it in GitHub Desktop.
Toogle word wrap, editor, overleaf, tampermonkey, codemirror, overleaf please fix your editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Overleaf Toggle WordWrap | |
| // @namespace http://tampermonkey.net/ | |
| // @version 2024-03-07 | |
| // @description try to take over the world! | |
| // @author nonodev96 | |
| // @match https://www.overleaf.com/project/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=overleaf.com | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| var whiteSpaceValues = ['pre', 'break-spaces']; | |
| var currentIndex = 0; | |
| // Función para cambiar el modo de white space | |
| function cambiarWhiteSpace() { | |
| // Encuentra el elemento de texto en Overleaf | |
| var contentElement = document.querySelectorAll(".cm-content")[0]; | |
| // Obtén el próximo valor de white space | |
| currentIndex = (currentIndex + 1) % whiteSpaceValues.length; | |
| var newWhiteSpace = whiteSpaceValues[currentIndex]; | |
| // Cambia el estilo de white space | |
| contentElement.style.whiteSpace = newWhiteSpace; | |
| } | |
| // Agrega el botón al menú de Overleaf | |
| function agregarBoton() { | |
| // Crea un nuevo botón | |
| var boton = document.createElement('button'); | |
| boton.innerHTML = 'Toggle'; | |
| boton.addEventListener('click', cambiarWhiteSpace); | |
| // Encuentra el contenedor del menú en Overleaf y agrega el botón | |
| var menuContainer = document.querySelectorAll(".ol-cm-toolbar-button-group")[7] | |
| console.log(menuContainer); | |
| if (menuContainer) { | |
| menuContainer.appendChild(boton); | |
| } | |
| } | |
| // Espera a que la página esté completamente cargada antes de agregar el botón | |
| if (document.readyState === 'complete' || document.readyState === 'interactive') { | |
| setTimeout(agregarBoton, 3000); | |
| } else { | |
| window.addEventListener('DOMContentLoaded', agregarBoton); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment