extract_tampermonkey_script.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python
  2. # URL: https://gist.github.com/derjanb/9f6c10168e63c3dc3cf0
  3. # TODO: NOTE:, appeared to not work with python v3.9.x
  4. # Linux usage: ./extract_tampermonkey_script.py "/home/<USER>/.config/<BROWSER>/Default/Local Extension Settings/<EXTENSION_ID>"
  5. # i.e.: ./extract_tampermonkey_script.py "/home/foo/.config/google-chrome-beta/Default/Local Extension Settings/gcalenpjmijncebpfijmoaglllgpjagf"
  6. # Mac usage: ./extract_tampermonkey_script.py "/Users/<USER>/Library/Application Support/Google/Chrome/Default/Local Extension Settings/<EXTENSION_ID>/"
  7. # i.e.: ./extract_tampermonkey_script.py "/Users/foo/Library/Application Support/Google/Chrome/Default/Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo/"
  8. import leveldb
  9. import sys
  10. import re
  11. import json
  12. import codecs
  13. pattern = re.compile("^@source(.*)$")
  14. db = leveldb.LevelDB(sys.argv[1:][0])
  15. for k,v in db.RangeIter():
  16. m = pattern.match(k)
  17. if m:
  18. name = re.sub("[\W\b]", "_", m.groups()[0].strip())
  19. full_name = "%s.user.js" % name
  20. print "Writing to %s" % full_name
  21. content = json.JSONDecoder(encoding='UTF-8').decode(v)['value']
  22. with codecs.open(full_name, 'w', 'utf-8') as text_file:
  23. text_file.write(content)