firefox w/greasemonkey
I got this working as a greasemonkey script. The only change I needed to make is $.get needed to be replaced with GM_xmlhttpRequest to get around CORS.
Should be helpful when making a firefox plugin. Not sure if theres an easy way to go from greasemonkey to full fledged firefox plugin (probably with JetPack).
Cheers!
That runs asynchronously, right? Is that literally the only change you made?
Yes it is asynchronous. fetchPositionProjections looks like this now:
//Get the data from external sites
function fetchPositionProjections(position, cb) {
var source_site = '';
if (window.positions.indexOf(position) > -1) {
source_site = 'http://www.fantasypros.com/nfl/projections/' + position + '.php?filters=44:45:73:152:469&export=xls';
}
else {
source_site = 'http://www.fantasysharks.com/apps/bert/forecasts/projections.php?csv=1&Position=' + position;
}
/* Use GM_xmlhttpRequest for CORS in greasemonkey */
GM_xmlhttpRequest({
method: "GET",
url: source_site,
onload: function(response) {
cb(position, response.responseText.trim());
}
});
/*
$.get(source_site, function(data) {
cb(position, data.trim());
});
*/
}
In fact, you could probably just add something like
// if in greasemonkey script
if(GM_xmlhttpRequest){
GM_xmlhttpRequest({
method: "GET",
url: source_site,
onload: function(response) {
cb(position, response.responseText.trim());
}
});
} else {
$.get....
}
I also prepended the jquery as I am not sure how to use multiple scripts with greasemonkey. I just made one concatenated script.
Is there somewhere that this script is posted to download/add to greasemonkey? I am not very sure how to do it manually.