Skip to content

Instantly share code, notes, and snippets.

@sp4ce
Forked from derjanb/extract_tampermonkey_script.py
Last active September 28, 2018 20:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sp4ce/a649517a429d72ffc442 to your computer and use it in GitHub Desktop.
Save sp4ce/a649517a429d72ffc442 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# usage ./extract_tampermonkey_script.py "/home/<user>/.config/<browser>/Default/Local Extension Settings/<extension_id>"
# i.e.: ./extract_tampermonkey_script.py "/home/foo/.config/google-chrome-beta/Default/Local Extension Settings/gcalenpjmijncebpfijmoaglllgpjagf"
#
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\d\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 codecs.open(full_name, 'w', 'utf-8') as text_file:
text_file.write(content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment