Last active
June 12, 2022 18:01
-
-
Save emreavcilar/8edcd18f76f21e36e58f1e39c2e915cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
browser functions | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
javascript to connect a bluetooth device. Displays a popup dialog to pair a device with the | |
current web app and then you can communicate with that device in your #reactjs app. | |
*/ | |
/* | |
#javascript to connect a #bluetooth device. | |
Displays a popup dialog to pair a device with | |
the current web app and then you can communicate | |
with that device in your #reactjs app. | |
Give it a try in the console! | |
Works only on Chromium based web browsers. | |
*/ | |
navigator | |
.bluetooth | |
.requestDevice({acceptAllDevices:true}) | |
.then(console.log); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐ ๐๐ถ๐ฝ: Check Network Status | |
How to detect if the internet connection is online or offline in JavaScript. | |
Also, how to listen for a change in the network status. | |
*/ | |
//listen for a change in the network status | |
window.addEventListener('offline', (e) => { | |
console.log('You are offline'); | |
}); | |
window.addEventListener('online', (e) => { | |
console.log('You are online'); | |
}); | |
// get current status | |
if(navigator.online){ | |
console.log('online'); | |
} else { | |
console.log('offline') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
JavaScript Tip ๐ก | |
You can use the "navigator.clipboard.writeText" function to copy text to clipboard. | |
It's asynchronous - and you don't have to artificially place it in the DOM first (like we had to in the old days). | |
*/ | |
https://www.linkedin.com/posts/simonhoiberg_javascript-tip-you-can-use-the-navigatorclipboardwritetext-activity-6924264860713156608-SQCH?utm_source=linkedin_share&utm_medium=member_desktop_web | |
/*WRONG !!!!!!!*/ | |
document.execCommand('copy') | |
/*TRUE !!!!!*/ | |
navigator.clipboard.writeText('npm i twitter-api-client'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
๐ป๐ฎ๐๐ถ๐ด๐ฎ๐๐ผ๐ฟ.๐ด๐ฒ๐๐๐ฎ๐๐๐ฒ๐ฟ๐() ๐ฎ๐ฆ๐ต๐ฉ๐ฐ๐ฅ ๐ฑ๐ณ๐ฐ๐ท๐ช๐ฅ๐ฆ๐ด ๐ช๐ฏ๐ง๐ฐ๐ณ๐ฎ๐ข๐ต๐ช๐ฐ๐ฏ ๐ข๐ฃ๐ฐ๐ถ๐ต ๐ต๐ฉ๐ฆ ๐ด๐บ๐ด๐ต๐ฆ๐ฎ'๐ด ๐ฃ๐ข๐ต๐ต๐ฆ๐ณ๐บ | |
- ๐ถ๐ด๐ฆ๐ฅ ๐ต๐ฐ ๐ช๐ฎ๐ฑ๐ญ๐ฆ๐ฎ๐ฆ๐ฏ๐ต ๐ฃ๐ข๐ต๐ต๐ฆ๐ณ๐บ-๐ด๐ข๐ท๐ช๐ฏ๐จ ๐ง๐ถ๐ฏ๐ค๐ต๐ช๐ฐ๐ฏ๐ข๐ญ๐ช๐ต๐ช๐ฆ๐ด ๐ธ๐ฉ๐ฆ๐ฏ ๐ต๐ฉ๐ฆ ๐ถ๐ด๐ฆ๐ณ'๐ด ๐ฃ๐ข๐ต๐ต๐ฆ๐ณ๐บ ๐ช๐ด ๐ญ๐ฐ๐ธ, | |
๐ญ๐ช๐ฌ๐ฆ ๐ฌ๐ช๐ญ๐ญ๐ช๐ฏ๐จ ๐ด๐ฐ๐ฎ๐ฆ ๐ฃ๐ข๐ค๐ฌ๐จ๐ณ๐ฐ๐ถ๐ฏ๐ฅ ๐ฑ๐ณ๐ฐ๐ค๐ฆ๐ด๐ด๐ฆ๐ด ๐ต๐ฉ๐ข๐ต ๐ฅ๐ณ๐ข๐ช๐ฏ ๐ต๐ฉ๐ฆ ๐ฃ๐ข๐ต๐ต๐ฆ๐ณ๐บ ๐ง๐ข๐ด๐ต๐ฆ๐ณ | |
- ๐๐ต ๐ณ๐ฆ๐ต๐ถ๐ณ๐ฏ๐ด ๐ข ๐ฃ๐ข๐ต๐ต๐ฆ๐ณ๐บ ๐ฑ๐ณ๐ฐ๐ฎ๐ช๐ด๐ฆ, ๐ธ๐ฉ๐ช๐ค๐ฉ ๐ช๐ด ๐ณ๐ฆ๐ด๐ฐ๐ญ๐ท๐ฆ๐ฅ ๐ช๐ฏ ๐ข ๐๐ข๐ต๐ต๐ฆ๐ณ๐บ๐๐ข๐ฏ๐ข๐จ๐ฆ๐ณ ๐ฐ๐ฃ๐ซ๐ฆ๐ค๐ต ๐ฑ๐ณ๐ฐ๐ท๐ช๐ฅ๐ช๐ฏ๐จ | |
๐ข๐ญ๐ด๐ฐ ๐ด๐ฐ๐ฎ๐ฆ ๐ฏ๐ฆ๐ธ ๐ฆ๐ท๐ฆ๐ฏ๐ต๐ด ๐บ๐ฐ๐ถ ๐ค๐ข๐ฏ ๐ฉ๐ข๐ฏ๐ฅ๐ญ๐ฆ ๐ต๐ฐ ๐ฎ๐ฐ๐ฏ๐ช๐ต๐ฐ๐ณ ๐ต๐ฉ๐ฆ ๐ฃ๐ข๐ต๐ต๐ฆ๐ณ๐บ ๐ด๐ต๐ข๐ต๐ถ๐ด. | |
*/ | |
navigator.getBattery().then( | |
(b)=> | |
{ | |
console.log(b) | |
}); | |
/* | |
charging: true | |
chargingTime: 0 | |
dischargingTime: Infinity | |
level: 1 | |
onchargingchange: null | |
onchargingtimechange: null | |
ondischargingtimechange: null | |
onlevelchange: null | |
*/ | |
navigator.getBattery().then((battery) => { | |
console.log('Battery Charging?', battery.charging); | |
console.log('Battery Level', battery.level); | |
console.log('Battery Discharging Time', battery.dischargingTime); | |
// Event Listeners Available | |
battery.addEventListener('chargingchange', () => {}); | |
battery.addEventListener('levelchange', () => {}) | |
battery.addEventListener('chargingtimechange', () => {}) | |
battery.addEventListener('dischargingtimechange', () => {}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*get user geolocation*/ | |
navigator.geolocation.getCurrentPosition( | |
res => { | |
// success | |
const latitude = res.coords.latitude; | |
const longitude = res.coords.longitude; | |
}, | |
error => { | |
// error | |
const code = error.code; | |
const message = error.message; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
detects user | |
*/ | |
var isMobile = | |
{ | |
android: function() | |
{ | |
return navigator.userAgent.match(/Android/i); | |
}, | |
blackBerry: function() | |
{ | |
return navigator.userAgent.match(/BlackBerry/i); | |
}, | |
iOS: function() | |
{ | |
return navigator.userAgent.match(/iPhone|iPad|iPod/i); | |
}, | |
opera: function() | |
{ | |
return navigator.userAgent.match(/Opera Mini/i); | |
}, | |
windows: function() | |
{ | |
return navigator.userAgent.match(/IEMobile/i); | |
}, | |
any: function() | |
{ | |
return (isMobile.android() || isMobile.blackBerry() || isMobile.iOS() || isMobile.opera() || isMobile.windows()); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
#javascript to turn on the users webcam and show a live video. | |
*/ | |
// HTML | |
<video autoplay="true" id="video"></video> | |
//Javascript | |
const el = document.getElementById("video"); | |
navigator.mediaDevices | |
.getUserMedia({ video:true }) | |
.then((stream) => el.srcObject = stream); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
#javascript to trigger the vibrator feedback on a mobile device. | |
*/ | |
navigator.vibrate(1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment