以编程方式获取 Firefox 的最新版本号

问题描述 投票:0回答:3

如何以编程方式解析 Firefox 的版本号。

所以,我不必每次都访问该页面。 我所要做的就是运行脚本,它会给我最新的版本。

http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/update/win32/en-US/

该文件中始终包含“.complete.mar”。这是该目录下唯一带有“完整”字样的文件。 我如何从中解析版本“40.0.2”。

firefox updates mozilla auto-update
3个回答
5
投票

下载最新版本

简单的答案是Mozilla Release Engineering已经提供了下载最新版本的方法。请参阅https://ftp.mozilla.org/pub/firefox/releases/latest/README.txt

例如,我想下载最新的Linux 64位美国英语版本的Firefox。所以我会:

curl -Lo firefox.tar.bz2 'https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US'
tar -xjf firefox.tar.bz2
cd firefox
./firefox --version

请注意,这些是稳定版本,而不是 RC 版本或每晚版本。对于这些内容,请参阅相应子文件夹中的发行说明

备注:

  • curl
    命令 URL 用单引号 (
    '
    ) 括起来,以避免 bash 解释与符号 (
    &
    )。
  • 您可能希望将下载的 Firefox 添加到
    $PATH
    (或 Windows 中的
    %PATH%
    )环境变量的开头。

获取最新发布版本号

要在不下载存档的情况下获取最新版本号,您可以使用 HTTP

HEAD
方法(
curl -I
选项)。例如,

curl -fI 'https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US' | grep -o 'firefox-[0-9.]\+[0-9]'

它将返回类似

firefox-67.0.4
的内容。


0
投票

您将会遇到问题,因为您要检查的数据不在同一域内。

但是,您可以使用 Node Webkit(现在是 nwjs)之类的东西来突破浏览器限制。

  1. 要从以下链接开始下载适用于您的操作系统的nodewebkit文件:

http://nwjs.io/

  1. 提取内容。

  2. 下载JQuery并将其放在解压的文件夹中(将文件重命名为jquery.js)。

  3. 新建一个文本文件,添加以下内容并保存为package.json

package.json内容:

{
  "main": "index.html",
  "name": "firefoxversion",
  "version": "1",
  "window": {
    "title": "latest firefox version",
    "icon": "link.png",
    "toolbar": true,
    "width": 800,
    "height":600
   }
}

创建文件名为index.html并保存以下内容:

index.html内容:

<html>
    <head>
        <title>Latest Firefox Version</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>

        <div id="result"></div>




        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="main.js"></script>
    </body>
</html>
  1. 接下来创建一个名为 main.js 的文件并保存以下内容:

main.js 内容:

var url ="http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/update/win32/en-US/";


var version;

$.get(url,function(data){//begin function


$(data).contents().find("a").each(function(){//begin each function


//create an array to hold the hmtl
var html = [];


if($(this).attr("href").indexOf("complete.mar" !== -1 )){//begin if then


version = $(this).attr("href").split(".c");


//start building your html to output
html.push("Download the latest Firefox Version " + version[0] + " below:<br>");

//add the download button
html.push("<input type ='button' id ='firefox-latest' value = 'Download Firefox'>");


//display the html in the #result div
$("#result").html(html.join(""));


}//end if then


});//end each function




});//end function

//on click event for #firefox-latest
$(document).on("click","#firefox-latest",function(){//begin on click event

//change the window location to the file for the latest firefox version
window.location.href = url + version[0] + ".complete.mar";


});//end on click event
  1. 最后单击您之前解压的文件夹中的 nw.exe 图标 你应该会看到 Firefox 的最新版本号。

0
投票

我使用这个 json 响应来获取最新版本的 Firefox

https://product-details.mozilla.org/1.0/firefox_history_major_releases.json

此脚本将其记录到控制台并显示在网页上...

<script>
document.addEventListener('DOMContentLoaded', function() {
  async function getLatestFirefoxRelease() {
    const response = await fetch('https://product-details.mozilla.org/1.0/firefox_history_major_releases.json');
    const data = await response.json();
    const latestRelease = Object.keys(data).pop();
    const latestReleaseDate = data[latestRelease];
    return { version: latestRelease, date: latestReleaseDate };
  }

  getLatestFirefoxRelease().then(result => {
    console.log(`Latest Firefox release: version ${result.version}, released on ${result.date}`);
    document.getElementById("firefox-version").innerText = `Latest Firefox release is ${result.version} released on ${result.date} - ${hasFF}`;
  });
});

</script>
© www.soinside.com 2019 - 2024. All rights reserved.