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
const videoElement = document.getElementById('myVideo'); | |
videoElement.onerror = onerror; | |
const errorButton = document.createElement('button'); | |
errorButton.setAttribute('type', 'button'); | |
errorButton.setAttribute('id', 'reload'); | |
errorButton.setAttribute('onclick', 'reloadVideo()'); | |
errorButton.textContent = 'Reload'; | |
errorButton.addEventListener("click", reloadVideo); |
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
let loadingTimes = 0; | |
const maxLoadingTimesBeforeChange = 4; | |
const videoOptions = { | |
hd: 'myAwesomeVideoHD.mp4', | |
sd: 'myAwesomeVideoSD.mp4', | |
}; | |
const video = `<video id='myVideo' src=${videoOptions.hd}></video>`; | |
const videoContainer = document.getElementById('myVideoContainerID'); | |
videoContainer.innerHTML = video; |
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
const videoContainer = document.getElementById('myVideoID'); | |
const suppressAutoplayForUser = /* Use an external service like a database to fill this in */ | |
const video = document.createElement('video'); | |
video.autoplay = suppressAutoplayForUser ? false : true; | |
video.src = 'myAwesomeVideo.mp4'; | |
video.textContent = 'Your browser does not support this media type, or the Video tag.'; | |
videoContainer.appendChild(video); | |
/* Creates: | |
<div id='myVideoID'> |
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
const test = getFalseValue(); | |
function getFalseValue () { | |
return false; | |
} | |
console.assert(test, 'Test value was false', test); | |
// Outputs: "Assertion failed: Test value was false false" |
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
function myFunction (userID) { | |
console.count(`MyFunction called with user: ${userID}`); | |
} | |
let users = 5; | |
while (users--) { | |
myFunction(users); | |
} |
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
console.log('This will format a %s then the number %i, then the object %o, then the floating point number %.2f', | |
"String", | |
5, | |
{ name: "Justin"}, | |
5.5855 | |
); | |
// Outputs: | |
// "This will format a String then the number 5, then the object Objectname: "Justin"__proto__: Object, then the floating point number 5.5855" |
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
function ends () { | |
console.trace(); | |
} | |
function middle () { | |
ends(); | |
} | |
function begins () { | |
middle(); |
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
if ('getBattery' in navigator) { | |
navigator.getBattery().then(battery => { | |
console.log('Initial', battery); | |
battery.onchargingchange = onchange; | |
battery.onchargingtimechange = onchange; | |
battery.ondischargingtimechange = onchange; | |
battery.onlevelchange = onchange; | |
function onchange (event) { | |
console.log('On change, type: %s', event.type, battery); |
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
let warningShowed = false; | |
if ('getBattery' in navigator) { | |
navigator.getBattery().then(battery => { | |
checkBatteryLevel(); | |
battery.onchargingchange = checkBatteryLevel; | |
battery.onchargingtimechange = checkBatteryLevel; | |
battery.ondischargingtimechange = checkBatteryLevel; | |
battery.onlevelchange = checkBatteryLevel; | |
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
// This must be triggered by a user event. | |
function copyText (text) { | |
// Create the textarea input to hold our text. | |
const element = document.createElement('textarea'); | |
element.value = text; | |
// Add it to the document so that it can be focused. | |
document.body.appendChild(element); | |
// Focus on the element so that it can be copied. | |
element.focus(); | |
element.setSelectionRange(0, element.value.length); |
OlderNewer