View measureEventPerformance.js
function measureEventPerformance(event) { | |
const lag = performance.now() - event.timeStamp; | |
console.log(`Event took: ${lag} ms`); | |
} | |
// Usage | |
const submitButton = document.querySelector('button[type="submit"]'); | |
submitButton.addEventListener('click', (event) => { | |
// Event listener logic here... |
View Queue.js
'use strict'; | |
function Queue(){ | |
this.push = function(){ | |
for (var i = 0, len = arguments.length; i < len; i++){ | |
if (typeof arguments[i] !== 'function'){ | |
throw new TypeError('Argument must be a function.') | |
} | |
arguments[i]() | |
} |
View overrideOnce.js
function overrideOnce(object, method, callback){ | |
// override method with original as argument | |
object[method] = (function(original){ | |
return function(){ | |
// store whatever callback does | |
var result = callback.apply(this, arguments); | |
// restore method | |
object[method] = original; |
View criticalcss.js
/** | |
* criticalCSS by @dansajin. based on @scottjehl's criticalcss.js | |
* run this in a browser console or create a bookmarklet. | |
* lists rules per css file. | |
* does not include cross origin css files and inline css. | |
*/ | |
(function(){ | |
var sheets = document.styleSheets, | |
host = window.location.host, | |
maxTop = 1200, |