{"size": 699, "ext": "js", "max_stars_repo_path": "fec/fec/static/js/modules/load-recaptcha.js", "max_stars_repo_name": "cnlucas/fec-cms", "max_stars_repo_stars_event_min_datetime": "2018-03-09T21:56:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T02:31:38.000Z", "max_issues_repo_path": "fec/fec/static/js/modules/load-recaptcha.js", "max_issues_repo_name": "rbtrsv/fec-cms", "max_issues_repo_issues_event_min_datetime": "2018-03-09T20:30:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T21:27:49.000Z", "max_forks_repo_path": "fec/fec/static/js/modules/load-recaptcha.js", "max_forks_repo_name": "rbtrsv/fec-cms", "max_forks_repo_forks_event_min_datetime": "2018-03-09T20:47:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-10T02:54:33.000Z"}
{"max_stars_count": 39, "max_issues_count": 3183, "max_forks_count": 19, "avg_line_length": 33.2857142857, "max_line_length": 116, "alphanum_fraction": 0.7210300429}
/**
 * Used to load recaptcha on demand since not every user uses it on every page
 */
const recaptchaSrc = 'https://www.google.com/recaptcha/api.js';

/**
 * Checks whether there's already a recaptcha script on the page and will not load a second script with the same src
 */
function _loadRecaptchaIfNeeded() {
  let scriptExists = document.querySelector(`script[src="${recaptchaSrc}"]`);
  if (!scriptExists) {
    let head = document.getElementsByTagName('head')[0];
    let newScript = document.createElement('script');
    newScript.type = 'text/javascript';
    newScript.src = recaptchaSrc;
    head.appendChild(newScript);
  }
}

module.exports = { loadRecaptcha: _loadRecaptchaIfNeeded };
