X
Tap here to go to the mobile version of the site.

Support Forum

Tools for working with search engines

Posted

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].

Modified by ZeroUnderscoreOu

Chosen solution

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/
Read this answer in context 1

Additional System Details

Installed Plug-ins

  • Shockwave Flash 25.0 r0

Application

  • User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0

More Information

jscher2000
  • Top 10 Contributor
6916 solutions 56461 answers

Helpful Reply

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!

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!

Question owner

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.

''jscher2000 [[#answer-961296|said]]'' <blockquote> By any chance did you get an email notification with that information from the other site? </blockquote> Good hint! I actually did, sadly, the part regarding decompression [https://support.mozilla.org/t5/Firefox/DEcompressed-jsonlz4/m-p/1231172 was on this forum] and is also removed.
jscher2000
  • Top 10 Contributor
6916 solutions 56461 answers

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);
 }
}
'''''Is this the one you wanted?''''' <p>It is just a matter of opening the <b>about:config</b> 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).<br> Then if you open the Browser Console then you should see a command line at the bottom of the Browser Console window.<br> 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.<br> There is no need to fully understand how this code works.<br> 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.<br> It will show a message to what file the decompressed file has been saved. </p> <ul><li>https://support.mozilla.org/questions/1071533 </li></ul> <pre>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() &amp;&amp; file.isFile() &amp;&amp; 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); } }</pre>

Question owner

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).

''jscher2000 [[#answer-961389|said]]'' <blockquote> '''''Is this the one you wanted?''''' </blockquote> That's close, but doesn't work (for me "Components" has only "interfaces" property)(also, forum seems to insert "<wbr>" in the code).

Modified by ZeroUnderscoreOu

jscher2000
  • Top 10 Contributor
6916 solutions 56461 answers

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

Hopefully the correct code will emerge from cor-el's big bag of tricks...
cor-el
  • Top 10 Contributor
  • Moderator
15848 solutions 143369 answers

Chosen Solution

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/
That would be this code to run in the Browser Console (i.e. NOT in the Web Console) as this is XUL. <pre><nowiki>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); } } } });</nowiki></pre> ---- (https://support.mozilla.org/t5/Firefox/Search-engines-reset/m-p/1375515) <blockquote><pre>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/</pre></blockquote>

Modified by cor-el

Question owner

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.

''cor-el [[#answer-961442|said]]'' <blockquote> That would be this code to run in the Browser Console (i.e. NOT in the Web Console) as this is XUL. </blockquote> That's what was my mistake - running it in Web Console.