"); } // only if button was added if($(".follow-button").length) { $(".follow-button").click(function(){ var promise = isFollowing(); promise.then(function(result) { if (result) { unfollow(); } else { follow(); } }); }); // initial load toggleFollowButton(); } function toggleFollowButton() { var button = $(".follow-text"), promise = isFollowing(); promise.then(function(result) { if (result) { button.text(followingLabel); button.css("color", "#6c6d6f"); $(".follow-button").css("border-color", "#6c6d6f"); } else { button.text(followLabel); button.css("color", "#007aff"); $(".follow-button").css("border-color", "#007aff"); } }); } function isFollowing() { var promise = getMyPreferences(); return promise.then(function(result) { let myPlayers = result.myPlayers; if (myPlayers.length > 0) { for (var i = 0;i