// ==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); } })();