为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

Tools for working with search engines

more options

Hi everyone once again.

I asked a similar question a week ago, and got a relevant answer from cor-el, but now with "system changes" to the forum it seems gone.

Remind me please, how do I open *.mozlz4 files and how do I import search engines through *.xml files? Thanks in advance.


In case someone would need this: XML Search Engines Exporter/Importer.

Hi everyone once again. I asked a similar question a week ago, and got a relevant answer from cor-el, but now with "system changes" to the forum it seems gone. Remind me please, how do I open *.mozlz4 files and how do I import search engines through *.xml files? Thanks in advance. <HR> In case someone would need this: [https://addons.mozilla.org/ru/firefox/addon/search-engines-export-import/ XML Search Engines Exporter/Importer].

由ZeroUnderscoreOu于修改

被采纳的解决方案

That would be this code to run in the Browser Console (i.e. NOT in the Web Console) as this is XUL.

var {classes:Cc,interfaces:Ci,utils:Cu} = Components;
function decompressFile(oFilePath,nFilePath){
  Cu.import("resource://gre/modules/Task.jsm");
  Cu.import("resource://gre/modules/osfile.jsm");
  return Task.spawn(function* () {
    var jsonString = yield OS.File.read(oFilePath,{compression:"lz4"});
    yield OS.File.writeAtomic(nFilePath, jsonString);})
}
// Set up file chooser
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
var fu = Cu.import("resource://gre/modules/FileUtils.jsm").FileUtils
fp.init(window, "Open File", Ci.nsIFilePicker.modeOpen);
fp.appendFilter("Bookmarks/Session (.jsonlz4)","*.jsonlz4");
fp.appendFilter("Search Engines (.mozlz4)","*.mozlz4");
fp.appendFilter("Add-ons Files (.lz4)","*.lz4");
fp.displayDirectory = fu.File(OS.Path.join(OS.Constants.Path.profileDir, "sessionstore-backups"));
// Call file chooser
fp.open((aResult) => {
  if (aResult == Ci.nsIFilePicker.returnOK) {
  if (fp.file.exists() && fp.file.isFile() && fp.file.isReadable()) {
    var oldfile = fp.file.path;
    var newfile = oldfile + ".json"; // Construct output file name
    try {
      decompressFile(oldfile, newfile);
      console.log("Saved as: \"" + newfile + "\"");
      if(confirm("Open JSON file in a Firefox tab?")){
        var uri="file:///"+newfile.replace(/\\/g, "/");
        window.open(uri, "_blank");
      }
    }
    catch (err) {
      console.log(err);
    }
  }
  }
});

(https://support.mozilla.org/t5/Firefox/Search-engines-reset/m-p/1375515)

You only need to decompress the search.json.mozlz4 file to make its content visible.
It is compressed the same way as the compressed .jsonlz4 bookmark backups.
See:
https://support.mozilla.org/t5/Firefox/DEcompressed-jsonlz4/m-p/1231172
You need to add/modify a line for the *.mozlz4 file extension.
* fp.appendFilter("Search Engines Files","*.mozlz4");
The file contains hashes, so you can't modify this file.
You can't add a search engine that has the same name as a built-in search engine and DuckDuckGo is a built-in search engine as you can see if you inspect the built-in engines via this chrome URI.
* chrome://browser/locale/searchplugins/

XML Search Engines Exporter/Importer:
* https://addons.mozilla.org/firefox/addon/search-engines-export-import/
定位到答案原位置 👍 1

所有回复 (7)

more options

By any chance did you get an email notification with that information from the other site? If not, hopefully cor-el will find your question again!

more options

jscher2000 said

By any chance did you get an email notification with that information from the other site?

Good hint! I actually did, sadly, the part regarding decompression was on this forum and is also removed.

more options

Is this the one you wanted?

It is just a matter of opening the about:config page via the location/address bar like you open a website and you its search bar to locate the devtools.chrome.enabled pref and sets its value to true with a double-click if its current value is false (default).
Then if you open the Browser Console then you should see a command line at the bottom of the Browser Console window.
On this command line you can paste the code to decompress the compressed .jsonlz4 file and press the enter key to evaluate (run) this JavaScript code.
There is no need to fully understand how this code works.
The below posted code when evaluated in the Browser Console will open a file picker window that allows to browse to a compressed .jsonlz4 and select this file for decompression.
It will show a message to what file the decompressed file has been saved.

var {classes:Cc,interfaces:Ci,utils:Cu} = Components;
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.<wbr>nsIFilePicker);
fp.init(window, "Open File", Ci.nsIFilePicker.modeOpen);
fp.appendFilter("Bookmark Backup Files", "*.jsonlz4");
if (fp.show() == Ci.nsIFilePicker.returnOK) {
 var file = fp.file;
 if (file.exists() && file.isFile() && file.isReadable()) {
  var oldFile = fp.file.path;
  var newFile = oldFile.replace(".jsonlz4", ".json");
  Cu.import("resource://gre/modules/Task.jsm");
  Cu.import("resource://gre/modules/osfile.jsm");
  function decompressBookmarksFile(oFilePath,nFilePath){retur<wbr>n Task.spawn(function* () {var jsonString = yield OS.File.read(oFilePath,{ compression: "lz4" });yield OS.File.writeAtomic(nFilePath, jsonString);})}
  decompressBookmarksFile(oldFile,newFile);
  console.log("Saved as: "+ newFile);
 }
}
more options

jscher2000 said

Is this the one you wanted?

That's close, but doesn't work (for me "Components" has only "interfaces" property)(also, forum seems to insert "<wbr>" in the code).

由ZeroUnderscoreOu于修改

more options

Hopefully the correct code will emerge from cor-el's big bag of tricks...

more options

选择的解决方案

That would be this code to run in the Browser Console (i.e. NOT in the Web Console) as this is XUL.

var {classes:Cc,interfaces:Ci,utils:Cu} = Components;
function decompressFile(oFilePath,nFilePath){
  Cu.import("resource://gre/modules/Task.jsm");
  Cu.import("resource://gre/modules/osfile.jsm");
  return Task.spawn(function* () {
    var jsonString = yield OS.File.read(oFilePath,{compression:"lz4"});
    yield OS.File.writeAtomic(nFilePath, jsonString);})
}
// Set up file chooser
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
var fu = Cu.import("resource://gre/modules/FileUtils.jsm").FileUtils
fp.init(window, "Open File", Ci.nsIFilePicker.modeOpen);
fp.appendFilter("Bookmarks/Session (.jsonlz4)","*.jsonlz4");
fp.appendFilter("Search Engines (.mozlz4)","*.mozlz4");
fp.appendFilter("Add-ons Files (.lz4)","*.lz4");
fp.displayDirectory = fu.File(OS.Path.join(OS.Constants.Path.profileDir, "sessionstore-backups"));
// Call file chooser
fp.open((aResult) => {
  if (aResult == Ci.nsIFilePicker.returnOK) {
  if (fp.file.exists() && fp.file.isFile() && fp.file.isReadable()) {
    var oldfile = fp.file.path;
    var newfile = oldfile + ".json"; // Construct output file name
    try {
      decompressFile(oldfile, newfile);
      console.log("Saved as: \"" + newfile + "\"");
      if(confirm("Open JSON file in a Firefox tab?")){
        var uri="file:///"+newfile.replace(/\\/g, "/");
        window.open(uri, "_blank");
      }
    }
    catch (err) {
      console.log(err);
    }
  }
  }
});

(https://support.mozilla.org/t5/Firefox/Search-engines-reset/m-p/1375515)

You only need to decompress the search.json.mozlz4 file to make its content visible.
It is compressed the same way as the compressed .jsonlz4 bookmark backups.
See:
https://support.mozilla.org/t5/Firefox/DEcompressed-jsonlz4/m-p/1231172
You need to add/modify a line for the *.mozlz4 file extension.
* fp.appendFilter("Search Engines Files","*.mozlz4");
The file contains hashes, so you can't modify this file.
You can't add a search engine that has the same name as a built-in search engine and DuckDuckGo is a built-in search engine as you can see if you inspect the built-in engines via this chrome URI.
* chrome://browser/locale/searchplugins/

XML Search Engines Exporter/Importer:
* https://addons.mozilla.org/firefox/addon/search-engines-export-import/

由cor-el于修改

more options

cor-el said

That would be this code to run in the Browser Console (i.e. NOT in the Web Console) as this is XUL.

That's what was my mistake - running it in Web Console.