浏览器 扩展

发布于 更新于

AI总结: 本文介绍了一个用于导出Firefox扩展插件列表的Python脚本,脚本功能包括查找Firefox配置目录、读取已安装扩展的相关信息,并将已启用和禁用的扩展分别导出到Markdown文件中。用户需要根据自己的实际情况修改配置目录路径。 优化建议: 1. 考虑添加异常处理以应对文件读取错误,并提供更详细的错误信息。 2. 增加命令行参数支持,让用户可以自定义输出文件名和配置目录。 3. 优化代码结构,考虑将重复的字符串格式化逻辑提取为单独的函数。 4. 增加注释和文档字符串,以提高代码的可读性和可维护性。

Enabled Extensions

  1. uBlacklist 8.9.2
  2. ChatGPTBox 2.5.8
  3. Limit Tabs 2.2.9
  4. FoxyTab 2.31
  5. Block Site 0.5.2.1
  6. Copy Selection as Markdown 0.22.0
  7. Omnibug 2.0.2
  8. JSLibCache 0.0.21
  9. Captcha Solver: Auto captcha solving service 1.10.5
  10. I'm not robot captcha clicker 1.3.1
  11. DontBugMe 2.0.3
  12. Circle reader 2.7.0
  13. LibRedirect 3.0.2
  14. Web Archives 7.0.0
  15. Violentmonkey 2.26.0
  16. LastPass 4.134.0
  17. uBlock Origin 1.60.0

Disabled Extensions

  1. Vimium 2.1.2
  2. FastForward 0.2383
  3. ClearURLs 1.26.1
  4. Sidebery 5.2.0
  5. Tridactyl 1.24.1
  6. Tab Reloader (page auto refresh) 0.6.3
  7. Silk - Privacy Pass Client 4.0.2
  8. Linguist - web pages translator 6.0.1
  9. Buster: Captcha Solver for Humans 3.1.0
  10. Sort tabs advanced 0.2
  11. FireMonkey 2.72
  12. Edit 1.9
  13. Auto Tab Discard 0.6.7
  14. Foxy Gestures 1.2.12
  15. Tranquility Reader 3.0.26
  16. KISS Translator 1.8.11
  17. FindSomething 2.0.18
  18. 流畅阅读 0.0.9
  19. 即时工具 1.2.0
  20. Local CDN 0.1.4resigned1
  21. NopeCHA: CAPTCHA Solver 0.4.12
  22. Checker Plus for Gmail 29.0.3.1
  23. Tree Style Tab 4.0.23
  24. Immersive Translate - Translate Web & PDF 1.9.8
  25. LocalCDN 2.6.74

导出插件列表脚本

能用就没优化了, 而且现在也没用Firefox, 此处只做备份 需要根据实际情况修改config_dir配置

# -*-coding:utf-8-*-

import os
import json

def find_firefox_profile_path():
    # 获取当前用户的配置目录
    # config_dir = os.path.expandvars(r'%APPDATA%\Floorp')
    config_dir = 'C:\\Users\\Administrator\\AppData\\Roaming\\zen\\'
    profiles_ini_path = os.path.join(config_dir, "profiles.ini")

    if not os.path.exists(profiles_ini_path):
        raise FileNotFoundError("Could not find profiles.ini file.")

    with open(profiles_ini_path, "r", encoding="utf-8") as file:
        lines = file.readlines()

    profile_path = None
    for line in lines:
        if line.strip().startswith("Path="):
            profile_path = line.strip().split("=")[1]
            break

    if not profile_path:
        raise FileNotFoundError("Could not find profile path in profiles.ini file.")

    return os.path.join(config_dir, profile_path)

def get_firefox_addons(profile_path):
    # print("profile_path", profile_path)
    addons_file_path = os.path.join(profile_path, "extensions.json")

    if not os.path.exists(addons_file_path):
        raise FileNotFoundError("Could not find extensions.json file.")

    with open(addons_file_path, "r", encoding="utf-8") as file:
        addons_data = json.load(file)

    addons = []
    for addon in addons_data.get("addons", []):
        source_url = ""
        install_telemetry_info = addon.get("installTelemetryInfo")
        if install_telemetry_info:
            source_url = install_telemetry_info.get("sourceURL", "")

        location = addon.get("location", "")

        # 只导出用户安装的插件, 过滤应用内置插件
        if location == "app-profile":
            addons.append({
                "name": addon.get("defaultLocale", {}).get("name", ""),
                "version": addon.get("version", ""),
                "description": addon.get("defaultLocale", {}).get("description", "No description"),
                "manifestVersion": addon.get("manifestVersion", ""),
                "active": addon.get("active", False),
                "sourceURI": addon.get("sourceURI", ""),
                "sourceURL": source_url
            })

    return addons

def export_addons_to_file(addons, output_file):
    with open(output_file, "w") as file:
        enable_count = 0
        disable_count = 0

        enable_addons = """\n## Enabled Extensions\n"""
        disable_addons = """\n## Disabled Extensions\n"""

        for addon in addons:
            # 处理每个插件的信息
            name = addon.get("name", "No name")
            version = addon.get("version", "No version")
            description = addon.get("description", "No description")
            active = addon.get("active", False)
            source_uri = addon.get("sourceURI", "No source URI")
            source_url = addon.get("sourceURL", "No source URL")

            if active:
              enable_count = enable_count+1
              enable_addons += f"{enable_count}. [{name} {version}]({source_uri} \"{description}\")\n"
            else:
              disable_count = disable_count+1
              disable_addons += f"{disable_count}. [{name} {version}]({source_uri} \"{description}\")\n"

        file.write(enable_addons)
        file.write(disable_addons)

def main():
    try:
        profile_path = find_firefox_profile_path()
        addons = get_firefox_addons(profile_path)
        output_file = "firefox_addons.md"
        export_addons_to_file(addons, output_file)
        print(f"Exported Firefox addons to {output_file}")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    main()