// 定义20种常用的分辨率组合
const resolutions = [
{ width: 1024, height: 768 },
{ width: 1280, height: 720 },
{ width: 1280, height: 800 },
{ width: 1366, height: 768 },
{ width: 1440, height: 900 },
{ width: 1536, height: 864 },
{ width: 1600, height: 900 },
{ width: 1680, height: 1050 },
{ width: 1920, height: 1080 },
{ width: 1920, height: 1200 },
{ width: 2560, height: 1440 },
{ width: 2560, height: 1600 },
{ width: 3840, height: 2160 }, // 4K
{ width: 3200, height: 1800 },
{ width: 2880, height: 1800 },
{ width: 2048, height: 1536 },
{ width: 2560, height: 1080 },
{ width: 3440, height: 1440 },
{ width: 5120, height: 2880 }, // 5K
{ width: 7680, height: 4320 } // 8K
];
// 随机选择一个分辨率组合
const randomResolution = resolutions[Math.floor(Math.random() * resolutions.length)];
// 使用Object.defineProperty来伪装screen.width和screen.height
Object.defineProperty(screen, 'width', { value: randomResolution.width, writable: false });
Object.defineProperty(screen, 'height', { value: randomResolution.height, writable: false });
console.log(screen.width); // 输出:随机选择的宽度值
console.log(screen.height); // 输出:随机选择的高度值
// 生成4到32之间的随机值,且为2的倍数
const fakeCPUCores = Math.round((Math.random() * (16 - 2) + 2)) * 2;
// 使用Object.defineProperty来重写navigator.hardwareConcurrency
Object.defineProperty(navigator, 'hardwareConcurrency', {
value: fakeCPUCores,
writable: false // 将其设置为不可写,以防止后续修改
});
// 测试伪装是否成功
console.log(navigator.hardwareConcurrency); // 输出:一个在4到32之间的随机数,且为2的倍数
const toBlob = HTMLCanvasElement.prototype.toBlob;
const toDataURL = HTMLCanvasElement.prototype.toDataURL;
HTMLCanvasElement.prototype.manipulate = function() {
const {width, height} = this;
const context = this.getContext('2d');
const shift = {
'r': Math.floor(Math.random() * 10) - 5,
'g': Math.floor(Math.random() * 10) - 5,
'b': Math.floor(Math.random() * 10) - 5
};
const matt = context.getImageData(0, 0, width, height);
for (let i = 0; i < height; i += Math.max(1, parseInt(height / 10))) {
for (let j = 0; j < width; j += Math.max(1, parseInt(width / 10))) {
const n = ((i * (width * 4)) + (j * 4));
matt.data[n + 0] = matt.data[n + 0] + shift.r;
matt.data[n + 1] = matt.data[n + 1] + shift.g;
matt.data[n + 2] = matt.data[n + 2] + shift.b;
}
}
context.putImageData(matt, 0, 0);
};
Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
value: function() {
try {
this.manipulate();
}
catch(e) {
console.warn('manipulation failed', e);
}
return toBlob.apply(this, arguments);
}
});
Object.defineProperty(HTMLCanvasElement.prototype, 'toDataURL', {
value: function() {
try {
this.manipulate();
}
catch(e) {
console.warn('manipulation failed', e);
}
return toDataURL.apply(this, arguments);
}
});