10 ms·
It does seem that the unminified code is very close to the original. In some cases ChatGPT even did its own refactoring in addition to the unminification:
by lifthrasiir 2y ago
It does seem that the unminified code is very close to the original. In some cases ChatGPT even did its own refactoring in addition to the unminification:
// ORIGINAL:
j.useEffect(() => {
function r() {
n({ height: window.innerHeight, width: window.innerWidth });
}
if (typeof window < "u") return n({ height: window.innerHeight, width: window.innerWidth }), window.addEventListener("resize", r), () => window.removeEventListener("resize", r);
}, []),
// UNMINIFIED:
useEffect(() => {
const handleResize = () => {
setSize({ height: window.innerHeight, width: window.innerWidth });
};
// Initial size setting
handleResize();
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
}, []);
Note that the original code doesn't call `handleResize` immediately, but have its contents inlined instead. (Probably the minifier did the actual inlining.) The only real difference here is a missing `if (typeof window < "u")` condition.
- sabbaticaldev 2y agothe condition is a constant so it can be safely removed
- lifthrasiir 2y agoOnly in the web environment. In fact the condition itself is true only when it runs in a web browser and not in a web worker.
- sabbaticaldev 2y agowhich is the case for that code and it was added by the obfuscator
- lifthrasiir 2y agoNo obfuscator would add only that. It is almost surely from some library that is aware of the possibility that `window` may not exist.