Skip to content

Instantly share code, notes, and snippets.

@lejeunerenard
Created November 6, 2017 04:02
Show Gist options
  • Save lejeunerenard/56d468fdf0d3478fca3c69745146fc3d to your computer and use it in GitHub Desktop.
Save lejeunerenard/56d468fdf0d3478fca3c69745146fc3d to your computer and use it in GitHub Desktop.
Drop in logging solution for debugging where DevTools isn't available.
var lastMsg
function exlog (text) {
var popup = document.getElementById('xlog-popup')
if (!popup) {
popup = document.createElement('div')
Object.assign(popup.style, {
width: '100%',
height: '100%',
top: 0,
left: 0,
position: 'absolute',
zIndex: 1000000,
padding: '20px',
pointerEvents: 'none',
background: 'rgba(255, 255, 255, 0.5)'
})
popup.setAttribute('id', 'xlog-popup')
document.body.appendChild(popup)
}
if (lastMsg === text) {
var msg = document.getElementById('xlog-popup').querySelector('p:last-child')
var counter = msg.querySelector('span')
if (!counter) {
counter = document.createElement('span')
counter.style.paddingLeft = '10px'
msg.appendChild(counter)
}
counter.innerText = (parseInt(counter.innerText) || 0) + 1
} else {
var msg = document.createElement('p')
Object.assign(msg.style, {
color: '#c00',
fontSize: '20px'
})
msg.innerText = text
lastMsg = text
popup.appendChild(msg)
}
}
window.onerror = function errorExlog (err, source, lineno, colno, error) {
exlog('Error: ' + err + ' source: ' + source + ' line#' + lineno + ':' + colno + ' : ' + error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment