Skip to content

Instantly share code, notes, and snippets.

@zephster
Last active August 29, 2015 14:23
Show Gist options
  • Save zephster/75fadb456779168b9b7d to your computer and use it in GitHub Desktop.
Save zephster/75fadb456779168b9b7d to your computer and use it in GitHub Desktop.
apple watch availability checker
<!doctype html>
<html>
<head>
<title>AWmonitor</title>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
</head>
<body>
<p>
AWmonitor, by brandon
</p>
</body>
<script>
(function($)
{
"use strict";
var interval = "60", // seconds between checks
stores = [
"R214", // galleria
"R074", // boca
],
models = [
"MJ3T2LL", // 42mm space gray, black band
"MJ3U2LL", // 42mm stainless steel, black band
],
watches = "https://reserve.cdn-apple.com/US/en_US/reserve/watch/availability.json",
timer = null;
function checkAvailability()
{
/**
* i added a custom rule to Fiddler to force-enable CORS
*
* add menu item:
* public static RulesOption("Force CORS Response")
* var m_ForceCORS: boolean = false;
*
* check m_ForceCORS in OnBeforeResponse():
* if (m_ForceCORS)
* oSession.oResponse.headers.Add("Access-Control-Allow-Origin", "*");
**/
$.getJSON(watches).done(function(data)
{
var available = false,
store,
model;
for (store in stores)
{
store = stores[store];
for (model in models)
{
model = models[model];
if (data[store][model +"/A"])
{
available = true;
if (Notification.permission === "granted")
new Notification(model + " is available at " + store);
}
}
}
if (!available)
{
console.log("unavailable, resetting timer");
timer = setTimeout(function(){
checkAvailability();
}, interval * 1000);
}
});
}
function start()
{
Notification.requestPermission();
checkAvailability();
}
start();
}(jQuery));
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment