Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firefox w/greasemonkey #6

Open
jedahan opened this issue Sep 26, 2014 · 4 comments
Open

firefox w/greasemonkey #6

jedahan opened this issue Sep 26, 2014 · 4 comments

Comments

@jedahan
Copy link

jedahan commented Sep 26, 2014

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!

@flipperbw
Copy link
Owner

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

@jedahan
Copy link
Author

jedahan commented Sep 26, 2014

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
Copy link
Author

jedahan commented Sep 26, 2014

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.

@smartymcfly
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants