AllanChain / blog

Blogging in GitHub issues. Building with Astro.
https://allanchain.github.io/blog/
MIT License
13 stars 0 forks source link

Reverting changes in Overleaf #200

Open AllanChain opened 1 year ago

AllanChain commented 1 year ago

View Post on Blog

Getting documents older than 24 hours back in Overleaf, discarding changes you just made, without upgrading your Overleaf plan.


Man always makes mistakes. But Overleaf doesn't let you quickly revert all your changes, without upgrading and enabling the Git sync. However, it does allow you to view the history and compare it with the previous version, even if the previous version is older than 24 hours. That means it's actually possible to extract the changes and revert.

For the following content, I'll Assume you have some basic web skills.

First, open the developer tools of your browser and switch to the "Network" tab. Then open the history tab on the right-top of the page, and filter the URLs with diff?path. Select it (or one of them if multiple files are changed). You will see something like:

{"diff":[{"u":"\\documentclass..."}]}

Right-click on the request (not the JSON), and select "Copy Value" -> "Copy Response", and then paste it to a file named diff.json.

Open up a Python console, run

import json

with open("diff.json") as f:
    s = json.load(f)

t = ""

for l in s["diff"]:
    if "u" in l:
        t += l["u"]
    elif "d" in l:
        t += l["d"]

with open("fix.txt", "w") as f:
    f.write(t)

The recovered document is in fix.txt