阻止用户通过浏览器控制台修改css样式//阻止非会员用户通过修改css查看清晰图片
let imgList = document.getElementById("vip_control").querySelectorAll("img");
let imgBoxList = document.getElementById("vip_control").querySelectorAll(".img_box");
let styleStr = "filter: blur(4px);"
let mo_options = {
childList: true,
attributes: true,
subtree: true,
attributesOldValue: true,
characterData: true,
characterDataOldValue: true,
}
let reset = (expression = () => {}) => {
setTimeout(() => {
observer.disconnect();
expression();
for (let i = 0; i < imgList.length; i++) {
observer.observe(imgList[i], mo_options);
observer.observe(imgBoxList[i], mo_options);
}
}, 0);
}
let callback = (records) => {
let record = records[0];
if (record.type === 'attributes' && record.attributeName === 'style') {
reset(() => {
for (let i = 0; i < imgList.length; i++) {
imgList[i].setAttribute('style', styleStr);
imgBoxList[i].setAttribute('style', styleStr);
}
});
}
}
let observer = new MutationObserver(callback);
for (let i = 0; i < imgList.length; i++) {
observer.observe(imgList[i], mo_options);
observer.observe(imgBoxList[i], mo_options);
}