My Technical Notes

Friday, 22 January 2016

*.url path handler in Chrome

Internet Explorer stores its favourites in the file system, with each link being a separate file.

In order to allow ourselves to access the same bookmarks within Firefox, we first navigate to favourites folder `file:///.../Favourites/` Within there, we can click on the `*.url` file links.

However, Chrome does not handle `*.url` files in the same way. It displays the textual contents of the `.url` file rather than following its URL. The solution is to implement a Tampermonkey script handling URLs ending in `.url`.

But first we must allow Tampermonkey access to the local file URLs. Below is the user script that handles `*.url` file extensions:


// ==UserScript==
// @name         *.url File Handler
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       Tahir Hassan
// @match        file:///*/*.url
// @require      https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js
// @grant        none
// ==/UserScript==
/* jshint -W097 */
'use strict';

var lines = $('pre').html().match(/[^\r\n]+/g);
$('pre').hide();

var urlKeyNames = ['URL', 'BASEURL'];
lines.forEach(function(line) {
    urlKeyNames.forEach(function(keyName) {
        if (line.startsWith(keyName + '=')) {
            var url = line.replace(keyName + '=', '');
            window.location.replace(url);
        }
    });
});

No comments: