A technique we use to visualise how Lateral recommendations would look and work on a website is to create a Chrome extension that inserts the recommendations at load time. This is useful because:
We often use extensions to insert recommendations into websites that don’t currently benefit from Lateral recommendations. An example is our
Wikipedia similar page Chrome extension. There are, however, many other applications for this type of extension, such as modifying the styling of a website, hiding an annoying element, auto-populating a form, or clicking something on page load.
In this blog post, I will create a Chrome extension that modifies this blog to set a custom background and to modify the HTML.
Side note: You may be thinking “Why not just use Userscripts?” which is a good question. The main reasons for using a Chrome extension are ease of installation and ease of updating. With Userscripts you’d first need to get the user to install a userscript manager. Then you’d need to get them to install the userscript. With Chrome, it’s as simple as clicking a button. Cross-browser compatibility is a valid concern which Userscripts solve (kind of) but so far, as we are primarily creating demos, targeting only Chrome has not been an issue for us.
So, the first thing to do is to create a folder to hold the chrome extension. This folder needs to contain a few files.
Chrome extensions require a file called the manifest. It’s a simple JSON file (named manifest.json) and is read by Chrome to understand what permissions the extension requires, which pages it should load on and things like the name and icons. Here’s a simple example for this application:
This is the stylesheet referenced by the manifest. All I want to do is to change the background of the blog to a simple pattern so my styles.css contains the following:
I changed the background to a GIF of a unicorn floating through space. Since the GIF has a dark background, I set a background colour and inverted the main content areas.
Note: Here I am loading the background image from giphy, but it’s entirely possible to load from the extension itself using the web_accessible_resources field of the manifest and this tip from StackOverflow.
Note #2: I’m using !important here to override the existing pages CSS. You could probably get around this using a more specific selector, but for demonstration purposes I’ll leave it at that.
Now we have everything in place, the extension folder should look something like this:
To install the extension, visit chrome://extensions in Chrome and drag the folder containing the above files into the window:
And now the Lateral blog looks like this:
Hopefully the extension you make will be a bit more meaningful. ¯\_(ツ)_/¯
How to create a VHD that is fully compatible with Azure from an Ubuntu Cloud Image base.
Build your own Give me five Chrome extension using our open source template, based on our popular NewsBot Chrome extension for recommending news.