Created
December 30, 2016 10:43
-
-
Save tokland/8e7412eecfc4da85af9850079adf2f59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name DeezerCLI | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Control Deezer web player from the console | |
// @author [email protected] | |
// @match http://www.deezer.com/* | |
// @grant none | |
// ==/UserScript== | |
// = Setup | |
// | |
// - Server: | |
// $ nc -k -l 9123 | wscat -l 9124 | |
// | |
// - Send command ("toggle-play" | "next" | "prev"): | |
// $ echo '{"type": "deezer", "command": COMMAND}' | nc localhost 9123 | |
(function() { | |
'use strict'; | |
function init(url) { | |
var ws = new WebSocket(url); | |
ws.onclose = function (event) { | |
setTimeout(function() { init(url); }, 1000); | |
}; | |
ws.onmessage = function (event) { | |
var command = JSON.parse(event.data); | |
switch (command.type) { | |
case "alert": | |
alert(command.message); | |
break; | |
case "deezer": | |
switch (command.command) { | |
case "toggle-play": | |
jQuery(".control-play").click(); | |
break; | |
case "prev": | |
jQuery(".control-prev").click(); | |
break; | |
case "next": | |
jQuery(".control-next").click(); | |
break; | |
} | |
} | |
}; | |
} | |
init("ws://localhost:9124"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment