How to Parse External JSON code in Greasemonkey (or any other language)?
How to Parse External JSON code in Greasemonkey (or any other language) and use comparison operators?
I want to parse this JSON feed https://api.mintpal.com/v1/market/trades/bc/BTC and then execute an alert() when new instances of "total" in the JSON feed are greater than e.g. 100. What's the simplest way to do this? This is the code I have so far.
The essence of what I'm trying to do is just below, ideally I want it to play a sound file and send me an email if that's possible, apparently executing external macros from the browser is impossible. I know this is probably a really simple thing to do for an experienced programmer, but I'm a beginner, I'm also interested in examples of this code in any other language as long as I can edit the parameters and compile on windows [:)]
Code:
$.getJSON('https://api.mintpal.com/v1/market/trades/bc/btc', {}, function(JsonData){
if ( total >= 10 ) {
alert(A trade with a value over 10 BTC has been executed.) //alert+execute sound file etc.
}
// some code to reload the feed to check for new data every 60 seconds.
The full thing.
Code:
/ ==UserScript==
// @name Mintpal1
// @namespace MintPal
// @include https://api.mintpal.com/v1/market/trades/bc/btc
// @version 1
// @grant none
// ==/UserScript==
var $;
// Add jQuery
(function(){
if (typeof unsafeWindow.jQuery == 'undefined') {
var GM_Head = document.getElementsByTagName('head')[0] || document.documentElement,
GM_JQ = document.createElement('script');
GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
GM_JQ.type = 'text/javascript';
GM_JQ.async = true;
GM_Head.insertBefore(GM_JQ, GM_Head.firstChild);
}
GM_wait();
})();
// Check if jQuery's loaded
function GM_wait() {
if (typeof unsafeWindow.jQuery == 'undefined') {
window.setTimeout(GM_wait, 100);
} else {
$ = unsafeWindow.jQuery.noConflict(true);
letsJQuery();
}
}
// All your GM code must be inside this function
function letsJQuery() {
alert($); // check if the dollar (jquery) function works
alert($().jquery); // check jQuery version
}
$.getJSON('https://api.mintpal.com/v1/market/trades/bc/btc', {}, function(JsonData){
if ( total >= 10 ) {
alert(A trade with a value over 10 BTC has been executed.)
}
}
});
<script>
var time = new Date().getTime();
$(document.body).bind("mousemove keypress", function(e) {
time = new Date().getTime();
});
function refresh() {
if(new Date().getTime() - time >= 60000)
window.location.reload(true);
else
setTimeout(refresh, 10000);
}
setTimeout(refresh, 10000);
</script>
I can't seem to edit my old thread related to this, it's too vaguely described, so I made this new one. The old one: http://forums.codeguru.com/showthrea...ions-on-events
1 Attachment(s)
Re: How to Parse External JSON code in Greasemonkey (or any other language)?
I've found something that does exactly what I need it to do (JBison)
Attachment 32681
The problem now is that it doesn't support JSON feeds above 2048 bytes (very strange limitation) and it checks the feed once every 5 minutes, instead of the 30-60 seconds which I need.
Does anyone know of an alternative?