FantasyPlus icon indicating copy to clipboard operation
FantasyPlus copied to clipboard

firefox w/greasemonkey

Open jedahan opened this issue 11 years ago • 4 comments

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!

jedahan avatar Sep 26 '14 16:09 jedahan

That runs asynchronously, right? Is that literally the only change you made?

flipperbw avatar Sep 26 '14 16:09 flipperbw

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());
        });
        */
    }

jedahan avatar Sep 26 '14 16:09 jedahan

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.

jedahan avatar Sep 26 '14 16:09 jedahan

Is there somewhere that this script is posted to download/add to greasemonkey? I am not very sure how to do it manually.

smartymcfly avatar Oct 31 '14 05:10 smartymcfly