paint-brush
A Bibliography Generator From Browser Bookmarks: How It Worksby@bobnoxious
1,293 reads
1,293 reads

A Bibliography Generator From Browser Bookmarks: How It Works

by Bob WrightNovember 27th, 2023
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

A simple bibliography generator uses a Browser Bookmarks file as its source content. The database itself is actually a JSON object file which we may save and use locally. This gets me the same set of bookmarks on Chrome and Edge and Firefox for example without having the browser save my bookmark data. We edit the bookmarks folder to extract the only bookmarks we want to use.

People Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - A Bibliography Generator From Browser Bookmarks: How It Works
Bob Wright HackerNoon profile picture

A simple bibliography generator that uses a JSON Browser Bookmarks file as its source content.

Prerequisites and Code

The first requirement for the bibliography generator’s operation is a source of its content data which consists of a JSON object created by a browser bookmark manager application named xbrowserSync. This application is a browser-agnostic bookmark manager in two parts.


One part is a browser extension, and the other is a server API that manages the bookmark data as a MongoDB data file. All we need to know about the server API is its URL. The browser extension can be found in online app “stores” like Google Play for the Chrome browser.


The basic idea is that the xbrowserSync application stores your bookmark data in an encrypted database which is stored on the API server. The database itself is actually a JSON object file that we may save and use locally, and which may be used by any browser that has our application extension appropriately installed.


This gets me the same set of bookmarks on Chrome, Edge, and Firefox, for example, without having the browser save my bookmark data. The APP and the API source for xbrowserSync are each in a GitHub repository.


The second requirement for the bibliography generator is its program code which runs under node.js in a Command Window on my Windows 10 machine. Here following, is this simple node program named handler.js.

#!/usr/bin/env node
// ---------------------------------
// Simple bibliography file handler Node Server API
// ---------------------------------
const fs = require('fs')
const path = require('path')
//const dn = require('./dirname');

var filePath = './bibliotest.json'; //the biblio bookmark file
var biblio = '';
var str = '';
var searchValue = 'url:';

// --------------
// read and parse biblio JSON file
// ----------------
const jsonReader = () => {
return new Promise(resolve => {
  str = fs.readFile(filePath, (err, fd) => {
    object = JSON.parse(fd);
    str = object.children; // strip outer layer
    biblio = str;
    // count biblio array elements
    count = biblio.length;
    resolve (str);
    //return str;
  })
})
}
//
async function performAsyncFunctions(){
// list of promises to execute sequentially
const firstRequest = await jsonReader();

    //console.log('\nAll tasks complete.');
    console.log('====  function complete ====\n')
    console.log('count = ', count)
    var html = '<html><lang = en><head></head><body>';
for (let i = 0; i < count; i++) {
  html = html + '<h3><i>id'+[i]+':</i>&nbsp;<a href='+biblio[i].url+'>'+biblio[i].title+'</a></h3><p>'+biblio[i].description+'</p>\n';
}
html = html + '</body></html>';
console.info(html);
const content = html
try {
const data = fs.writeFileSync('./bibliotest.html', content)
//file written successfully
} catch (err) {
console.error(err)
}}

// ---------------
performAsyncFunctions();
    // console.log('biblio = ', object)
// ------------------


The JSON Format Bookmark File

From the xbrowserSync browser extension menu, we can elect to save a backup of our bookmarks’ data. The backup is saved as a JSON file. For our example here, all of the bookmarks are in a bookmarks folder named “MuskArticle.”


We edit the bookmarks JSON to extract only the bookmarks folder we want to use in our bibliography. This JSON file is shown here next below.

{
    "title": "__MuskArticle",
    "children": [
      {
        "title": "Musk's X caught throttling outbound links to websites he doesn't like",
        "url": "https://www.msn.com/en-us/news/technology/musk-s-x-caught-throttling-outbound-links-to-websites-he-doesn-t-like/ar-AA1fmbYw?ocid=windirect&cvid=3ff1100b6fba4172b3b0b8b9c6bbc7e0&ei=185",
        "description": "Elon Musk claims that he bought Twitter, now called X, to preserve free speech. He claimed that everyone’s voice should be heard. This is a great thing for free speech and must surely be a coincidence, right? Elon Musk's X was this week caught throttling outbound links to several sites, coincidentally ones that the billionaire has complained about or feuded with in the past.… Links directing users of the website formerly…",
        "id": 6643
      },
      {
        "title": "Mark Cuban takes another jab at Elon Musk's business practices",
        "url": "https://www.msn.com/en-us/money/companies/mark-cuban-takes-another-jab-at-elon-musk-s-business-practices/ar-AA1fmrNQ?ocid=windirect&cvid=528ef4be846842fa87342b96d92d0dfa&ei=35",
        "description": "These two billionaires are not best buds.",
        "id": 6664
      },
      {
        "title": "Twitter now makes you PAY to access one of its most popular features",
        "url": "https://www.msn.com/en-us/money/technology/twitter-now-makes-you-pay-to-access-one-of-its-most-popular-features/ar-AA1flk5Y?ocid=windirect&cvid=ee4ba03e4c414849a910c7f25dbfd759&ei=27",
        "description": "X (formerly Twitter) has started diverting users to a paid-subscription sign-up page when they try to access TweetDeck.",
        "id": 6665
      },
      {
        "title": "NYU Professor Locked Out of Twitter After Reportedly Declining to Meet With Elon Musk",
        "url": "https://www.msn.com/en-us/news/technology/nyu-professor-locked-out-of-twitter-after-reportedly-declining-to-meet-with-elon-musk/ar-AA1fmedB?ocid=windirect&cvid=a7973a74a0d24f2287ea421bbd70f5ea&ei=42",
        "description": "New York University professor and Kara Swisher’s podcasting buddy Scott Galloway voiced his outrage at being banned from posting on Twitter in a Threads post on Tuesday. Galloway claims he’s been locked out of Twitter (aka X) two days after allegedly declining an invitation to meet with the chief…",
        "id": 6666
      },
      {
        "title": "A federal judge wondered if Elon Musk was trying to 'cozy up' to Trump by trying to inform him about a search warrant into his social media account",
        "url": "https://www.msn.com/en-us/news/politics/a-federal-judge-wondered-if-elon-musk-was-trying-to-cozy-up-to-trump-by-trying-to-inform-him-about-a-search-warrant-into-his-social-media-account/ar-AA1flSZV?ocid=windirect&cvid=ee4ba03e4c414849a910c7f25dbfd759&ei=51",
        "description": "In January, federal prosecutors obtained a search warrant to obtain information from Trump's personal Twitter account.",
        "id": 6667
      }
    ]
  }


The Bibliography File

If we submit the JSON file above to our node.js handler program, it will generate the following HTML format bibliography listing.


Conclusion

So, we have seen how we may leverage the use of xbrowserSync as a bookmarks manager to generate bibliographies from our bookmarks data. Thanks for reading, and hope this information is useful to you. As always, comments, suggestions, and criticisms are welcomed.