<commit_before>// 'use strict';

chrome.downloads.onCreated.addListener(function(item) {
    downloadCreated();
});

chrome.downloads.onChanged.addListener(function(item) {
    // if (getSetting() === true) {
    downloadChanged();
    // }
});

chrome.runtime.onStartup.addListener(function() {
    console.log("Extension onStartup");
});

chrome.runtime.onInstalled.addListener(function() {
    console.log("Extension Installed");
    downloadChanged();
});

chrome.runtime.onUpdateAvailable.addListener(function() {
    console.log("Extension Updated");
});

// onInstalled
// onUninstalled
// onEnabled
// onDisabled
// chrome.management.onEnabled.addListener(function(info) {
//     console.log('1'+info);
// });

/*
function onInstall() {
    console.log("Extension Installed");
  }

  function onUpdate() {
    console.log("Extension Updated");
  }

  function getVersion() {
    var details = chrome.app.getDetails();
    return details.version;
  }

  // Check if the version has changed.
  var currVersion = getVersion();
  var prevVersion = localStorage['version']
  if (currVersion != prevVersion) {
    // Check if we just installed this extension.
    if (typeof prevVersion == 'undefined') {
      onInstall();
    } else {
      onUpdate();
    }
    localStorage['version'] = currVersion;
  }*/

//called when the icon is clicked
chrome.browserAction.onClicked.addListener(function(tab) {
    var openUrl = 'chrome://downloads/';

    // chrome.tabs.getAllInWindow(null, function (tabs) {
    chrome.tabs.query({
        "currentWindow": true
    }, function(tabs) {
        // console.log("\n");
        tabs.forEach(function(tab) {
            // console.log( tab.url );
            if (tab.url == openUrl) {
                chrome.tabs.update(tab.id, {
                    selected: true
                });
                openUrl = false;
                return false;
            }
        });

        // console.log( openUrl );
        if (openUrl !== false) {
            chrome.tabs.create({
                url: openUrl,
                selected: true
            });
        }
    });

});

function getSetting() {
    if (localStorage.showdownbar == 'true') {
        return true;
    }
    return false;
}

function downloadCreated() {
    chrome.downloads.setShelfEnabled(getSetting());
}


function wait(ms){
   var start = new Date().getTime();
   var end = start;
   while(end < start + ms) {
     end = new Date().getTime();
  }
}

function downloadChanged() {
    chrome.downloads.search({}, function(items) {
        var now_progress = false;
        var count = 0;

        items.forEach(function(item) {
            // console.log(item.state);
            if (item.state == 'in_progress') {
                now_progress = true;
                count = ++count;
                // console.log(count);
                // console.log(item);
                if (count === 1) {
                    // fileSize
                    // totalBytes
                    count = Math.round(item.bytesReceived * 100 / item.fileSize) + "%";
                    // var percent = setInterval(downloadChanged(), 1000 * 5);
                    wait(1000 * 1);
                    downloadChanged();
                // } else {
                //     clearInterval(percent);
                }
                // return false;
            }
            // else if ((item.state.current == 'complete') && item.endTime && !item.error)
            //     now_progress = false;
            // else
            //   now_progress = true;
        });
        if (getSetting() === true && now_progress === false) {
            chrome.downloads.setShelfEnabled(now_progress);
        }
        setToolbarText(count);
        // setToolbarText('nan');
    });
}
var circleNum = 0;

// function isInt(n){
//     return Number(n) === n && n % 1 === 0;
// }
//
// function isFloat(n){
//     return Number(n) === n && n % 1 !== 0;
// }

// function flashBadge(message) {
function setToolbarText(message) {
    circleNum = circleNum < 2 ? ++circleNum : 0;
    // if (circleNum < 2) {
    //   circleNum = ++circleNum;
    // } else {
    //   circleNum = 0;
    // }
    // console.log("circleNum > " + circleNum);

    if (message === 0) {
        message = "";
    } else if (Number.isInteger(message) === false) {
        var loadingSymbol = ["|--", "-|-", "--|"];
        message = loadingSymbol[circleNum];
        // console.log(" > " + message);
    }
    chrome.browserAction.setBadgeBackgroundColor({
        color: "black"
    });
    chrome.browserAction.setBadgeText({
        text: message
        // text: message.toString()
    });
}<commit_msg>fix loop msg<commit_after>// 'use strict';

chrome.downloads.onCreated.addListener(function(item) {
    downloadCreated();
});

chrome.downloads.onChanged.addListener(function(item) {
    // if (getSetting() === true) {
    downloadChanged();
    // }
});

chrome.runtime.onStartup.addListener(function() {
    console.log("Extension onStartup");
});

chrome.runtime.onInstalled.addListener(function() {
    console.log("Extension Installed");
    downloadChanged();
});

chrome.runtime.onUpdateAvailable.addListener(function() {
    console.log("Extension Updated");
});

// onInstalled
// onUninstalled
// onEnabled
// onDisabled
// chrome.management.onEnabled.addListener(function(info) {
//     console.log('1'+info);
// });

/*
function onInstall() {
    console.log("Extension Installed");
  }

  function onUpdate() {
    console.log("Extension Updated");
  }

  function getVersion() {
    var details = chrome.app.getDetails();
    return details.version;
  }

  // Check if the version has changed.
  var currVersion = getVersion();
  var prevVersion = localStorage['version']
  if (currVersion != prevVersion) {
    // Check if we just installed this extension.
    if (typeof prevVersion == 'undefined') {
      onInstall();
    } else {
      onUpdate();
    }
    localStorage['version'] = currVersion;
  }*/

//called when the icon is clicked
chrome.browserAction.onClicked.addListener(function(tab) {
    var openUrl = 'chrome://downloads/';

    // chrome.tabs.getAllInWindow(null, function (tabs) {
    chrome.tabs.query({
        "currentWindow": true
    }, function(tabs) {
        // console.log("\n");
        tabs.forEach(function(tab) {
            // console.log( tab.url );
            if (tab.url == openUrl) {
                chrome.tabs.update(tab.id, {
                    selected: true
                });
                openUrl = false;
                return false;
            }
        });

        // console.log( openUrl );
        if (openUrl !== false) {
            chrome.tabs.create({
                url: openUrl,
                selected: true
            });
        }
    });

});

function getSetting() {
    if (localStorage.showdownbar == 'true') {
        return true;
    }
    return false;
}

function downloadCreated() {
    chrome.downloads.setShelfEnabled(getSetting());
}


function wait(ms){
   var start = new Date().getTime();
   var end = start;
   while(end < start + ms) {
     end = new Date().getTime();
  }
}

function downloadChanged() {
    chrome.downloads.search({}, function(items) {
        var now_progress = false;
        var count = 0;

        items.forEach(function(item) {
            // console.log(item.state);
            if (item.state == 'in_progress') {
                now_progress = true;
                count = ++count;
                // console.log(count);
                // console.log(item);
                if (count === 1) {
                    // fileSize
                    // totalBytes
                    count = Math.round(item.bytesReceived * 100 / item.fileSize);
                    // var percent = setInterval(downloadChanged(), 1000 * 5);
                    wait(1000 * 1);
                    downloadChanged();
                // } else {
                //     clearInterval(percent);
                }
                // return false;
            }
            // else if ((item.state.current == 'complete') && item.endTime && !item.error)
            //     now_progress = false;
            // else
            //   now_progress = true;
        });
        if (getSetting() === true && now_progress === false) {
            chrome.downloads.setShelfEnabled(now_progress);
        }
        setToolbarText(count);
        // setToolbarText('nan');
    });
}

// function isInt(n){
//     return Number(n) === n && n % 1 === 0;
// }
//
// function isFloat(n){
//     return Number(n) === n && n % 1 !== 0;
// }

var circleNum = 0;
// function flashBadge(message) {
function setToolbarText(message) {
    // if (circleNum < 2) {
    //   circleNum = ++circleNum;
    // } else {
    //   circleNum = 0;
    // }
    // console.log("circleNum > " + circleNum);

    if (message === 0) {
        message = "";
    } else if (message > 0) {
        message = message.toString() + "%";
    } else if (Number.isInteger(message) === false) {
        var loadingSymbol = ["|--", "-|-", "--|"];
        circleNum = circleNum < 2 ? ++circleNum : 0;
        message = loadingSymbol[circleNum];
    }
    // console.log("message > " + message);
    chrome.browserAction.setBadgeBackgroundColor({
        color: "black"
    });
    chrome.browserAction.setBadgeText({
        text: message
    });
}
{'fraction_non_alphanumeric': 0.15435525192143468, 'fraction_numerical': 0.0056575576430401365, 'mean_word_length': 1.8704044117647058, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5459927', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2648, 'n_words': 528}