function documentReady(callback, doc = document) {
  const state = doc.readyState;

  if (state === 'complete' || state === 'interactive') {
    return setTimeout(callback, 0);
  }

  doc.addEventListener('DOMContentLoaded', callback);
}
Fork https://github.com/bendrucker/document-ready/blob/master/index.js
@param {Function} callback The callbacack to be called when the page is loaded
@returns {Number|void} If the page is already loaded returns the result of the setTimeout callback,
 otherwise it only attaches the callback to the DOMContentLoaded event