Last active
February 25, 2017 20:37
-
-
Save harrynewsome/53aa7e81ba35fb6951223d3efd04c8c7 to your computer and use it in GitHub Desktop.
sb
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
var soundbouncer = { | |
_: { | |
playerFrame: false, | |
eventId: false, | |
}, | |
init: function() { | |
this._.eventId = ((new Date()).getTime()); | |
this.setPlayerFrame(); | |
this.playTrack('1nKclWMxh7nPbrxHrteHOB'); | |
}, | |
setPlayerFrame: function() { this._.playerFrame = document.getElementById('app-player') }, | |
playTrack: function(trackId) { | |
var evalString = 'window.top.postMessage(JSON.stringify({"type":"cosmos-request","resolver":1,"id":"cosmos_' + (this._.eventId++) + '","name":"cosmos_request_create", "payload":{"action":"POST","uri":"sp://player/v1/main","headers":{}, "body":JSON.stringify({"action":"play","context":"spotify:track:' + trackId + '","tracks":["spotify:track:' + trackId + '"], "options":{"repeat":false,"shuffle":false,"can_repeat":true,"can_shuffle":true,"can_skip_prev":true,"can_skip_next":true,"can_seek":true,"use_dmca_rules":false}, "play_origin":{"source":"unknown","reason":"playbtn","referrer":"spotify:app:now-playing-recs","referrer_version":"2.2.2","referrer_vendor":"com.spotify"}})}}), "*")'; | |
soundbouncer._.playerFrame.contentWindow.window.eval(evalString); | |
}, | |
play: function() { | |
var evalString = 'window.top.postMessage(JSON.stringify({"type":"bridge_request","id":"' + (this._.eventId++) + '","name":"player_play","args":["main"],"appVendor":"com.spotify","appVersion":"4.2.0"}), "*");'; | |
soundbouncer._.playerFrame.contentWindow.window.eval(evalString); | |
}, | |
pause: function() { | |
var evalString = 'window.top.postMessage(JSON.stringify({"type":"bridge_request","id":"' + (this._.eventId++) + '","name":"player_pause","args":["main"],"appVendor":"com.spotify","appVersion":"4.2.0"}), "*");'; | |
soundbouncer._.playerFrame.contentWindow.window.eval(evalString); | |
}, | |
executeOnPlayerFrame: function(evalString) { | |
this.playerFrame.contentWindow.window.eval(evalString); | |
} | |
}; | |
soundbouncer.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment