var helper = true;
var first = true;
$("#help").click(function () {
if (helper) {
$("#helper").fadeIn();
helper = false;
} else {
$("#helper").fadeOut();
helper = true;
}
});
$("#sub").click(find);
function find() {
if (first) {
if ($("#id").val()) {
var req = new XMLHttpRequest();
var url = "http://pblweb.com/api/v1/hearts/" + $("#id").val() + ".json";
req.open('GET', url, true);
req.onload = function (e) {
if (req.readyState == 4 && req.status == 200) {
if (req.status == 200) {
var response = JSON.parse(req.responseText);
$("#init").remove();
$("#hearts").html("<h2>This app has <span id='num'>" + response.hearts + "</span> hearts</h2><br><br>Another?<br><input id='id'/><button id='sub' onclick='find()'>Go!</button><br><div id='message' hidden>Please enter an ID.</div>");
$("#hearts").fadeIn(2000);
$("#sub").click(find);
} else {
alert("Sorry; it appears that there has been an error. Check to make sure that the ID you've entered is valid.");
}
}
};
req.send(null);
first = false;
} else {
$("#message").fadeIn(1000).delay(500).fadeOut(1000);
}
} else {
if ($("#id").val()) {
var req = new XMLHttpRequest();
var url = "http://pblweb.com/api/v1/hearts/" + $("#id").val() + ".json";
req.open('GET', url, true);
req.onload = function (e) {
if (req.readyState == 4 && req.status == 200) {
if (req.status == 200) {
var response = JSON.parse(req.responseText);
$("#num").html(response.hearts);
} else {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.