我有一个 Google Chrome 打包应用程序,我想根据其 list 文件更新该应用程序的“关于”页面上的版本号。我的 list 文件如下所示:
list .json
{
"manifest_version": 2,
"name": "Book Writer",
"version": "2.0.8.0",
"icons": {
"16": "images/Book-icon.png",
"48": "images/Book-icon.png",
"128": "images/Book-icon.png"
},
"app": {
"background": {
"scripts": ["main.js"]
}
},
"permissions": [
"storage",
"contextMenus"
]
}
重要部分是"version": "2.0.8.0",
我的关于页面的结构如下:
about.html
<!DOCTYPE html>
<head>
<title>about</title>
<link rel="stylesheet" type="text/css" href="/css/about.css">
</head>
<body>
<h1 class="main-header">book writer v 2.0.8.0</h1>
<h2 class="sub-header">This game was made by: Dragonloverlord</h2>
<h2 class="sub-header">LICENSE</h2>
<div class="license-div">
<code>
The MIT License (MIT)<br>
<br>
Copyright (c) 2014 dragonloverlord<br>
<br>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:<br>
<br>
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.<br>
<br>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.<br>
</code>
</div>
</body>
</html>
如果我无法直接从 list 文件更新它,那么是否有一个符合 angularjs csp 标准的方法来更新单个变量的数量,所以我所要做的就是将脚本链接到应用程序中需要的任何页面版本号更新了吗?
最佳答案
您可以直接从 list 更新:这就是chrome.runtime.getManifest API 是为了。
在纯 JavaScript 中,您可以执行以下操作:
document.addEventListener('DOMContentLoaded', function () {
manifest = chrome.runtime.getManifest();
document.querySelector('h1.main-header').innerHTML = "book writer v " + manifest.version;
});
关于javascript - 如何动态更新chrome应用程序的版本号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26653361/