mirror of
https://github.com/xenos1337/httptoolkit-patcher.git
synced 2026-07-15 16:20:02 +02:00
update for 1.24.4
This commit is contained in:
@@ -1,14 +1,11 @@
|
|||||||
(function () {
|
(function () {
|
||||||
console.log("[PAGE-INJECT] Installing hooks in page context");
|
console.log("[PAGE-INJECT] Installing hooks in page context");
|
||||||
|
|
||||||
|
// Properties to hook directly on accountStore (still exist as computed properties)
|
||||||
const propertyHooks = {
|
const propertyHooks = {
|
||||||
isPaidUser: true,
|
|
||||||
isLoggedIn: true,
|
isLoggedIn: true,
|
||||||
userHasSubscription: true,
|
|
||||||
userEmail: "hi@httptoolkit.com",
|
userEmail: "hi@httptoolkit.com",
|
||||||
mightBePaidUser: true,
|
mightBePaidUser: true,
|
||||||
isPastDueUser: false,
|
|
||||||
isStatusUnexpired: true,
|
|
||||||
userSubscription: {
|
userSubscription: {
|
||||||
state: "fulfilled",
|
state: "fulfilled",
|
||||||
status: "active",
|
status: "active",
|
||||||
@@ -25,12 +22,35 @@
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Methods to hook on the user object (moved from accountStore properties to user methods in v3.1.0)
|
||||||
|
const userMethodHooks = {
|
||||||
|
isPaidUser: true,
|
||||||
|
isPastDueUser: false,
|
||||||
|
userHasSubscription: true,
|
||||||
|
};
|
||||||
|
|
||||||
const hookedObjects = new WeakSet();
|
const hookedObjects = new WeakSet();
|
||||||
|
const hookedUsers = new WeakSet();
|
||||||
|
|
||||||
|
// Patch user object methods
|
||||||
|
function patchUserObject(user) {
|
||||||
|
if (!user || typeof user !== "object" || hookedUsers.has(user)) return;
|
||||||
|
|
||||||
|
for (const methodName of Object.keys(userMethodHooks)) {
|
||||||
|
if (typeof user[methodName] === "function") {
|
||||||
|
console.log("[PAGE-INJECT] Patching user." + methodName + "()");
|
||||||
|
user[methodName] = function () {
|
||||||
|
return userMethodHooks[methodName];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hookedUsers.add(user);
|
||||||
|
}
|
||||||
|
|
||||||
// Override Object.defineProperty to intercept all property definitions
|
// Override Object.defineProperty to intercept all property definitions
|
||||||
const originalDefineProperty = Object.defineProperty;
|
const originalDefineProperty = Object.defineProperty;
|
||||||
Object.defineProperty = function (target, prop, descriptor) {
|
Object.defineProperty = function (target, prop, descriptor) {
|
||||||
// Intercept our target properties
|
|
||||||
if (prop in propertyHooks) {
|
if (prop in propertyHooks) {
|
||||||
console.log("[PAGE-INJECT] Intercepting defineProperty for: " + prop);
|
console.log("[PAGE-INJECT] Intercepting defineProperty for: " + prop);
|
||||||
|
|
||||||
@@ -47,6 +67,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Intercept the 'user' property to patch its methods when it's set/accessed
|
||||||
|
if (prop === "user") {
|
||||||
|
console.log("[PAGE-INJECT] Intercepting defineProperty for: user");
|
||||||
|
|
||||||
|
if (descriptor && descriptor.get) {
|
||||||
|
const originalGetter = descriptor.get;
|
||||||
|
descriptor.get = function () {
|
||||||
|
const user = originalGetter.call(this);
|
||||||
|
if (user) patchUserObject(user);
|
||||||
|
return user;
|
||||||
|
};
|
||||||
|
} else if (descriptor && descriptor.value !== undefined && descriptor.value) {
|
||||||
|
patchUserObject(descriptor.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return originalDefineProperty.call(this, target, prop, descriptor);
|
return originalDefineProperty.call(this, target, prop, descriptor);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -67,6 +103,20 @@
|
|||||||
props[prop].value = propertyHooks[prop];
|
props[prop].value = propertyHooks[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prop === "user") {
|
||||||
|
console.log("[PAGE-INJECT] Intercepting defineProperties for: user");
|
||||||
|
if (props[prop].get) {
|
||||||
|
const originalGetter = props[prop].get;
|
||||||
|
props[prop].get = function () {
|
||||||
|
const user = originalGetter.call(this);
|
||||||
|
if (user) patchUserObject(user);
|
||||||
|
return user;
|
||||||
|
};
|
||||||
|
} else if (props[prop].value !== undefined && props[prop].value) {
|
||||||
|
patchUserObject(props[prop].value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return originalDefineProperties.call(this, target, props);
|
return originalDefineProperties.call(this, target, props);
|
||||||
};
|
};
|
||||||
@@ -80,6 +130,7 @@
|
|||||||
if (!obj || hookedObjects.has(obj)) return;
|
if (!obj || hookedObjects.has(obj)) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Patch direct property hooks
|
||||||
Object.keys(propertyHooks).forEach(prop => {
|
Object.keys(propertyHooks).forEach(prop => {
|
||||||
try {
|
try {
|
||||||
const desc = Object.getOwnPropertyDescriptor(obj, prop);
|
const desc = Object.getOwnPropertyDescriptor(obj, prop);
|
||||||
@@ -88,7 +139,7 @@
|
|||||||
|
|
||||||
if (desc.get) {
|
if (desc.get) {
|
||||||
const originalGetter = desc.get;
|
const originalGetter = desc.get;
|
||||||
Object.defineProperty(obj, prop, {
|
originalDefineProperty(obj, prop, {
|
||||||
get: function () {
|
get: function () {
|
||||||
const originalValue = originalGetter.call(this);
|
const originalValue = originalGetter.call(this);
|
||||||
console.log("[PAGE-INJECT] " + prop + " getter intercepted, original=" + originalValue + ", returning=" + JSON.stringify(propertyHooks[prop]));
|
console.log("[PAGE-INJECT] " + prop + " getter intercepted, original=" + originalValue + ", returning=" + JSON.stringify(propertyHooks[prop]));
|
||||||
@@ -108,6 +159,14 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Patch user object if present
|
||||||
|
try {
|
||||||
|
if (obj.user && typeof obj.user === "object") {
|
||||||
|
console.log("[PAGE-INJECT] Found user object on object #" + idx + ", patching methods...");
|
||||||
|
patchUserObject(obj.user);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
hookedObjects.add(obj);
|
hookedObjects.add(obj);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Ignore object access errors
|
// Ignore object access errors
|
||||||
@@ -128,7 +187,7 @@
|
|||||||
const desc = Object.getOwnPropertyDescriptor(store, prop);
|
const desc = Object.getOwnPropertyDescriptor(store, prop);
|
||||||
if (desc && desc.configurable && desc.get) {
|
if (desc && desc.configurable && desc.get) {
|
||||||
const originalGetter = desc.get;
|
const originalGetter = desc.get;
|
||||||
Object.defineProperty(store, prop, {
|
originalDefineProperty(store, prop, {
|
||||||
get: function () {
|
get: function () {
|
||||||
const originalValue = originalGetter.call(this);
|
const originalValue = originalGetter.call(this);
|
||||||
console.log("[PAGE-INJECT] accountStore." + prop + " intercepted, original=" + originalValue + ", returning=" + JSON.stringify(propertyHooks[prop]));
|
console.log("[PAGE-INJECT] accountStore." + prop + " intercepted, original=" + originalValue + ", returning=" + JSON.stringify(propertyHooks[prop]));
|
||||||
@@ -141,6 +200,15 @@
|
|||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Patch user methods on the store
|
||||||
|
try {
|
||||||
|
if (store.user && typeof store.user === "object") {
|
||||||
|
console.log("[PAGE-INJECT] Found user object in accountStore, patching methods...");
|
||||||
|
patchUserObject(store.user);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
hookedObjects.add(store);
|
hookedObjects.add(store);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,7 +228,7 @@
|
|||||||
|
|
||||||
if (scanCount >= 50) {
|
if (scanCount >= 50) {
|
||||||
clearInterval(scanInterval);
|
clearInterval(scanInterval);
|
||||||
console.log("[PAGE-INJECT] Stopped periodic scanning after 10 attempts");
|
console.log("[PAGE-INJECT] Stopped periodic scanning after 50 attempts");
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user