Created
April 20, 2018 02:55
-
-
Save imerr/0f84ae5ebff0b89373adbf06685a5272 to your computer and use it in GitHub Desktop.
Loads current playing track from pretzel api
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
/** | |
* @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