<commit_before><!DOCTYPE html>
<html>

<head>
  <title>Playlist sorting for Spotify</title>
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
  <link rel="stylesheet" href="css/default.css">
</head>

<body>
  <div class="header">
    <h3>Playlist sorting for Spotify</h3>
    <hr/>
    <div id="app-description">
      Sort your Spotify playlists online
    </div>
  </div>
  <div class="main">
    <div class="container">
      <div id="login">
        <a href="http://localhost:8888/spotify_playlist_shuffle/login" class="btn btn-primary">Log in with Spotify</a>
      </div>
      <div id="loggedin">
        <div id="user-info-container">
          <div id="user-profile">
          </div>
          <!--
          <button class="btn btn-default" id="obtain-new-token">Obtain new token using the refresh token</button>
          -->
        </div>
        <div id="playlist-container">
          <button class="btn btn-default" id="get-user-playlists">Get Playlists</button>
          <div id="user-playlists">
          </div>
        </div>
        <div id="user-current-playlist-container">
          <div id="user-current-playlist"></div>
          <button class="btn btn-default" id="upload-changed-playlist">Upload Changed Playlist</button>
          <div id="upload-status"></div>
        </div>
      </div>
    </div>
  </div>
  <div class="footer">
    <hr/>
    <div>
      Made by <NAME> &copy; 2017 · Check out the
      <a href="https://github.com/gordody/spotify-playlist-shuffle" target="_blank">code on GitHub
        <img src="img/GitHub-Mark-32px.png" height="16" width="16">
      </a>
    </div>
  </div>
  <script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.10/handlebars.runtime.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/sortablejs@1.6.1/Sortable.min.js"></script>
  <script src="libs/spotify-web-api/0.22.1/spotify-web-api.js"></script>
  <script src="libs/just-handlebars-helpers/1.0.13/h.min.js"></script>
  <script src="handlebars_out/templates.js"></script>    
  <script>
    (function () {
      var app_root = "/spotify_playlist_shuffle/";  // TODO: get it from node.js

      // Register helpers for Handlebars
      H.registerHelpers(Handlebars);

      /*
      $(document).ready(function() {

      });

      /**
       * Obtains parameters from the hash of the URL
       * @return Object
       */
      function getHashParams() {
        var hashParams = {};
        var e, r = /([^&;=]+)=?([^&;]*)/g,
          q = window.location.hash.substring(1);
        while (e = r.exec(q)) {
          hashParams[e[1]] = decodeURIComponent(e[2]);
        }
        return hashParams;
      }

      var userProfileTemplate = Handlebars.templates.user_profile_template;
      var userProfilePlaceholder = document.getElementById('user-profile');

      var userPlaylistsTemplate = Handlebars.templates.user_playlist_template;
      var userPlaylistsPlaceholder = document.getElementById('user-playlists');

      var userCurrentPlaylistTemplate = Handlebars.templates.user_current_playlist_template;
      var userCurrentPlaylistPlaceholder = document.getElementById('user-current-playlist');

      var userProfile;
      var userPlaylists;
      var userCurrentPlaylist;
      var sortablePlaylist;

      var params = getHashParams();

      var access_token = params.access_token,
        refresh_token = params.refresh_token,
        error = params.error;

      var spotifyApi = new SpotifyWebApi();
      spotifyApi.setAccessToken(access_token);

      if (error) {
        alert('There was an error during the authentication');
      } else {
        if (access_token) {
          // render oauth info
          console.log('Tokens found in url', {
            access_token: access_token,
            refresh_token: refresh_token
          });

          spotifyApi.getMe().then(data => {
            userProfilePlaceholder.innerHTML = userProfileTemplate(data);
            userProfile = data;
            $('#login').hide();
            $('#loggedin').show();
          }).catch(err => {
            $('#login').show();
          });
        } else {
          // render initial screen
          $('#login').show();
          $('#loggedin').hide();
        }

        $('#obtain-new-token').on('click', function () {
          $.ajax({
            url: app_root + 'refresh_token',
            data: {
              'refresh_token': refresh_token
            }
          }).done(function (data) {
            access_token = data.access_token;
            spotifyApi.setAccessToken(access_token);
            console.log('New tokens obtained', {
              access_token: access_token,
              refresh_token: refresh_token
            });
          });
        }, false);<commit_msg>get html base path from window.location<commit_after><!DOCTYPE html>
<html>

<head>
  <title>Playlist sorting for Spotify</title>
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
  <link rel="stylesheet" href="css/default.css">
</head>

<body>
  <div class="header">
    <h3>Playlist sorting for Spotify</h3>
    <hr/>
    <div id="app-description">
      Sort your Spotify playlists online
    </div>
  </div>
  <div class="main">
    <div class="container">
      <div id="login">
        <a href="http://localhost:8888/spotify_playlist_shuffle/login" class="btn btn-primary">Log in with Spotify</a>
      </div>
      <div id="loggedin">
        <div id="user-info-container">
          <div id="user-profile">
          </div>
          <!--
          <button class="btn btn-default" id="obtain-new-token">Obtain new token using the refresh token</button>
          -->
        </div>
        <div id="playlist-container">
          <button class="btn btn-default" id="get-user-playlists">Get Playlists</button>
          <div id="user-playlists">
          </div>
        </div>
        <div id="user-current-playlist-container">
          <div id="user-current-playlist"></div>
          <button class="btn btn-default" id="upload-changed-playlist">Upload Changed Playlist</button>
          <div id="upload-status"></div>
        </div>
      </div>
    </div>
  </div>
  <div class="footer">
    <hr/>
    <div>
      Made by <NAME> &copy; 2017 · Check out the
      <a href="https://github.com/gordody/spotify-playlist-shuffle" target="_blank">code on GitHub
        <img src="img/GitHub-Mark-32px.png" height="16" width="16">
      </a>
    </div>
  </div>
  <script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.10/handlebars.runtime.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/sortablejs@1.6.1/Sortable.min.js"></script>
  <script src="libs/spotify-web-api/0.22.1/spotify-web-api.js"></script>
  <script src="libs/just-handlebars-helpers/1.0.13/h.min.js"></script>
  <script src="handlebars_out/templates.js"></script>    
  <script>
    (function () {
      // Register helpers for Handlebars
      H.registerHelpers(Handlebars);

      function getLocationRoot() {
        var loc = window.location;
        return loc.protocol + '//' + loc.hostname + ':' + loc.port + '/' + loc.pathname;
      }

      /*
      $(document).ready(function() {

      });

      /**
       * Obtains parameters from the hash of the URL
       * @return Object
       */
      function getHashParams() {
        var hashParams = {};
        var e, r = /([^&;=]+)=?([^&;]*)/g,
          q = window.location.hash.substring(1);
        while (e = r.exec(q)) {
          hashParams[e[1]] = decodeURIComponent(e[2]);
        }
        return hashParams;
      }

      var userProfileTemplate = Handlebars.templates.user_profile_template;
      var userProfilePlaceholder = document.getElementById('user-profile');

      var userPlaylistsTemplate = Handlebars.templates.user_playlist_template;
      var userPlaylistsPlaceholder = document.getElementById('user-playlists');

      var userCurrentPlaylistTemplate = Handlebars.templates.user_current_playlist_template;
      var userCurrentPlaylistPlaceholder = document.getElementById('user-current-playlist');

      var userProfile;
      var userPlaylists;
      var userCurrentPlaylist;
      var sortablePlaylist;

      var params = getHashParams();

      var access_token = params.access_token,
        refresh_token = params.refresh_token,
        error = params.error;

      var spotifyApi = new SpotifyWebApi();
      spotifyApi.setAccessToken(access_token);

      if (error) {
        alert('There was an error during the authentication');
      } else {
        if (access_token) {
          // render oauth info
          console.log('Tokens found in url', {
            access_token: access_token,
            refresh_token: refresh_token
          });

          spotifyApi.getMe().then(data => {
            userProfilePlaceholder.innerHTML = userProfileTemplate(data);
            userProfile = data;
            $('#login').hide();
            $('#loggedin').show();
          }).catch(err => {
            $('#login').show();
          });
        } else {
          // render initial screen
          $('#login').show();
          $('#loggedin').hide();
        }

        $('#obtain-new-token').on('click', function () {
          $.ajax({
            url: getLocationRoot() + 'refresh_token',
            data: {
              'refresh_token': refresh_token
            }
          }).done(function (data) {
            access_token = data.access_token;
            spotifyApi.setAccessToken(access_token);
            console.log('New tokens obtained', {
              access_token: access_token,
              refresh_token: refresh_token
            });
          });
        }, false);
{'fraction_non_alphanumeric': 0.15136827224073512, 'fraction_numerical': 0.008078360092901141, 'mean_word_length': 2.302434144714905, 'pattern_counts': {'":': 0, '<': 141, '<?xml version=': 0, '>': 145, 'https://': 2, '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': '4466207', 'n_tokens_mistral': 3039, 'n_tokens_neox': 2975, 'n_words': 550}