<commit_before>(function poll() {
  if ( typeof ynabToolKit !== "undefined"  && ynabToolKit.pageReady === true ) {

    ynabToolKit.enhancedSelectedTotals = function ()  {

      function enhancedSelectedTotalsApply() {
          var parent = document.getElementsByClassName("accounts-header-balances")[0];
          var totals = document.createElement("div");
          totals.className = "accounts-header-balances-selected hidden";
          totals.id = "accounts-selected-total";
          var label = document.createElement("div");
          label.className = "accounts-header-balances-label";
          label.textContent = "Selected Transactions Total";
          totals.appendChild(label);
          parent.appendChild(totals);
          var dataSetParent = document.getElementsByClassName('ynab-grid-body')[0].getElementsByClassName('ynab-grid-body-row');
          for (var i = 0; i < dataSetParent.length; i++) {
              dataSet.push(dataSetParent[i].id);
          }
          enhancedSelectedTotalsPoll();
      }

      function enhancedSelectedTotalsCalculate() {
          var outflows = 0;
          var inflows = 0;
          var transactionsFound = false;
          var accountId, transactions;
          accountId = 'null';
          if (currentPath.indexOf('/accounts/') > -1) {
              accountId = currentPath.substr(currentPath.lastIndexOf('/') + 1)
          }
          transactions = ynabToolKit.shared.getVisibleTransactions(accountId);
          notSubTransactions = transactions.filter(function(el) { return el.displayItemType != ynab.constants.TransactionDisplayItemType.ScheduledSubTransaction && el.displayItemType != ynab.constants.TransactionDisplayItemType.SubTransaction });
          for (var i = 0; i < notSubTransactions.length; i++) {
              if (notSubTransactions[i].isChecked) {
                  inflows += notSubTransactions[i].inflow;
                  outflows += notSubTransactions[i].outflow;
                  transactionsFound = true;
              }
          }
          var total = inflows - outflows;
          if (!transactionsFound) {
              total = false;
          }
          enhancedSelectedTotalsUpdate(total);

          setTimeout(enhancedSelectedTotalsPoll, 750);
      }

      function enhancedSelectedTotalsUpdate(total) {
          var parent = document.getElementById('accounts-selected-total');
          if (parent == null) {
              return false;
          }
          if ((' ' + parent.className + ' ').indexOf(' hidden ') == -1 && total === false) {
              parent.className += " hidden";
              return true;
          } else if (total === false) {
              return true;
          }
          parent.className = "accounts-header-balances-selected";
          var spans = parent.getElementsByClassName("user-data");
          for (var i = 0; i < spans.length; i++) {
              spans[i].remove();
          }
          var totalFormatted = ynabToolKit.shared.formatCurrency(total, true);
          var totalFormattedNoHtml = ynabToolKit.shared.formatCurrency(total, false);
          var userData = document.createElement("span");
          userData.className = "user-data";
          userData.title = totalFormattedNoHtml;
          var userCurrency = document.createElement("span");
          userCurrency.className = "user-data currency";
          if (total >= 0) {
              userCurrency.className += " positive";
          } else {
              userCurrency.className += " negative";
          }
          userCurrency.innerHTML = totalFormatted;
          userData.appendChild(userCurrency);
          parent.appendChild(userData);
      }

      function enhancedSelectedTotalsInit() {
          var parentDiv = document.getElementsByClassName('accounts-header-balances');
          n = parentDiv.length;
          if (n > 0) {
              enhancedSelectedTotalsApply();
          } else {
              setTimeout(enhancedSelectedTotalsInit, 250);
          }
      }
<commit_msg>Removing use of HTML string building and replacing with appends and text.<commit_after>(function poll() {
  if ( typeof ynabToolKit !== "undefined"  && ynabToolKit.pageReady === true ) {

    ynabToolKit.enhancedSelectedTotals = function ()  {

      function enhancedSelectedTotalsApply() {
          var parent = document.getElementsByClassName("accounts-header-balances")[0];
          var totals = document.createElement("div");
          totals.className = "accounts-header-balances-selected hidden";
          totals.id = "accounts-selected-total";
          var label = document.createElement("div");
          label.className = "accounts-header-balances-label";
          label.textContent = "Selected Transactions Total";
          totals.appendChild(label);
          parent.appendChild(totals);
          var dataSetParent = document.getElementsByClassName('ynab-grid-body')[0].getElementsByClassName('ynab-grid-body-row');
          for (var i = 0; i < dataSetParent.length; i++) {
              dataSet.push(dataSetParent[i].id);
          }
          enhancedSelectedTotalsPoll();
      }

      function enhancedSelectedTotalsCalculate() {
          var outflows = 0;
          var inflows = 0;
          var transactionsFound = false;
          var accountId, transactions;
          accountId = 'null';
          if (currentPath.indexOf('/accounts/') > -1) {
              accountId = currentPath.substr(currentPath.lastIndexOf('/') + 1)
          }
          transactions = ynabToolKit.shared.getVisibleTransactions(accountId);
          notSubTransactions = transactions.filter(function(el) { return el.displayItemType != ynab.constants.TransactionDisplayItemType.ScheduledSubTransaction && el.displayItemType != ynab.constants.TransactionDisplayItemType.SubTransaction });
          for (var i = 0; i < notSubTransactions.length; i++) {
              if (notSubTransactions[i].isChecked) {
                  inflows += notSubTransactions[i].inflow;
                  outflows += notSubTransactions[i].outflow;
                  transactionsFound = true;
              }
          }
          var total = inflows - outflows;
          if (!transactionsFound) {
              total = false;
          }
          enhancedSelectedTotalsUpdate(total);

          setTimeout(enhancedSelectedTotalsPoll, 750);
      }

      function enhancedSelectedTotalsUpdate(total) {
          var parent = $('#accounts-selected-total');

          if (parent.length == 0) {
              return false;
          }

          if (total === false) {
              parent.addClass('hidden');
              return true;
          }

          parent.attr('class', 'accounts-header-balances-selected');

          parent.find('.user-data').remove();

          var totalFormatted = ynabToolKit.shared.formatCurrency(total);

          var userData = $('<span>', { class: 'user-data', title: totalFormatted });
          var userCurrency = $('<span>', { class: 'user-data currency', text: totalFormatted });

          if (total >= 0) {
              userCurrency.addClass('positive');
          } else {
              userCurrency.addClass('negative');
          }

          userData.append(userCurrency);
          parent.append(userData);
      }

      function enhancedSelectedTotalsInit() {
          var parentDiv = document.getElementsByClassName('accounts-header-balances');
          n = parentDiv.length;
          if (n > 0) {
              enhancedSelectedTotalsApply();
          } else {
              setTimeout(enhancedSelectedTotalsInit, 250);
          }
      }

{'fraction_non_alphanumeric': 0.11263157894736842, 'fraction_numerical': 0.004605263157894736, 'mean_word_length': 2.177675585284281, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, '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': '3431717', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1952, 'n_words': 363}