Search code examples
jsonangularuserscriptsspoofing

Spoof JSON (or other resource) while loading realtime Web site


I'm trying to write a userscript for a friend. The Website I'm writing it for (app.patientaccess.com) tells you what doctors appointments you have, (among other things). However, in order to write my userscript, I need to know how the app handle appointments for the following year.

At the moment, the only way to know is to wait until the end of the year when my friend starts making appointments for the following year. Since it's an Angular app, I'd rather, if possible, point it to a fabricated JSON file of my creation when the app requests that particular data. In that file I can give it some data for this year and next year and then I can see what happens with appointments made for the following year.

I'm hoping this can be done with an addon for Chrome or Firefox or perhaps some kind of free/open source software.

Thanks in advance.


Solution

  • I came up with a function that will accurately guess there year, given the day name, date and month, if it's within a couple of years either side of the current year.

    function calculateYear(dayName, dayOfMonth, monthNum, returnDateObj) {
        monthNum -= 1;
        maxIterations = 3;
        var startYear = (new Date()).getFullYear();
        var dateObj = new Date(startYear, monthNum, dayOfMonth);
        for (var i = 0; i < maxIterations; i++) {
            dateObj.setYear(startYear + (1 * i));
            if (dayName == daysOfTheWeek[dateObj.getDay()]) {
                return (returnDateObj) ? dateObj : dateObj.getFullYear();
            }
    
            dateObj.setYear(startYear - (i + 1));
            if (dayName == daysOfTheWeek[dateObj.getDay()]) {
                return (returnDateObj) ? dateObj : dateObj.getFullYear();
            }
        }
    
        return 'No Match';
    }
    

    It works a treat, as you can see here.