2015-12-01 10:57:56 +00:00
|
|
|
const apiUrl = 'https://match.audio';
|
2014-12-07 22:06:08 +00:00
|
|
|
|
2015-12-01 10:57:56 +00:00
|
|
|
chrome.runtime.onInstalled.addListener(() => {
|
|
|
|
chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {
|
2014-12-07 22:06:08 +00:00
|
|
|
chrome.declarativeContent.onPageChanged.addRules([
|
|
|
|
{
|
|
|
|
conditions: [
|
2015-01-12 22:54:44 +00:00
|
|
|
new chrome.declarativeContent.PageStateMatcher({
|
2015-12-01 10:57:56 +00:00
|
|
|
pageUrl: { hostEquals: 'www.deezer.com', pathPrefix: '/album' },
|
2015-01-12 22:54:44 +00:00
|
|
|
}),
|
|
|
|
new chrome.declarativeContent.PageStateMatcher({
|
2015-12-01 10:57:56 +00:00
|
|
|
pageUrl: { hostEquals: 'www.deezer.com', pathPrefix: '/track' },
|
2015-01-12 22:54:44 +00:00
|
|
|
}),
|
|
|
|
new chrome.declarativeContent.PageStateMatcher({
|
2015-12-01 10:57:56 +00:00
|
|
|
pageUrl: { hostEquals: 'play.google.com', pathPrefix: '/music' },
|
2014-12-07 22:06:08 +00:00
|
|
|
}),
|
|
|
|
new chrome.declarativeContent.PageStateMatcher({
|
2015-12-01 10:57:56 +00:00
|
|
|
pageUrl: { hostEquals: 'itunes.apple.com', pathPrefix: '/music' },
|
2014-12-07 22:06:08 +00:00
|
|
|
}),
|
|
|
|
new chrome.declarativeContent.PageStateMatcher({
|
2015-01-12 22:54:44 +00:00
|
|
|
pageUrl: { hostSuffix: 'rdio.com' },
|
2014-12-07 22:06:08 +00:00
|
|
|
}),
|
|
|
|
new chrome.declarativeContent.PageStateMatcher({
|
2015-12-01 10:57:56 +00:00
|
|
|
pageUrl: { hostSuffix: 'spotify.com', pathPrefix: '/album' },
|
2014-12-07 22:06:08 +00:00
|
|
|
}),
|
|
|
|
new chrome.declarativeContent.PageStateMatcher({
|
2015-12-01 10:57:56 +00:00
|
|
|
pageUrl: { hostSuffix: 'spotify.com', pathPrefix: '/track' },
|
2014-12-07 22:06:08 +00:00
|
|
|
}),
|
|
|
|
new chrome.declarativeContent.PageStateMatcher({
|
2015-12-01 10:57:56 +00:00
|
|
|
pageUrl: { hostEquals: 'music.microsoft.com', pathPrefix: '/track' },
|
2014-12-07 22:06:08 +00:00
|
|
|
}),
|
|
|
|
new chrome.declarativeContent.PageStateMatcher({
|
2015-12-01 10:57:56 +00:00
|
|
|
pageUrl: { hostEquals: 'music.microsoft.com', pathPrefix: '/album' },
|
2015-01-12 22:54:44 +00:00
|
|
|
}),
|
|
|
|
new chrome.declarativeContent.PageStateMatcher({
|
|
|
|
pageUrl: { hostSuffix: 'youtube.com' },
|
|
|
|
}, [])
|
2014-12-07 22:06:08 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
actions: [ new chrome.declarativeContent.ShowPageAction() ]
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
chrome.pageAction.onClicked.addListener(function(tab) {
|
2015-12-01 10:57:56 +00:00
|
|
|
chrome.pageAction.setIcon({tabId: tab.id, path: 'icon-blue-128.png'}, () => {
|
|
|
|
const headers = new Headers();
|
|
|
|
headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
|
|
|
fetch(apiUrl + '/search', {method: 'POST', mode: 'cors', headers, body: 'url=' + encodeURI(tab.url)}).then((response) => {
|
|
|
|
response.json().then((match) => {
|
|
|
|
chrome.pageAction.setIcon({tabId: tab.id, path: 'icon-128.png'});
|
|
|
|
if (match.id) {
|
|
|
|
chrome.tabs.create({ url: apiUrl + '/' + match.service + '/' + match.type + '/' + match.id});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}).catch(() => {
|
|
|
|
chrome.pageAction.setIcon({tabId: tab.id, path: 'icon-128.png'});
|
|
|
|
});
|
|
|
|
});
|
2014-12-07 22:06:08 +00:00
|
|
|
});
|