One indirect way to detect initial changes would be via transition events.(一种检测初始变化的间接方法是通过过渡事件。)
Of course, this can be bypassed, but then again, everything you do on the frontend can.(当然,可以绕开它,但是话又说回来,您在前端执行的所有操作都可以。)
The gist of the idea is to add an incredibly short transition to all elements and listen to any transition events fired by it.(这个主旨是为所有元素添加一个非常短的过渡,并监听由它引发的任何过渡事件。)
let timeout = null; Array.from(document.querySelectorAll('*')).forEach(element => { element.addEventListener('transitionstart', () => { if (timeout) return; timeout = setTimeout(() => { console.log('styles changed'); timeout = null; }, 0); }); });
* { transition: all 0.0001s; }
<p>Edit my styles in the console to see messages</p>
Alternatively you could look to find a way to diff computed styles on all elements when certain events are fired, but I can't see a way how that wouldn't be prohibitively expensive to compute.(另外,您可能希望找到一种方法,以在触发某些事件时对所有元素的计算样式进行比较,但是我看不到这样的方式来计算成本不会过高。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…