<commit_before>
// "use strict"

var g_jsonObj;
var VIEW_SIZE = 1500;
var SCALE = VIEW_SIZE/5;
var RADIUS = 4;
var TEST = true;
var TEST = false;
;

var g_svgContainer;
var g_currentTrack;

var PLAY_MODE = {
    WEB: {value:0, text: 'Play on Browser'},
    SPOTIFY: {value:0, text: 'Play on Spotify'}
}

var COLOR_PLAY = "#E64A19";
var COLOR_NONE = "#757575";

var g_play_mode = PLAY_MODE.WEB;

var currentPlayingId = '';
var nowpending = '';
var spotifyPlayer = '';
var textTitle= '';

function init() {
    console.log('init!!!');
    spotifyPlayer = document.getElementById('spotifyplayer');
    textTitle = document.getElementById('text-title');
    d3.json('output.txt', draw);
}

function getTrackInfo(id) {
    var http_request = new XMLHttpRequest();
    var url = 'https://api.spotify.com/v1/tracks/' + id;
    http_request.open("GET", url, false);
    http_request.send(null);
    g_currentTrack = JSON.parse(http_request.responseText);
    
    return g_currentTrack;
}

function playMusic(id, me) {

    console.log('playMusic()!!')

    window.clearTimeout(nowpending);

    

    if (id == currentPlayingId) {
        console.log('play music');
        // pause
        spotifyPlayer.pause();
        currentPlayingId = '';
    } else {
        // play

        var trackInfo = getTrackInfo(id);
        var previewurl;

        if ('preview_url' in trackInfo) {
            previewurl = trackInfo['preview_url'];
        } else {
            previewurl = null;
        }

        console.log('previewurl : ' + previewurl);

        
        currentPlayingId = id;
            
        if (g_play_mode == PLAY_MODE.WEB) {

            if (previewurl) {
                spotifyPlayer.src = previewurl;
                spotifyPlayer.play();
                }

        } else {
            // play on spotify
            var url = "https://open.spotify.com/track/"  + id;
            var win = window.open(url, '_blank');
            win.focus(url);
            spotifyPlayer.pause();       
        } 
        
        textTitle.textContent = 'Artist:' + g_currentTrack['artists'][0].name + ', Title: '  + g_currentTrack.name<commit_msg>added condition for playing<commit_after>
// "use strict"

var g_jsonObj;
var VIEW_SIZE = 1500;
var SCALE = VIEW_SIZE/5;
var RADIUS = 4;
// var TEST = true;
var TEST = false;


var g_svgContainer;
var g_currentTrack;

var PLAY_MODE = {
    WEB: {value:0, text: 'Play on Browser'},
    SPOTIFY: {value:0, text: 'Play on Spotify'}
}

var COLOR_PLAY = "#E64A19";
var COLOR_NONE = "#757575";

var g_play_mode = PLAY_MODE.WEB;

var currentPlayingId = '';
var nowpending = '';
var spotifyPlayer = '';
var textTitle= '';

function init() {
    console.log('init!!!');
    spotifyPlayer = document.getElementById('spotifyplayer');
    textTitle = document.getElementById('text-title');
    d3.json('output.txt', draw);
}

function getTrackInfo(id) {
    var http_request = new XMLHttpRequest();
    var url = 'https://api.spotify.com/v1/tracks/' + id;
    http_request.open("GET", url, false);
    http_request.send(null);
    g_currentTrack = JSON.parse(http_request.responseText);
    
    return g_currentTrack;
}

function playMusic(id, me) {

    console.log('playMusic()!!')

    window.clearTimeout(nowpending);

    

    if (id == currentPlayingId) {
        console.log('play music');
        // pause
        spotifyPlayer.pause();
        currentPlayingId = '';
    } else {
        // play

        var trackInfo = getTrackInfo(id);
        var previewurl;

        if ('preview_url' in trackInfo) {
            previewurl = trackInfo['preview_url'];
        } else {
            previewurl = null;
        }

        console.log('previewurl : ' + previewurl);

        
        currentPlayingId = id;
            
        if (g_play_mode == PLAY_MODE.WEB && previewurl ) {

            spotifyPlayer.src = previewurl;
            spotifyPlayer.play();

        } else {
            // play on spotify
            var url = "https://open.spotify.com/track/"  + id;
            var win = window.open(url, '_blank');
            win.focus(url);
            spotifyPlayer.pause();       
        } 
        
        textTitle.textContent = 'Artist:' + g_currentTrack['artists'][0].name + ', Title: '  + g_currentTrack.name
{'fraction_non_alphanumeric': 0.1355019892347297, 'fraction_numerical': 0.009829159840861221, 'mean_word_length': 2.302936630602782, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '2529982', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1338, 'n_words': 285}