Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.buildpath
.project
.gitignore
19 changes: 5 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
Simple app that opens deezer.com in own window and binds itself to media keys.
This is a fork from original dev by Natrim: [https://github.com/natrim/deezer-shortcut/](https://github.com/natrim/deezer-shortcut/)

Available at [Chrome Web Store](https://chrome.google.com/webstore/detail/deezer-shortcut/paccflbfblppaoidibhflahkogodngie) for free.
---

NOTE: this app is NOT developed by Deezer.

NOTE2: this app may works, or not .)

TODO's (probadly):
- right click context menu with browser controls
- better window size handling
- editable keys
- more keys (focus, hide, ...)
- notifications

Key binding part "lent" from https://github.com/julianxhokaxhiu/chrome-deezer-mediakeys-reloaded
Upgrades:
* Adding "like/unlike" key
* Adding notification when music changes
72 changes: 72 additions & 0 deletions assets/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
/* global chrome, BrowserControl, TitleBar */
var viewIsLoaded = false;

window.onload = function () {
// Used to replace some html entities into normal chars
var htmlStr = function(str){
return String(str).replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot/g, '"');
};

var webview = document.querySelector('#deezerview');

// Add listener for consolemessage from webview
webview.addEventListener('consolemessage', function(e) {
try {
var result = JSON.parse(e.message);
if (result){
if (result.id === 'deezer_shortcut_handle_events'){
switch (result.action){
case 'change_music':
// Get image from Deezer
var xhr = new XMLHttpRequest();
xhr.open('GET', result.data.nextCover, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
// Create & show notification
chrome.notifications.create('music-changed',{
type: 'basic',
iconUrl: window.URL.createObjectURL(this.response),
title: htmlStr(result.data.nextTitle),
message: htmlStr(result.data.nextArtist)
});

};
xhr.send();
break;
}
}
}

}catch (e){
// Not for our purpose
}

});

//block ads
webview.request.onBeforeRequest.addListener(
function (details) {
Expand Down Expand Up @@ -44,6 +84,30 @@ window.onload = function () {
document.querySelector('#deezerview').executeScript({
code: "var script=document.createElement('script');script.textContent=\"" + source + "\";(document.head||document.documentElement).appendChild(script);script.parentNode.removeChild(script);"
});

// Send message into host to handle music changes
webview.executeScript(
{
code: "Array.prototype.slice.call(document.querySelectorAll('div.player-track .player-track-link')).forEach(function(el){" +
"el.addEventListener('DOMSubtreeModified', function(){" +
"var nextCover, nextTitle, nextArtist = '';" +
"window.setTimeout(function(){" +
"nextCover = Array.prototype.slice.call(document.querySelectorAll('div.player-cover img'))[0].src;" +
"nextTitle = Array.prototype.slice.call(document.querySelectorAll('h2.player-track-title a.player-track-link'))[0].innerHTML;" +
"nextArtist = new Array();" +
"Array.prototype.slice.call(document.querySelectorAll('h3.player-track-artist a.player-track-link')).forEach(function(el){" +
"nextArtist.push(el.innerHTML)" +
"});" +
"nextArtist = nextArtist.join(', ');" +
"console.log(JSON.stringify({id: 'deezer_shortcut_handle_events', action: 'change_music', data: {nextTitle: nextTitle, nextArtist: nextArtist, nextCover: nextCover}}));" +
"}, 100);" +
"});" +
"});"
}, function(result){
console.log(result);
});


});
webview.addEventListener('permissionrequest', function (e) {
if (e.permission === 'download') {
Expand Down Expand Up @@ -130,9 +194,11 @@ window.onload = function () {
});
};


chrome.commands.onCommand.addListener(function (command) {
if (!viewIsLoaded) return;
var webview = document.querySelector('#deezerview');

switch (command) {
case 'NEXT-MK':
//NEXT_MK
Expand All @@ -158,5 +224,11 @@ chrome.commands.onCommand.addListener(function (command) {
code: "Array.prototype.slice.call(document.querySelectorAll('#player_control_pause,button.control-pause')).forEach(function(el) { el.click(); });"
});
break;
case 'LIKE-MK':
//LIKE_MK
webview.executeScript({
code: "var btns = Array.prototype.slice.call(document.querySelectorAll('a[role=\"button\"].evt-over.evt-out.action:not(.action-hide)'));if (btns.length>1){btns[1].click()}else{btns[0].click()}"
});
break;
}
});
7 changes: 7 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
"suggested_key": {
"default": "MediaStop"
}
},
"LIKE-MK": {
"description": "Like Key",
"global": true,
"suggested_key": {
"default": "Ctrl+Shift+Up"
}
}
},

Expand Down