<commit_before>/*                       _____________________________
 *                      |    States + Transitions:    |
 *                      |                             |
 *                      | legend:                     |
 *                      |       user = the user       |
 *                      |         DO = digitalocean   |
 *                      |         us = this content   |
 *                      |              script         |
 *                       -----------------------------
 *
 *
 *
 *                            /{signup,login}
 *                                   |
 *                         (user: submit valid form)
 *                                   |
 *                             (DO: redirect)
 *                                   |
 *                               /droplets
 *                                   |
 *                         (DO: payment added?)
 *                          /                \
 *                        no                 yes
 *                        /                    \
 *                (DO: redirect)          (us: shouldPromptPromo?)
 *                      /                     /            \
 *                  /welcome                 no            yes
 *                    /                     /                \
 *      (DO: email confirmed?)      (us: show overlay)  (us: redirect)
 *          /         \                   /                    |
 *        no         yes       (user: click 'proceed')  /settings/billing
 *       /              \                                      |
 * (user: click )    (user: click)                (us: show overlay w/ promo input)
 * (confirm link)    (add pmnt link)                           |
 *         \            /                                      |
 *       /settings/billing                          (user: enter promo code)
 *               |                                             |
 *  (user: add payment method)                    (user: click 'proceed to uproxy')
 *               |
 *        (DO: redirect)
 *               |
 *          /droplets (see above) ^^^
 *
 */

(function (document, navigator) {

  var isChrome = navigator.userAgent.indexOf('Chrome') !== -1;

  var globalSettingsP = new Promise(function (resolve) {
    if (isChrome) {
      chrome.runtime.sendMessage({globalSettingsRequest: true}, resolve);
    } else {
      self.port.on('globalSettings', function (globalSettings) {
        resolve(globalSettings);
      });
    }
  });

  globalSettingsP.then(function (globalSettings) {

    if (!globalSettings.shouldHijackDO) {
      return;
    }

    function getPageId(url) {
      if (url.indexOf('cloud.digitalocean.com/welcome') !== -1) {
        return 'welcome';
      } else if (url.indexOf('cloud.digitalocean.com/settings/billing') !== -1) {
        return 'billing';
      } else if (url.indexOf('cloud.digitalocean.com/droplets') !== -1) {
        return 'droplets';
      }
    }

    var pageId = getPageId(document.location.href);

    if (pageId === 'droplets') {
      if (shouldPromptPromo()) {
        // Must be on billing page to submit promo codes, so redirect.
        document.location.href = 'https://cloud.digitalocean.com/settings/billing';
      }
      // Proceed to showing the overlay.
    } else if (pageId === 'billing') {
      if (!isPmntAdded()) {
        return;
      }
      // Proceed to showing the overlay.
    } else {
      return;
    }

    // Interpose our overlay.
    var i18nKeyByUIKey = {
      // TODO: Check if user has already completed oauth, if so use different
      // test for this h1?
      h1: 'PROCEED_TO_UPROXY_TITLE',
      msg: 'PROCEED_TO_UPROXY_MSG',
      proceedLink: 'PROCEED_TO_UPROXY',
      promoInput: 'ENTER_PROMO',
      promoAccepted: 'PROMO_ACCEPTED',
      promoFailed: 'PROMO_FAILED',
      processing: 'PROCESSING',
      applyButton: 'APPLY',
    };
    var getLocalAssetUrlP, translationsP;
    if (isChrome) {
      getLocalAssetUrlP = Promise.resolve(chrome.extension.getURL);
      translationsP = new Promise(function (resolve) {
        chrome.runtime.sendMessage({translationsRequest: values(i18nKeyByUIKey)}, resolve);
      });
    } else {
      getLocalAssetUrlP = new Promise(function (resolve) {
        self.port.on('baseUrlFF', function (baseUrl) {
          resolve(function (relUrl) { return baseUrl + relUrl; });
        });
      });
      translationsP = new Promise(function (resolve) {
        self.port.on('translations', resolve);
        self.port.emit('translationsRequest', values(i18nKeyByUIKey));
      });
    }

    var allP = [getLocalAssetUrlP, translationsP];
    Promise.all(allP).then(function (results) {
      var getLocalAssetUrl = results[0];
      var translations = results[1];  // {i18nkey: message}

      var overlay = document.createElement('div');
      overlay.style.position = 'fixed';
      overlay.style.top = '0';
      overlay.style.left = '0';
      overlay.style.bottom = '0';
      overlay.style.right = '0';
      overlay.style.opacity = '.95';
      overlay.style.background = '#12A391';
      overlay.style.zIndex = '10000';
      overlay.style.textAlign = 'center';
      overlay.style.padding = '180px 0 0';

      var closeBtn = document.createElement('img');
      closeBtn.src = getLocalAssetUrl('icons/cloud/ic_close_white_24dp.svg');
      closeBtn.style.cursor = 'pointer';
      closeBtn.style.position = 'fixed';
      closeBtn.style.top = '15px';
      closeBtn.style.right = '20px';
      closeBtn.style.width = '40px';
      closeBtn.onclick = function () { overlay.style.display = 'none'; };
      overlay.appendChild(closeBtn);

      var img = document.createElement('img');
      img.src = getLocalAssetUrl('icons/cloud/overlay_uproxy_do.svg');
      img.style.width = '218px';
      overlay.appendChild(img);

      var textContainer = document.createElement('div');
      textContainer.style.margin = '26px auto';
      textContainer.style.maxWidth = '600px';
      textContainer.style.minWidth = '360px';
      textContainer.style.padding = '0 30px';
      overlay.appendChild(textContainer);

      var h1 = document.createElement('h1');
      h1.textContent = translations[i18nKeyByUIKey.h1];
      h1.style.color = '#fff';
      h1.style.fontFamily = 'Roboto';
      h1.style.fontSize = '24px';
      h1.style.fontWeight = 'bold';
      h1.style.lineHeight = '36px';
      h1.style.wordBreak = 'normal';
      textContainer.appendChild(h1);

      var msgDiv = document.createElement('div');
      msgDiv.textContent = translations[i18nKeyByUIKey.msg];
      msgDiv.style.color = '#fff';
      msgDiv.style.fontFamily = 'Roboto';
      msgDiv.style.fontSize = '14px';
      textContainer.appendChild(msgDiv);

      if (shouldPromptPromo()) {
        var DOtoken = document.querySelector('input[name="authenticity_token"]');
        if (DOtoken) {
          addPromoUI();
        } else {
          console.log('Missing DOtoken. DigitalOcean UI changed?');
        }
      }

      var proceedContainer = document.createElement('div');<commit_msg>bump up text container max width in DO overlay<commit_after>/*                       _____________________________
 *                      |    States + Transitions:    |
 *                      |                             |
 *                      | legend:                     |
 *                      |       user = the user       |
 *                      |         DO = digitalocean   |
 *                      |         us = this content   |
 *                      |              script         |
 *                       -----------------------------
 *
 *
 *
 *                            /{signup,login}
 *                                   |
 *                         (user: submit valid form)
 *                                   |
 *                             (DO: redirect)
 *                                   |
 *                               /droplets
 *                                   |
 *                         (DO: payment added?)
 *                          /                \
 *                        no                 yes
 *                        /                    \
 *                (DO: redirect)          (us: shouldPromptPromo?)
 *                      /                     /            \
 *                  /welcome                 no            yes
 *                    /                     /                \
 *      (DO: email confirmed?)      (us: show overlay)  (us: redirect)
 *          /         \                   /                    |
 *        no         yes       (user: click 'proceed')  /settings/billing
 *       /              \                                      |
 * (user: click )    (user: click)                (us: show overlay w/ promo input)
 * (confirm link)    (add pmnt link)                           |
 *         \            /                                      |
 *       /settings/billing                          (user: enter promo code)
 *               |                                             |
 *  (user: add payment method)                    (user: click 'proceed to uproxy')
 *               |
 *        (DO: redirect)
 *               |
 *          /droplets (see above) ^^^
 *
 */

(function (document, navigator) {

  var isChrome = navigator.userAgent.indexOf('Chrome') !== -1;

  var globalSettingsP = new Promise(function (resolve) {
    if (isChrome) {
      chrome.runtime.sendMessage({globalSettingsRequest: true}, resolve);
    } else {
      self.port.on('globalSettings', function (globalSettings) {
        resolve(globalSettings);
      });
    }
  });

  globalSettingsP.then(function (globalSettings) {

    if (!globalSettings.shouldHijackDO) {
      return;
    }

    function getPageId(url) {
      if (url.indexOf('cloud.digitalocean.com/welcome') !== -1) {
        return 'welcome';
      } else if (url.indexOf('cloud.digitalocean.com/settings/billing') !== -1) {
        return 'billing';
      } else if (url.indexOf('cloud.digitalocean.com/droplets') !== -1) {
        return 'droplets';
      }
    }

    var pageId = getPageId(document.location.href);

    if (pageId === 'droplets') {
      if (shouldPromptPromo()) {
        // Must be on billing page to submit promo codes, so redirect.
        document.location.href = 'https://cloud.digitalocean.com/settings/billing';
      }
      // Proceed to showing the overlay.
    } else if (pageId === 'billing') {
      if (!isPmntAdded()) {
        return;
      }
      // Proceed to showing the overlay.
    } else {
      return;
    }

    // Interpose our overlay.
    var i18nKeyByUIKey = {
      // TODO: Check if user has already completed oauth, if so use different
      // test for this h1?
      h1: 'PROCEED_TO_UPROXY_TITLE',
      msg: 'PROCEED_TO_UPROXY_MSG',
      proceedLink: 'PROCEED_TO_UPROXY',
      promoInput: 'ENTER_PROMO',
      promoAccepted: 'PROMO_ACCEPTED',
      promoFailed: 'PROMO_FAILED',
      processing: 'PROCESSING',
      applyButton: 'APPLY',
    };
    var getLocalAssetUrlP, translationsP;
    if (isChrome) {
      getLocalAssetUrlP = Promise.resolve(chrome.extension.getURL);
      translationsP = new Promise(function (resolve) {
        chrome.runtime.sendMessage({translationsRequest: values(i18nKeyByUIKey)}, resolve);
      });
    } else {
      getLocalAssetUrlP = new Promise(function (resolve) {
        self.port.on('baseUrlFF', function (baseUrl) {
          resolve(function (relUrl) { return baseUrl + relUrl; });
        });
      });
      translationsP = new Promise(function (resolve) {
        self.port.on('translations', resolve);
        self.port.emit('translationsRequest', values(i18nKeyByUIKey));
      });
    }

    var allP = [getLocalAssetUrlP, translationsP];
    Promise.all(allP).then(function (results) {
      var getLocalAssetUrl = results[0];
      var translations = results[1];  // {i18nkey: message}

      var overlay = document.createElement('div');
      overlay.style.position = 'fixed';
      overlay.style.top = '0';
      overlay.style.left = '0';
      overlay.style.bottom = '0';
      overlay.style.right = '0';
      overlay.style.opacity = '.95';
      overlay.style.background = '#12A391';
      overlay.style.zIndex = '10000';
      overlay.style.textAlign = 'center';
      overlay.style.padding = '180px 0 0';

      var closeBtn = document.createElement('img');
      closeBtn.src = getLocalAssetUrl('icons/cloud/ic_close_white_24dp.svg');
      closeBtn.style.cursor = 'pointer';
      closeBtn.style.position = 'fixed';
      closeBtn.style.top = '15px';
      closeBtn.style.right = '20px';
      closeBtn.style.width = '40px';
      closeBtn.onclick = function () { overlay.style.display = 'none'; };
      overlay.appendChild(closeBtn);

      var img = document.createElement('img');
      img.src = getLocalAssetUrl('icons/cloud/overlay_uproxy_do.svg');
      img.style.width = '218px';
      overlay.appendChild(img);

      var textContainer = document.createElement('div');
      textContainer.style.margin = '26px auto';
      textContainer.style.maxWidth = '700px';
      textContainer.style.minWidth = '360px';
      textContainer.style.padding = '0 30px';
      overlay.appendChild(textContainer);

      var h1 = document.createElement('h1');
      h1.textContent = translations[i18nKeyByUIKey.h1];
      h1.style.color = '#fff';
      h1.style.fontFamily = 'Roboto';
      h1.style.fontSize = '24px';
      h1.style.fontWeight = 'bold';
      h1.style.lineHeight = '36px';
      h1.style.wordBreak = 'normal';
      textContainer.appendChild(h1);

      var msgDiv = document.createElement('div');
      msgDiv.textContent = translations[i18nKeyByUIKey.msg];
      msgDiv.style.color = '#fff';
      msgDiv.style.fontFamily = 'Roboto';
      msgDiv.style.fontSize = '14px';
      textContainer.appendChild(msgDiv);

      if (shouldPromptPromo()) {
        var DOtoken = document.querySelector('input[name="authenticity_token"]');
        if (DOtoken) {
          addPromoUI();
        } else {
          console.log('Missing DOtoken. DigitalOcean UI changed?');
        }
      }

      var proceedContainer = document.createElement('div');
{'fraction_non_alphanumeric': 0.12416602289486621, 'fraction_numerical': 0.011236744153381557, 'mean_word_length': 1.4838653410081981, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 54, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1879594', 'n_tokens_mistral': 4107, 'n_tokens_neox': 3871, 'n_words': 741}