Skip to content

Instantly share code, notes, and snippets.

@AfroThundr3007730
Last active June 5, 2019 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AfroThundr3007730/ff8cda65180459280bebd0c9ce3e4c9e to your computer and use it in GitHub Desktop.
Save AfroThundr3007730/ff8cda65180459280bebd0c9ce3e4c9e to your computer and use it in GitHub Desktop.
Recover Stylish styles after webextension migration
#!/usr/bin/python
# Dumps pre-webextension Stylish styles to CSS files
import os
import json
def dump_styles():
dump_dir = os.path.join(os.getcwd(), 'style_dump')
style_file = os.path.join(os.getcwd(), 'stylish-storage.js')
stylish = json.load(open(style_file, 'r'))
if not os.path.exists(dump_dir):
os.mkdir(dump_dir)
for s in stylish['styles']:
out_file = os.path.join(dump_dir, str(s['id']).zfill(2) + '.css')
with open(out_file, 'w+') as f:
f.write('/* Name: ' + s['name'] + '\n')
f.write(' * ID: ' + str(s['id']).zfill(2) + '\n')
f.write(' * Enabled: ' + str(s['enabled']) + '\n')
if 'url' in s and s['url']:
f.write(' * URL: ' + s['url'] + '\n')
if 'updateUrl' in s and s['updateUrl']:
f.write(' * Update URL: ' + s['updateUrl'] + '\n')
if 'md5Url' in s and s['md5Url']:
f.write(' * MD5 URL: ' + s['md5Url'] + '\n')
f.write(' * Code follows' + '\n' + ' */' + '\n\n')
f.write(s['code'])
if __name__ == '__main__':
dump_styles()
@AfroThundr3007730
Copy link
Author

Note: This is really only useful for the 2.0.7 era Stylish, which migrated to using storage.js. Extracting the styles from the old school stylish.sqlite is left as an exercise to the reader.

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