Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
# Linux usage: ./ "/home/<USER>/.config/<BROWSER>/Default/Local Extension Settings/<EXTENSION_ID>"
# i.e.: ./ "/home/foo/.config/google-chrome-beta/Default/Local Extension Settings/gcalenpjmijncebpfijmoaglllgpjagf"
# Mac usage: ./ "/Users/<USER>/Library/Application Support/Google/Chrome/Default/Local Extension Settings/<EXTENSION_ID>/"
# i.e.: ./ "/Users/foo/Library/Application Support/Google/Chrome/Default/Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo/"
import leveldb
import sys
import re
import json
import codecs
pattern = re.compile("^@source(.*)$")
db = leveldb.LevelDB(sys.argv[1:][0])
for k,v in db.RangeIter():
m = pattern.match(k)
if m:
name = re.sub("[\W\b]", "_", m.groups()[0].strip())
full_name = "%s.user.js" % name
print "Writing to %s" % full_name
content = json.JSONDecoder(encoding='UTF-8').decode(v)['value']
with, 'w', 'utf-8') as text_file:
Copy link

sp4ce commented Oct 5, 2015


I forked you script and make it work with 3.11:

Copy link

derjanb commented Jan 11, 2016

@sp4ce Merged. Thanks a lot.

Copy link

Kerrigan29a commented Feb 9, 2016


I've added in my fork the usual path in Mac:

Thanks for this useful extension

Copy link

Enissay commented Feb 15, 2017

Ummm, I have deleted my chrome profile by mistake, but I managed to get a previous version of chrome's folder and trying to get my scripts back.

I've installed python for Windows but it doesn't seem to be working, or at least I couldn't make it work if someone can help please ?

Copy link

MrTact commented Apr 11, 2017

Forked & modded for Python3, in case that's more your poison of choice:

Copy link

calraith commented May 23, 2018

I couldn't compile leveldb in Windows 10. In case it helps @Enissay or anyone else, I wrote a quick and dirty PowerShell alternative to this Python script.

Copy link

derjanb commented Jul 19, 2018

@calraith Thank you!

Copy link

ImSeaWorld commented Nov 21, 2018

Aight. Took me a solid day plus an hour and a half to get it working. After it's all working properly it doesn't spit out my scripts. The only solution and it doesn't work. Good fucking god.

Copy link

etaderhold commented Jul 18, 2020

Thanks so much for this script! I was so worried I had lost my scripts, but I was able to run this against a Time Machine backup to get them back.

Copy link

Aceralon commented Aug 1, 2020

For Windows 10 user using python3 they can try wsl.

Copy link

needforsuv commented Oct 6, 2020

for windows users. Just rename .ldb to .sst because I guess the fork doesn't work with .ldb yet (at least with 2.7 binaries)

C:\Users\user>C:\Python27\python.exe C:\Users\user\Desktop\ "C:\Users\user\Desktop\dhdgffk
Writing to _0d456ca5_3601_4638_a417_25b70ba320ca.user.js
Writing to _2185129a_bd9d_4ed6_ae59_5e1b43dd5ecf.user.js
Writing to _5f0393a6_c0da_4069_b646_e505507724c6.user.js
Writing to _623ee855_0804_476a_922f_40b6ed938746.user.js
Writing to _66a053d9_70f0_4dc3_a490_0eb149ce9849.user.js
Writing to _6a5f7258_e74d_4383_8516_714c014c1bc1.user.js
Writing to _a1669f5f_d6f4_4f96_8e05_2c6582d8d21d.user.js
Writing to _a791fe14_381d_48a5_abe5_34c73db716b7.user.js
Writing to _bbdf06d1_0336_4dd1_acc0_9f2086548bcd.user.js
Writing to _bc2a3b39_40a2_40a5_812e_177af8f969b6.user.js
Writing to _e1af85c1_fd7a_40c2_8313_25ce1bb4c1c2.user.js
Writing to _f2e744c8_e237_45ba_ae22_bf63a1f80295.user.js


Copy link

ipatch commented Nov 27, 2020

is this suppose to work with python 3.9

Copy link

kitsune7 commented Mar 30, 2021

@ipatch, @MrTact made a fork of this that I think should work with python 3.9.

Copy link

lamchau commented Apr 13, 2021

Couldn't get the macOS leveldb python package to compile, but wrote a node-based solution for anyone else who gets stuck.

Copy link

OlehSuvorovSvitla commented Sep 22, 2021


My windows 10 was crashed and now I'm trying to extract Tampermonkey script from extension.
Found 000003 file (which contains them), but cannot run python script above due to errors like leveldb is missing.

Can someone please run that scripts for me?
Uploaded file to:!ApdatwDcvb1ijGud-awXAi5aIFFN?e=hYyutS (as 7z, not accepted unpacked)
Mirror: (raw text)

Copy link

DonaldDuck313 commented Oct 31, 2021

For it to work in Python 3, you need to change line 19 to m = pattern.match(str(k)) and line 24 to print("Writing to %s" % full_name)

Copy link

iamqiz commented Nov 25, 2021

on windows, i cannt install leveldb , so i use wsl to run the python;
here is result from your file!Aso5a3Kpi4YwgXekt87RSxpi-BTY?e=GTwciO

Copy link

OlehSuvorovSvitla commented Nov 25, 2021

@iamqiz oh, thank you very much for this work!

I tested extracting the 000003 file for ~500kb for me and placing it in the extension's folder - and it also worked somehow o_O
So my tampermonkey after all the restarts start to see older scripts.
Now I enabled sync of files, hopefully, it will not happen again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment