You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
/*!
|
|
devtools-detect
|
|
https://github.com/sindresorhus/devtools-detect
|
|
By Sindre Sorhus
|
|
MIT License
|
|
*/
|
|
|
|
const devtools = {
|
|
isOpen: false,
|
|
orientation: undefined,
|
|
};
|
|
|
|
const threshold = 170;
|
|
|
|
const emitEvent = (isOpen, orientation) => {
|
|
globalThis.dispatchEvent(new globalThis.CustomEvent('devtoolschange', {
|
|
detail: {
|
|
isOpen,
|
|
orientation,
|
|
},
|
|
}));
|
|
};
|
|
|
|
const main = ({emitEvents = true} = {}) => {
|
|
const widthThreshold = globalThis.outerWidth - globalThis.innerWidth > threshold;
|
|
const heightThreshold = globalThis.outerHeight - globalThis.innerHeight > threshold;
|
|
const orientation = widthThreshold ? 'vertical' : 'horizontal';
|
|
|
|
if (
|
|
!(heightThreshold && widthThreshold)
|
|
&& ((globalThis.Firebug && globalThis.Firebug.chrome && globalThis.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)
|
|
) {
|
|
if ((!devtools.isOpen || devtools.orientation !== orientation) && emitEvents) {
|
|
emitEvent(true, orientation);
|
|
}
|
|
|
|
devtools.isOpen = true;
|
|
devtools.orientation = orientation;
|
|
} else {
|
|
if (devtools.isOpen && emitEvents) {
|
|
emitEvent(false, undefined);
|
|
}
|
|
|
|
devtools.isOpen = false;
|
|
devtools.orientation = undefined;
|
|
}
|
|
};
|
|
|
|
main({emitEvents: false});
|
|
setInterval(main, 500);
|
|
|
|
export default devtools;
|