Skip to content

Instantly share code, notes, and snippets.

@imerr
Created April 20, 2018 02:55
Show Gist options
  • Save imerr/0f84ae5ebff0b89373adbf06685a5272 to your computer and use it in GitHub Desktop.
Save imerr/0f84ae5ebff0b89373adbf06685a5272 to your computer and use it in GitHub Desktop.
Loads current playing track from pretzel api
/**
* @name URLTOLOAD
* @label Url to Load
* @type text
* @description The web address/url from where to extract text
*/
var URLTOLOAD = "https://api.pretzel.rocks/api/v1/playing/YOUR ID HERE?limit=1";
/**
* @name UPDATEINTERVAL
* @label Update Interval
* @type int
* @positiveOnly true
* @description Optional. If set, the script will check the local file for any changes in text every X seconds, which will automatically update the text within the stage.
*/
var UPDATEINTERVAL = 1;
/*Do not modify anything below*/
var oldResponse;
function GetTextFromRemote()
{
$.ajax({url: URLTOLOAD,
type: "GET",
dataType: "json",
complete: function()
{
if (UPDATEINTERVAL > 0)
smlTitleTimeouts = setTimeout(function(){GetTextFromRemote(); }, UPDATEINTERVAL*1000);
},
success: function(response)
{
var responseCleaned = response.current.trackName + " - " + response.current.artistName
if(oldResponse!=responseCleaned)
{
SetText(responseCleaned, "Remote URL: " + URLTOLOAD);
}
oldResponse=responseCleaned;
}});
}
if (smlTitleTimeouts && smlTitleTimeouts != null)
{clearTimeout(smlTitleTimeouts);}
GetTextFromRemote();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment