Tampermonkey scripts?

Tampermonkey (and other similar projects) is amazing because it let you inject js into arbitrary websites (but just for you, locally). See https://www.tampermonkey.net/ . I typically use it to fine tune various website, like having a custom local cache for often listened youtube music videos or adding the possibility to add custom notes to vinted articles. But you can also use scripts written by others (but be careful, a script can do many things, like read a page and send data somwhere).

The problem?

I reinstalled my os (and firefox) and had forgotten to export (some of) my user scripts (tampermonkey scripts). The scripts are store in the firefox profile. I have a backup of my old profile, but the scripts are encoded, in an sqlite database, itself in an extension folder with a cryptic name.

The solution: a python script to extract existing scripts

I needed to adapt a solution from stackoverflow. The full process has been exploratory so I’m sharing rather than there.

Thanks to the stackoverflow question and answers (with the python script that I adapted): https://stackoverflow.com/questions/67246384/tampermonkey-firefox-user-scripts-storage-location

Here is the script: tampermonkey.py .

Here are the command to run:

Terminal window
pip install python-snappy
OLD=the/path/to/your/old/firefox/profile # or folder containing all profiles
python tampermonkey.py "$OLD"

Explorations to get the final script

I played with modifying the initial stackoverflow script and using sqlite browser. The information about the encoding of keys have been really helpful to start with.

Here are two version of an exploratory script. Some setup first.

Terminal window
pip install python-snappy
OLD=the/path/to/your/old/firefox/profile # or folder containing all profiles

First, I looked for all sqlite db that contain some keys that once decoded contain source (as seem to be used by Tampermonkey).

To replicate: download tampermonkey_explore1.py , then run

Terminal window
python tampermonkey_explore1.py "$OLD"

Second, I explored the decoding of the scripts, including handling different file encoding (hardcoded two possibilities).

To replicate: download tampermonkey_explore2.py , then run

Terminal window
python tampermonkey_explore2.py "$OLD"