Last active
April 17, 2025 12:27
-
-
Save derjanb/9f6c10168e63c3dc3cf0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/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) |
ziqian-L
commented
Apr 12, 2023
via email
已经整上谷歌云服务备份了😂谢谢佬抽时间解答
…---- 回复的原邮件 ----
| 发件人 | ***@***.***> |
| 日期 | 2023年04月12日 21:59 |
| 收件人 | ***@***.***> |
| 抄送至 | ***@***.***> |
| 主题 | Re: derjanb/extract_tampermonkey_script.py |
@iamqiz commented on this gist.
@ziqian-L😂 以后定期做好备份吧 ,设置>实用工具>压缩包|文件> 导出
—
Reply to this email directly, view it on GitHub or unsubscribe.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS or Android.
Is there something like this for Firefox?
I had to rewrite it slightly for it to work because values are bytearray
, not strings.
I also used python3
which AFAIK is the default on most distros now:
#!/usr/bin/env python3
# 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(b"^@source(.*)$")
db = leveldb.LevelDB(sys.argv[1:][0])
for k,v in db.RangeIter():
k = k.decode('utf-8')
m = pattern.match(k)
if m:
v = v.decode('utf-8')
name = re.sub("[\W\b]", "_", m.groups()[0].strip())
full_name = "%s.user.js" % name
print("Writing to %s" % full_name)
content = json.JSONDecoder().decode(v)['value']
with codecs.open(full_name, 'w', 'utf-8') as text_file:
text_file.write(content)
for those who cant install that leveldb crap. Install plyvel and try this script chatgpt adapted for me (tested on python 3.8 windows7)
import plyvel
import sys
import re
import json
import codecs
pattern = re.compile(b"^@source(.*)$")
db_path = sys.argv[1]
db = plyvel.DB(db_path, create_if_missing=False)
for k, v in db:
m = pattern.match(k)
if m:
k = k.decode('utf-8')
v = v.decode('utf-8')
group_decoded = m.groups()[0].decode('utf-8')
name = re.sub("[\\W\\b]", "_", group_decoded.strip())
full_name = f"{name}.user.js"
print(f"Writing to {full_name}")
content = json.JSONDecoder().decode(v)['value']
with codecs.open(full_name, 'w', 'utf-8') as text_file:
text_file.write(content)
db.close()
For those who just want to copy tampermonkey scripts from one Chrome browser to another, you don't need scripts to just copy the scripts to another browser.
Copy folder C:\Users\YourUserName\AppData\Local\Vivaldi\User Data\Default\Local Extension Settings\dhdgffkkebhmkfjojejmpbldmpobfkfo
. If the extension id changes when you will want to do it, look it up in the extension list.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment