Skip to content

Instantly share code, notes, and snippets.

@derjanb
Last active April 29, 2024 23:29
Show Gist options
  • Star 47 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save derjanb/9f6c10168e63c3dc3cf0 to your computer and use it in GitHub Desktop.
Save derjanb/9f6c10168e63c3dc3cf0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Linux 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"
# Mac usage: ./extract_tampermonkey_script.py "/Users/<USER>/Library/Application Support/Google/Chrome/Default/Local Extension Settings/<EXTENSION_ID>/"
# i.e.: ./extract_tampermonkey_script.py "/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 codecs.open(full_name, 'w', 'utf-8') as text_file:
text_file.write(content)
@iamqiz
Copy link

iamqiz commented Apr 12, 2023

@ziqian-L 😂 以后定期做好备份吧 ,设置>实用工具>压缩包|文件> 导出

@ziqian-L
Copy link

ziqian-L commented Apr 12, 2023 via email

@aleclarson
Copy link

Is there something like this for Firefox?

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