Last active
June 5, 2019 16:30
-
-
Save AfroThundr3007730/ff8cda65180459280bebd0c9ce3e4c9e to your computer and use it in GitHub Desktop.
Recover Stylish styles after webextension migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 schoolstylish.sqlite
is left as an exercise to the reader.