diff --git a/chrome/background.js b/chrome/background.js new file mode 100644 index 0000000..88d5f8f --- /dev/null +++ b/chrome/background.js @@ -0,0 +1,52 @@ +"use strict"; + +chrome.runtime.onInstalled.addListener(function() { + chrome.declarativeContent.onPageChanged.removeRules(undefined, function() { + chrome.declarativeContent.onPageChanged.addRules([ + { + conditions: [ + new chrome.declarativeContent.PageStateMatcher({ + pageUrl: { hostEquals: 'play.google.com', pathPrefix: "/music" }, + }), + new chrome.declarativeContent.PageStateMatcher({ + pageUrl: { hostEquals: 'itunes.apple.com', pathPrefix: "/music" }, + }), + new chrome.declarativeContent.PageStateMatcher({ + pageUrl: { hostSuffix: 'spotify.com' }, + }), + new chrome.declarativeContent.PageStateMatcher({ + pageUrl: { hostSuffix: 'beatsmusic.com' }, + }), + new chrome.declarativeContent.PageStateMatcher({ + pageUrl: { hostSuffix: 'deezer.com' }, + }), + new chrome.declarativeContent.PageStateMatcher({ + pageUrl: { hostSuffix: 'rdio.com' }, + }), + new chrome.declarativeContent.PageStateMatcher({ + pageUrl: { hostSuffix: 'rd.io' }, + }), + ], + + actions: [ new chrome.declarativeContent.ShowPageAction() ] + } + ]); + }); +}); + +chrome.pageAction.onClicked.addListener(function(tab) { + var params = "url=" + encodeURI(tab.url); + var xhr = new XMLHttpRequest(); + xhr.open("POST", "https://match.audio/search", true); + xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + var parser = document.createElement('a'); + parser.href = xhr.responseURL; + if (!parser.pathname.match(/^(\/search|\/)$/)) { + chrome.tabs.create({ url: xhr.responseURL}); + } + } + } + xhr.send(params); +}); diff --git a/chrome/icon-128.png b/chrome/icon-128.png new file mode 100644 index 0000000..cce2744 Binary files /dev/null and b/chrome/icon-128.png differ diff --git a/chrome/icon-16.png b/chrome/icon-16.png new file mode 100644 index 0000000..24e56d5 Binary files /dev/null and b/chrome/icon-16.png differ diff --git a/chrome/icon-48.png b/chrome/icon-48.png new file mode 100644 index 0000000..a516bc4 Binary files /dev/null and b/chrome/icon-48.png differ diff --git a/chrome/manifest.json b/chrome/manifest.json new file mode 100644 index 0000000..7d5148c --- /dev/null +++ b/chrome/manifest.json @@ -0,0 +1,23 @@ +{ + "name" : "Match Audio", + "version" : "0.2.0", + "description" : "Match Audio makes sharing from music services better.", + "background" : { + "persistent": false, + "scripts": [ "background.js" ] + }, + "page_action" : { + "default_icon": { + "16": "icon-16.png", + "48": "icon-48.png", + "128": "icon-128.png" + } + }, + "permissions" : [ "declarativeContent", "https://match.audio/" ], + "icons": { + "16": "icon-16.png", + "48": "icon-48.png", + "128": "icon-128.png" + }, + "manifest_version": 2 +} diff --git a/chrome/screenshot-1.jpg b/chrome/screenshot-1.jpg new file mode 100644 index 0000000..c3710ab Binary files /dev/null and b/chrome/screenshot-1.jpg differ