<commit_before>import calf from '../support/calf';
import jQueryNotPresent from '../common/jQueryNotPresent';
import {parseBountyPageForWorld} from './parseBountyPageForWorld';
import retryAjax from '../ajax/retryAjax';
import setValueJSON from '../system/setValueJSON';
import {
  bountyList,
  bountyUrl,
  bwNeedsRefresh,
  doRefresh,
  invalidateCache,
  wantedList
} from './lists';
import {bountyListDiv, createDivs, wantedListDiv} from './createDivs';
import {bountyListReset, injectBountyList} from './injectBountyList';
import {injectWantedList, wantedListReset} from './injectWantedList';

function notRefreshed(enableActiveBountyList, enableWantedList) {
  if (enableWantedList) {
    wantedList.isRefreshed = false;
    injectWantedList(wantedList);
  }
  if (enableActiveBountyList) {
    bountyList.isRefreshed = false;
    injectBountyList(bountyList);
  }
}

var refreshConditions = [
  function() {return !bountyList;},
  function() {return !wantedList;},
  function() {return bwNeedsRefresh;}
];

function needsRefresh() {
  return refreshConditions.some(function(el) {
    return el();
  });
}

function retrieveBountyInfo(enableActiveList, enableWantedList) {
  invalidateCache();
  if (needsRefresh()) {
    doRefresh();
    retryAjax(bountyUrl + '1').done(parseBountyPageForWorld);
  } else {
    notRefreshed(enableActiveList, enableWantedList);
  }
}

function resetList(e) {
  if (e.target === bountyListReset) {
    setValueJSON('bountyList', null);
    retrieveBountyInfo(calf.enableActiveBountyList, calf.enableWantedList);
  }
  if (e.target === wantedListReset) {
    setValueJSON('wantedList', null);
    retrieveBountyInfo(calf.enableActiveBountyList, calf.enableWantedList);
  }
}

export function prepareBountyData() {
  if (jQueryNotPresent()) {return;}
  createDivs();
  bountyListDiv.addEventListener('click', resetList);
  wantedListDiv.addEventListener('click', resetList);
  retrieveBountyInfo(calf.enableActiveBountyList, calf.enableWantedList);
}<commit_msg>oops, make sure we created divs before assigning event handlers in activeWantedBounties<commit_after>import calf from '../support/calf';
import jQueryNotPresent from '../common/jQueryNotPresent';
import {parseBountyPageForWorld} from './parseBountyPageForWorld';
import retryAjax from '../ajax/retryAjax';
import setValueJSON from '../system/setValueJSON';
import {
  bountyList,
  bountyUrl,
  bwNeedsRefresh,
  doRefresh,
  invalidateCache,
  wantedList
} from './lists';
import {bountyListDiv, createDivs, wantedListDiv} from './createDivs';
import {bountyListReset, injectBountyList} from './injectBountyList';
import {injectWantedList, wantedListReset} from './injectWantedList';

function notRefreshed(enableActiveBountyList, enableWantedList) {
  if (enableWantedList) {
    wantedList.isRefreshed = false;
    injectWantedList(wantedList);
  }
  if (enableActiveBountyList) {
    bountyList.isRefreshed = false;
    injectBountyList(bountyList);
  }
}

var refreshConditions = [
  function() {return !bountyList;},
  function() {return !wantedList;},
  function() {return bwNeedsRefresh;}
];

function needsRefresh() {
  return refreshConditions.some(function(el) {
    return el();
  });
}

function retrieveBountyInfo(enableActiveList, enableWantedList) {
  invalidateCache();
  if (needsRefresh()) {
    doRefresh();
    retryAjax(bountyUrl + '1').done(parseBountyPageForWorld);
  } else {
    notRefreshed(enableActiveList, enableWantedList);
  }
}

function resetList(e) {
  if (e.target === bountyListReset) {
    setValueJSON('bountyList', null);
    retrieveBountyInfo(calf.enableActiveBountyList, calf.enableWantedList);
  }
  if (e.target === wantedListReset) {
    setValueJSON('wantedList', null);
    retrieveBountyInfo(calf.enableActiveBountyList, calf.enableWantedList);
  }
}

function doHandlers() {
  if (bountyListDiv) {bountyListDiv.addEventListener('click', resetList);}
  if (wantedListDiv) {wantedListDiv.addEventListener('click', resetList);}
}

export function prepareBountyData() {
  if (jQueryNotPresent()) {return;}
  createDivs();
  doHandlers();
  retrieveBountyInfo(calf.enableActiveBountyList, calf.enableWantedList);
}
{'fraction_non_alphanumeric': 0.12310651598942053, 'fraction_numerical': 0.00048088482808367395, 'mean_word_length': 5.688102893890675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4889501', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1313, 'n_words': 250}