Skip to content

Commit 2947b1b

Browse files
committed
Require Node.js or a modern browser
1 parent 0346d26 commit 2947b1b

File tree

4 files changed

+42
-37
lines changed

4 files changed

+42
-37
lines changed

index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</a>
6363
<div class="container">
6464
<section class="main span12 text-center">
65-
<h1>is DevTools open?</h1>
65+
<h1>Is DevTools open?</h1>
6666
<h2 id="devtools-state"></h2>
6767
<h3 id="devtools-orientation"></h3>
6868
<div class="instruction">Try it out by opening DevTools</div>
@@ -74,16 +74,16 @@ <h3 id="devtools-orientation"></h3>
7474
</footer>
7575
</div>
7676
<script src="index.js"></script>
77-
<script>
78-
var stateEl = document.querySelector('#devtools-state');
79-
var oriEl = document.querySelector('#devtools-orientation');
77+
<script type="module">
78+
const stateElement = document.querySelector('#devtools-state');
79+
const orientationElement = document.querySelector('#devtools-orientation');
8080

81-
stateEl.textContent = window.devtools.open ? 'yes' : 'no';
82-
oriEl.textContent = window.devtools.orientation ? window.devtools.orientation : '';
81+
stateElement.textContent = window.devtools.open ? 'yes' : 'no';
82+
orientationElement.textContent = window.devtools.orientation ? window.devtools.orientation : '';
8383

84-
window.addEventListener('devtoolschange', function (e) {
85-
stateEl.textContent = e.detail.open ? 'yes' : 'no';
86-
oriEl.textContent = e.detail.orientation ? e.detail.orientation : '';
84+
window.addEventListener('devtoolschange', event => {
85+
stateElement.textContent = event.detail.open ? 'yes' : 'no';
86+
orientationElement.textContent = event.detail.orientation ? event.detail.orientation : '';
8787
});
8888
</script>
8989
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>

index.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
1-
/* eslint-disable spaced-comment */
21
/*!
3-
devtools-detect
4-
Detect if DevTools is open
5-
https://github.com/sindresorhus/devtools-detect
6-
by Sindre Sorhus
7-
MIT License
2+
devtools-detect
3+
Detect if DevTools is open
4+
https://github.com/sindresorhus/devtools-detect
5+
By Sindre Sorhus
6+
MIT License
87
*/
98
(function () {
109
'use strict';
11-
var devtools = {
10+
11+
const devtools = {
1212
open: false,
1313
orientation: null
1414
};
15-
var threshold = 160;
16-
var emitEvent = function (state, orientation) {
15+
16+
const threshold = 160;
17+
18+
const emitEvent = (state, orientation) => {
1719
window.dispatchEvent(new CustomEvent('devtoolschange', {
1820
detail: {
1921
open: state,
20-
orientation: orientation
22+
orientation
2123
}
2224
}));
2325
};
2426

25-
setInterval(function () {
26-
var widthThreshold = window.outerWidth - window.innerWidth > threshold;
27-
var heightThreshold = window.outerHeight - window.innerHeight > threshold;
28-
var orientation = widthThreshold ? 'vertical' : 'horizontal';
27+
setInterval(() => {
28+
const widthThreshold = window.outerWidth - window.innerWidth > threshold;
29+
const heightThreshold = window.outerHeight - window.innerHeight > threshold;
30+
const orientation = widthThreshold ? 'vertical' : 'horizontal';
2931

30-
if (!(heightThreshold && widthThreshold) &&
31-
((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)) {
32+
if (
33+
!(heightThreshold && widthThreshold) &&
34+
((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)
35+
) {
3236
if (!devtools.open || devtools.orientation !== orientation) {
3337
emitEvent(true, orientation);
3438
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=0.10.0"
13+
"node": ">=8"
1414
},
1515
"scripts": {
1616
"test": "xo && tsd"
@@ -33,7 +33,7 @@
3333
],
3434
"devDependencies": {
3535
"tsd": "^0.7.2",
36-
"xo": "^0.16.0"
36+
"xo": "^0.24.0"
3737
},
3838
"xo": {
3939
"envs": [

readme.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ $ npm install devtools-detect
1919

2020
```html
2121
<script src="node_modules/devtools-detect/index.js"></script>
22-
<script>
23-
// check if it's open
24-
console.log('is DevTools open?', window.devtools.open);
25-
// check it's orientation, null if not open
26-
console.log('and DevTools orientation?', window.devtools.orientation);
27-
28-
// get notified when it's opened/closed or orientation changes
29-
window.addEventListener('devtoolschange', function (e) {
30-
console.log('is DevTools open?', e.detail.open);
31-
console.log('and DevTools orientation?', e.detail.orientation);
22+
<script type="module">
23+
// Check if it's open
24+
console.log('Is DevTools open:', window.devtools.open);
25+
26+
// Check it's orientation, null if not open
27+
console.log('DevTools orientation:', window.devtools.orientation);
28+
29+
// Get notified when it's opened/closed or orientation changes
30+
window.addEventListener('devtoolschange', event => {
31+
console.log('Is DevTools open:', event.detail.open);
32+
console.log('DevTools orientation:', event.detail.orientation);
3233
});
3334
</script>
3435
```

0 commit comments

Comments
 (0)