const originalInnerTextDescriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
Object.defineProperty(HTMLElement.prototype, 'innerText', {
set: function(value) {
if (value === "你想要阻止的") {
console.warn(`Prevented setting innerText to: "${value}"`);
return;
}
originalInnerTextDescriptor.set.call(this, value);
},
get: function() {
return originalInnerTextDescriptor.get.call(this);
},
configurable: true,
enumerable: true
});
测试
document.body.innerText = "你想要阻止的";
PS:还是请大家有能力的支持下正版