Last active
August 29, 2015 14:23
-
-
Save zephster/75fadb456779168b9b7d to your computer and use it in GitHub Desktop.
apple watch availability checker
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
<!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