Skip to content

Instantly share code, notes, and snippets.

@nonodev96
Created March 7, 2024 20:14
Show Gist options
  • Save nonodev96/a75adb6359e6ba49bc9fb554a93d38d3 to your computer and use it in GitHub Desktop.
Save nonodev96/a75adb6359e6ba49bc9fb554a93d38d3 to your computer and use it in GitHub Desktop.

Revisions

  1. nonodev96 created this gist Mar 7, 2024.
    53 changes: 53 additions & 0 deletions overleaf-toogle-wordwrap.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    // ==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);
    }
    })();