From b2b45b67f539767368f61f51801bd3c70ac09da9 Mon Sep 17 00:00:00 2001 From: Damien Bruchet Date: Thu, 29 Dec 2016 18:14:49 +0100 Subject: [PATCH 1/6] Adding like button management --- .gitignore | 3 +++ assets/app.js | 7 +++++++ manifest.json | 7 +++++++ 3 files changed, 17 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec8069b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.buildpath +.project +.gitignore diff --git a/assets/app.js b/assets/app.js index e919f20..eaad2e2 100644 --- a/assets/app.js +++ b/assets/app.js @@ -158,5 +158,12 @@ 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 + console.log('LIKE KEY PRESSED') + webview.executeScript({ + code: "document.querySelectorAll('a[role=\"button\"].evt-over.evt-out.action:not(.action-hide)') .forEach(function(el) { el.click(); })" + }); + break; } }); diff --git a/manifest.json b/manifest.json index ba38dac..7880aa8 100644 --- a/manifest.json +++ b/manifest.json @@ -55,6 +55,13 @@ "suggested_key": { "default": "MediaStop" } + }, + "LIKE-MK": { + "description": "Like Key", + "global": true, + "suggested_key": { + "default": "Ctrl+Shift+Up" + } } }, From 988a7b6c17de28533e8c5d676687ddd909ef6d77 Mon Sep 17 00:00:00 2001 From: Damien Bruchet Date: Tue, 10 Jan 2017 11:35:24 +0100 Subject: [PATCH 2/6] Adding notification when music changes --- assets/app.js | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/assets/app.js b/assets/app.js index eaad2e2..d66fe2c 100644 --- a/assets/app.js +++ b/assets/app.js @@ -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(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/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) { @@ -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') { @@ -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 @@ -160,7 +226,6 @@ chrome.commands.onCommand.addListener(function (command) { break; case 'LIKE-MK': //LIKE_MK - console.log('LIKE KEY PRESSED') webview.executeScript({ code: "document.querySelectorAll('a[role=\"button\"].evt-over.evt-out.action:not(.action-hide)') .forEach(function(el) { el.click(); })" }); From d2e67726529926623b781da2420eadcdff2a3297 Mon Sep 17 00:00:00 2001 From: Damien Bruchet Date: Tue, 10 Jan 2017 15:15:40 +0100 Subject: [PATCH 3/6] Updating readme --- README.md | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5327261..a645ded 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,7 @@ -Simple app that opens deezer.com in own window and binds itself to media keys. +This 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 \ No newline at end of file From 35b4b1da9db80af67f30c41be668989cb83ba235 Mon Sep 17 00:00:00 2001 From: Damien Bruchet Date: Tue, 10 Jan 2017 15:18:27 +0100 Subject: [PATCH 4/6] Cleans readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a645ded..fbb671e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -This a fork from original dev by Natrim: [https://github.com/natrim/deezer-shortcut/](https://github.com/natrim/deezer-shortcut/) +This is a fork from original dev by Natrim: [https://github.com/natrim/deezer-shortcut/](https://github.com/natrim/deezer-shortcut/) --- From d04545f80462c4adfbc48bea70fdb4062678424c Mon Sep 17 00:00:00 2001 From: Damien Bruchet Date: Tue, 10 Jan 2017 17:51:02 +0100 Subject: [PATCH 5/6] Fix bug for like button when uing 'Flow' function --- assets/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/app.js b/assets/app.js index d66fe2c..1f63f6e 100644 --- a/assets/app.js +++ b/assets/app.js @@ -98,7 +98,7 @@ window.onload = function () { "Array.prototype.slice.call(document.querySelectorAll('h3.player-track-artist a.player-track-link')).forEach(function(el){" + "nextArtist.push(el.innerHTML)" + "});" + - "nextArtist = nextArtist.join(', ');" + + "nextArdtist = nextArtist.join(', ');" + "console.log(JSON.stringify({id: 'deezer_shortcut_handle_events', action: 'change_music', data: {nextTitle: nextTitle, nextArtist: nextArtist, nextCover: nextCover}}));" + "}, 100);" + "});" + @@ -227,7 +227,7 @@ chrome.commands.onCommand.addListener(function (command) { case 'LIKE-MK': //LIKE_MK webview.executeScript({ - code: "document.querySelectorAll('a[role=\"button\"].evt-over.evt-out.action:not(.action-hide)') .forEach(function(el) { el.click(); })" + 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; } From be30e12507c5cf1ccd14b1d19fbea65838ffc03f Mon Sep 17 00:00:00 2001 From: Damien Bruchet Date: Wed, 11 Jan 2017 10:49:31 +0100 Subject: [PATCH 6/6] Cleans code --- assets/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/app.js b/assets/app.js index 1f63f6e..32b1dba 100644 --- a/assets/app.js +++ b/assets/app.js @@ -98,7 +98,7 @@ window.onload = function () { "Array.prototype.slice.call(document.querySelectorAll('h3.player-track-artist a.player-track-link')).forEach(function(el){" + "nextArtist.push(el.innerHTML)" + "});" + - "nextArdtist = nextArtist.join(', ');" + + "nextArtist = nextArtist.join(', ');" + "console.log(JSON.stringify({id: 'deezer_shortcut_handle_events', action: 'change_music', data: {nextTitle: nextTitle, nextArtist: nextArtist, nextCover: nextCover}}));" + "}, 100);" + "});" +