Spotify open in app

This userscript redirects open.spotify.com links to the desktop app

As of 2018-02-26 11:29:51 UTC. See the latest version.

// ==UserScript==
// @name         Spotify open in app
// @description  This userscript redirects open.spotify.com links to the desktop app
// @version      1.0
// @match        http://open.spotify.com/*
// @match        https://open.spotify.com/*
// @namespace https://greasyfork.org/users/172431
// ==/UserScript==

(function() {
    'use strict';
    var data=document.URL.match(/[\/\&](track|playlist|album|artist)\/([^\&\#\/\?]+)/i);
    console.log("This is a "+data[1]+" with id:"+data[2]+"\nAttempting to redirect");
    window.location.replace('spotify:'+data[1]+':'+data[2]);
})();