Skip to content

Instantly share code, notes, and snippets.

@tokland
Created December 30, 2016 10:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokland/8e7412eecfc4da85af9850079adf2f59 to your computer and use it in GitHub Desktop.
Save tokland/8e7412eecfc4da85af9850079adf2f59 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name DeezerCLI
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Control Deezer web player from the console
// @author pyarnau@gmail.com
// @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