I've played around with the userscript approach... couldn't make it work.
Not sure if it's because there's something I'm missing or there are already too many other scripts intercepting the XHR calls.
// ==UserScript==
// @name SAS Retroclaim fix
// @namespace Violentmonkey Scripts
// @match *://www.flysas.com/en/eurobonus/points/claim-missing-points/flights/*
// @grant none
// @version 1.0
// @author -
// @description 11/19/2024, 5:09:37 AM
// ==/UserScript==
var jsonData = {id:12345678,firstName:"James",lastName:"Bond",bir thdate:"1974-04-15",title:"Mr",gender:"M",closed:false,email:"YOUR EMAIL",mobile:"+123456789",address:{countryCode:"N O"},euroBonus:{euroBonusNumber:"123456789",enrollm entDate:"2024-01-12",memberStatus:"EB",lastModifiedDate:"2024-01-24T16:27:54.423Z",memberSinceDate:"2024-01-12",membershipPeriodStartDate:"2024-01",membershipPeriodEndDate:"2024-12",nextIncentiveLevel:"S",basicPointsRequiredForN extLevel:20000,segmentsRequiredForNextLevel:10,qua lifyingFlightsThisYear:0,pointsInformation:{points ForUse:0,basicPointsEarnedThisYear:0,expiringPoint s:[],activities:[]},incentiveLevel:"B",incentiveLevelStartDate:"2024-01-12",lifetimeGold:{valid:false,years:0,periods:[{flightsRequired:45,pointsRequired:45000,periodEnd Date:"2023-12",periodStartDate:"2023-01",qualifyingFlights:0,qualifyingPoints:0,valid:f alse},{flightsRequired:45,pointsRequired:45000,per iodEndDate:"2024-12",periodStartDate:"2024-01",qualifyingFlights:0,qualifyingPoints:0,valid:f alse}]}}};
const createXmlHttpOverride = (
open
) => {
return function (
method,
url,
async,
username,
password
) {
this.addEventListener(
"readystatechange",
function () {
if (this.readyState === 4) {
//debugger;
// Override `onreadystatechange` handler, there's no where else this can go.
// Basically replace the client's with our override for interception.
this.onreadystatechange = (function (
originalOnreadystatechange
) {
return function (ev) {
if(url.indexOf('://sasgrowth.azure-api.net/api/profile/profile') >= 0) {
// Override the response text.
Object.defineProperty(this, "responseText", {
get() {
return JSON.stringify(jsonData);
},
});
Object.defineProperty(this, "status", {
get() {
return 200;
},
});
}
return (
originalOnreadystatechange &&
originalOnreadystatechange.call(this, ev)
);
}.call(this);
})(this.onreadystatechange);
}
},
false
);
open.call(this, method, url, async, username, password);
};
};
const main = () => {
XMLHttpRequest.prototype.open = createXmlHttpOverride(
XMLHttpRequest.prototype.open
);
};
main();