<commit_before>
var eightTracksTab = undefined;


function set8TracksTab(){
	chrome.tabs.query({'url':'*://8tracks.com/*'}, function(tabs) {
		if(tabs.length > 0)
		{
			eightTracksTab = tabs[0];
			observeTab(eightTracksTab);

			if(tabs.length > 1)
			{
				console.log("You have more than one tab open on 8tracks.");
			}
		}
		else
		{
			eightTracksTab = undefined;
		}
	});
}

function observeTab(tab){
	chrome.tabs.executeScript(tab.id, {
        file: 'js/observer.js'
	});
}

(function() {
	chrome.commands.onCommand.addListener(function(command) {
		if (eightTracksTab)
		{
			if (command == 'next')
			{
				chrome.tabs.executeScript(eightTracksTab.id, {code : "document.getElementById('player_skip_button').click();"});
			}
			else if (command == 'pause')
			{
				chrome.tabs.executeScript(eightTracksTab.id, {code : "document.getElementById('player_pause_button').style.display"}, function(results){
					if (results[0] == 'none')
					{
						chrome.tabs.executeScript(eightTracksTab.id, {code : "document.getElementById('player_play_button').click();"});
					}
					else
					{
						chrome.tabs.executeScript(eightTracksTab.id, {code : "document.getElementById('player_pause_button').click();"});
					}
				});
			}
		}
	});

	chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
		if (changeInfo['status'] == 'complete' && !eightTracksTab)
		{
			if (tab.url.indexOf("://8tracks.com") > -1)
			{
				set8TracksTab();
			}
		}
	});

	chrome.tabs.onRemoved.addListener(function(tabId, removeInfo) {
		if (eightTracksTab)
		{
			if (eightTracksTab.id == tabId)
			{
				set8TracksTab();
			}
		}
	});

	chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
		var notif_settings_key = 'com.8tracks.enable_notifs';
	
		chrome.storage.local.get(notif_settings_key, function(items) {
			if(items[notif_settings_key] == true)
			{
				if (message['message'] && message['message'] == 'com.8tracks.new_track')
				{
					var data = message['data'];

					var notification = {
						type: 'basic',
						title: '8tracks',
						message: data['title'] + ' by ' + data['artist'],
						iconUrl: '/img/icon128.png',
						appIconMaskUrl: '/img/icon16.png',
						isClickable: true,
						eventTime: (Date.now() + 5000)
					};
					
					if (data['img'])
					{
						notification['iconUrl'] = data['img'];
					}
					
					chrome.notifications.create('', notification, function(notificationId) {
					});
				}
			}
		});
	});

	chrome.notifications.onClicked.addListener(function(notificationId) {
		if (eightTracksTab)
		{<commit_msg>small refactoring<commit_after>
var eightTracksTab = undefined;


function set8TracksTab(){
	chrome.tabs.query({'url':'*://8tracks.com/*'}, function(tabs) {
		if(tabs.length > 0)
		{
			eightTracksTab = tabs[0];
			observeTab(eightTracksTab);

			if(tabs.length > 1)
			{
				console.log("You have more than one tab open on 8tracks.");
			}
		}
		else
		{
			eightTracksTab = undefined;
		}
	});
}

function observeTab(tab){
	chrome.tabs.executeScript(tab.id, {
        file: 'js/observer.js'
	});
}

(function() {
	chrome.commands.onCommand.addListener(function(command) {
		if (eightTracksTab)
		{
			if (command == 'next')
			{
				chrome.tabs.executeScript(eightTracksTab.id, {code : "document.getElementById('player_skip_button').click();"});
			}
			else if (command == 'pause')
			{
				chrome.tabs.executeScript(eightTracksTab.id, {code : "document.getElementById('player_pause_button').style.display"}, function(results){
					if (results[0] == 'none')
					{
						chrome.tabs.executeScript(eightTracksTab.id, {code : "document.getElementById('player_play_button').click();"});
					}
					else
					{
						chrome.tabs.executeScript(eightTracksTab.id, {code : "document.getElementById('player_pause_button').click();"});
					}
				});
			}
		}
	});

	chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
		if (changeInfo['status'] == 'complete' && !eightTracksTab)
		{
			if (tab.url.indexOf("://8tracks.com") > -1)
			{
				set8TracksTab();
			}
		}
	});

	chrome.tabs.onRemoved.addListener(function(tabId, removeInfo) {
		if (eightTracksTab)
		{
			if (eightTracksTab.id == tabId)
			{
				set8TracksTab();
			}
		}
	});

	chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
		var notif_settings_key = 'com.8tracks.enable_notifs';
	
		chrome.storage.local.get(notif_settings_key, function(items) {
			if(items[notif_settings_key] == true)
			{
				if (request.message && request.message == 'com.8tracks.new_track')
				{
					var data = request.data;

					var notification = {
						type: 'basic',
						title: '8tracks',
						message: data.title + ' by ' + data.artist,
						iconUrl: '/img/icon128.png',
						appIconMaskUrl: '/img/icon16.png',
						isClickable: true,
						eventTime: (Date.now() + 5000)
					};
					
					if (data.img)
					{
						notification.iconUrl = data.img;
					}
					
					chrome.notifications.create('', notification, function(notificationId) {
					});
				}
			}
		});
	});

	chrome.notifications.onClicked.addListener(function(notificationId) {
		if (eightTracksTab)
		{
{'fraction_non_alphanumeric': 0.1653726708074534, 'fraction_numerical': 0.008928571428571428, 'mean_word_length': 3.3013355592654423, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, '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': '4298459', 'n_tokens_mistral': 2228, 'n_tokens_neox': 1757, 'n_words': 251}