Convert links from OneTab Export to Netscape Bookmarks format

· forensicks's blog


If you are using the OneTab browser extension to manage your bookmarks, paste this JavaScript snippet in your browser's DevTools Console.

  1. Ensure OneTab is installed and the extension is enabled

  2. Open a new tab / right-click on any ordinary web page – example: https://example.com

  3. Select OneTab > Display OneTab

  4. Tap the link for Export / Import URLs
    or visit this URL if you're using Firefox: moz-extension://a0ae60b2-97a6-40b8-8411-3a8952194fed/onetab.html

  5. In the textbox below Export URLs, search-and-remove any links that might be sensitive or that you want excluded in the export — example:

    
    https://airtable.com/appoN2eAgiMPe5loXb | Confidential Plans for World Domaination
    
    
  6. Copy-and-paste the JavaScript code below into your browser's Developer Tools > Console

 1(function downloadOneTabExport() {
 2  function fileSave(data, filenamePrefix) {
 3    if (!data) {
 4      throw new Error("Missing data");
 5    }
 6
 7    const printableDate = new Date().toLocaleDateString(new Date(), {
 8      year: "numeric",
 9      month: "long",
10      day: "numeric",
11      hour: "2-digit",
12      minute: "2-digit",
13      second: "2-digit",
14    });
15    const dateTimeSafe = new Date()
16      .toJSON()
17      .replace(":", ".")
18      .replace("T", "__");
19    const filename = `${filenamePrefix}__${dateTimeSafe}.html`;
20
21    const outputChunks = [
22      `<!DOCTYPE NETSCAPE-Bookmark-file-1>
23<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
24<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'none'; img-src data: *; object-src 'none'"></meta>
25<TITLE>Bookmarks ${printableDate}</TITLE>
26<H1>Bookmarks ${printableDate}</H1>
27<DL><p>
28`,
29    ];
30
31    const DELIMETER = " | ";
32    data
33      .split("\n")
34      .filter(Boolean)
35      .forEach((line) => {
36        let input = (line || "").replace(/\s+/g, " ").trim();
37        input = input.replace(/[^\x20-\x7E]/g, "");
38
39        if (!input || !input.startsWith("http")) {
40          return;
41        }
42
43        const chunks = input.split(DELIMETER, 1);
44        const link = (chunks?.[0] || "").trim();
45        const title = input.substr(link.length + DELIMETER.length).trim();
46        console.log({ title, link });
47        outputChunks.push(`
48  <DT><A HREF="${link}">${title}</A></DT>
49`);
50      });
51
52    const mimeType = "text/html";
53
54    const blob = new Blob([outputChunks.join("\n")], { type: mimeType });
55    const evt = document.createEvent("MouseEvents");
56    const link = document.createElement("a");
57    link.download = filename;
58    link.href = window.URL.createObjectURL(blob);
59    link.dataset.downloadurl = [mimeType, link.download, link.href].join(":");
60    evt.initMouseEvent(
61      "click",
62      true,
63      false,
64      window,
65      0,
66      0,
67      0,
68      0,
69      0,
70      false,
71      false,
72      false,
73      false,
74      0,
75      null
76    );
77    link.dispatchEvent(evt);
78  }
79
80  const contents = document.querySelector("textarea:last-child")?.value || "";
81  fileSave(contents, "bookmarks_OneTab_export");
82})();

P.S. For more info on OneTab, visit their Help pages.