gpt4 book ai didi

google-chrome - 在 Chrome 中从用户脚本转换时保持相同的 ID

转载 作者:行者123 更新时间:2023-12-02 22:33:51 24 4
gpt4 key购买 nike

我目前正在将用户脚本更新为 chrome 扩展程序,但由于新 ID 不同,它不会更新旧扩展程序,而是添加一个新扩展程序。

有没有办法将用户脚本转换为 Chrome 扩展并保持相同的 ID?

由于用户脚本没有 key 文件,我认为这是可能的,
但是如何呢?

最佳答案

用户脚本在您加载时会转换为 Chrome 扩展程序。按照以下步骤创建和维护具有相同 ID 的扩展程序:

  1. 安装用户脚本。
  2. 访问chrome://extensions/并激活开发者模式。
  3. 向下滚动到您的用户脚本,找到 ID: Userscript 1.0 Description of user script ID: hjcgfecgldpgebeeflnjldogphkilfdo
    请注意,您的用户脚本版本为 1.0(默认情况下,通过 @version 覆盖)。
  4. 接下来,访问您的 Chrome/Chromium 用户配置文件的扩展程序目录。可以找到默认路径 here .如果您使用 --user-data-dir=... 启动 Chrome/chromium标志,然后访问... .
    进入目录后,查找 ID 为 3 的目录。
  5. 将整个目录复制到不同位置,例如/tmp/%tmp% .
  6. 使用“加载解压扩展”按钮,并选择先前复制目录的第一个子目录:此子目录的名称基于版本。
  7. 向下滚动以查看转换后的用户脚本是真正的扩展(加载!):
    Userscript 1.0 Description of user script ID: hjcgfecgldpgebeeflnjldogphkilfdo Loaded from: /tmp/hjcgfecgldpgebeeflnjldogphkilfdo/1.0_0

好的,步骤 6-7 是可选的,它们只是为了表明用户脚本已转换为真正的扩展,并设置了特殊标志。您还可以注意到有关 manifest version 的红色警告.要解决这个问题,请编辑 manifest.json , 并添加 "manifest_version": 2, .所以,在我们的例子中:

    ...<br/>
    "converted_from_user_script": true,<br/>
    "description": "Description of user script",<br/>
    "key": "eYxnPzfSPtfL3ji4nQX3ujTXpzz3YQ6dVlvHWf1gvW8=",<br/>
    "name": "Userscript",<br/>
    "version": "1.0",<br/>
    <strong>"manifest_version": 2</strong><br/>
}

现在,您已经有了一个 Chrome 扩展程序,它的行为类似于带有 some extra flavour 的 Chrome 扩展程序。 .按照官方文档中的步骤更新您的包:

Updating a package

To create an updated version of your extension:

  1. Increase the version number in manifest.json.
  2. Bring up the Extensions management page by going to this URL: chrome://extensions
  3. Click the Pack extension button. A dialog appears.
  4. In the Extension root directory field, specify the path to the extension's folder—for example, c:\myext.
  5. In the Private key file field, specify the location of the already generated .pem file for this extension—for example, c:\myext.pem.
  6. Click OK.

Uploading a previously packaged extension to the Chrome Web Store

You can use the Chrome Developer Dashboard to upload an extension that you've previously packaged yourself. However, unless you take special steps, the extension's ID in the Chrome Web Store will be different from its ID in the package you created. This different ID might be a problem if you've distributed your extension package, because it allows users to install multiple versions of your extension, each with its own local data.

If you want to keep the extension ID the same, follow these steps:

  1. Rename the private key that was generated when you created the .crx file to key.pem.
  2. Put key.pem in the top directory of your extension.
  3. Compress that directory into a ZIP file.
  4. Upload the ZIP file using the Chrome Developer Dashboard.

附录:在解压/打包扩展中保持相同的ID。

扩展的 extensionID 可以通过 "key" parameter in the manifest file 控制.文档中还说明了使解压和打包扩展具有相同 ID 的最简单方法:

key This value can be used to control the unique ID of an extension, app, or theme when it is loaded during development.

Note: You don't usually need to use this value. Instead, write your code so that the key value doesn't matter by using relative paths and chrome.extension.getURL().

要获得合适的键值,首先从 .crx 安装您的扩展 文件(您可能需要 upload your extensionpackage it manually )。 然后,在你的 user data directory ,查看文件 Default/Extensions/<extensionId>/<versionString>/manifest.json .你 会看到填入的键值。

key字段不存在,它是随机生成的。然后,extensionID 是从这个 key 生成的。生成extensionID的算法是explained here .根据算法的性质,您不能以相反的顺序执行它 (extensionID -> key )。

关于google-chrome - 在 Chrome 中从用户脚本转换时保持相同的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11772308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com