diff --git a/src/eventPage.js b/src/eventPage.js index f6c543c..8ffeb3f 100644 --- a/src/eventPage.js +++ b/src/eventPage.js @@ -5,17 +5,21 @@ chrome.browserAction.onClicked.addListener(function(){ }); }); +// Listen for tabs getting created. chrome.tabs.onCreated.addListener(function (tab) { - console.log('created', arguments) + // If a new tab is opened (without any URL), check user's + // replace Tab setting and act accordingly. if (tab.url === 'chrome://newtab/') { - chrome.tabs.update(tab.id, { - url: chrome.extension.getURL('index.html') - }, function callback() { - console.log('ho gaya'); + chrome.storage.sync.get({ + replaceNewTab: true + }, function(items) { + if (items.replaceNewTab) { + chrome.tabs.update(tab.id, { + url: chrome.extension.getURL('index.html') + }, function callback() { + console.log('ho gaya'); + }); + } }); } -}); - -chrome.tabs.onUpdated.addListener(function () { - console.log('updated', arguments) }); \ No newline at end of file diff --git a/src/options.html b/src/options.html index cba4b29..2528ef0 100644 --- a/src/options.html +++ b/src/options.html @@ -35,6 +35,11 @@ Preserve last written code + +
 
diff --git a/src/options.js b/src/options.js index 54c4682..bbc011f 100644 --- a/src/options.js +++ b/src/options.js @@ -1,17 +1,21 @@ // Restores preferences from chrome.storage. function restoreOptions() { chrome.storage.sync.get({ - preserveLastCode: true + preserveLastCode: true, + replaceNewTab: true }, function(items) { document.forms.optionsForm.preserveLastCode.checked = items.preserveLastCode; + document.forms.optionsForm.replaceNewTab.checked = items.replaceNewTab; }); } function saveOptions(e) { var preserveLastCode = document.forms.optionsForm.preserveLastCode.checked; + var replaceNewTab = document.forms.optionsForm.replaceNewTab.checked; chrome.storage.sync.set({ - preserveLastCode: preserveLastCode + preserveLastCode: preserveLastCode, + replaceNewTab: replaceNewTab }, function() { var status = document.getElementById('js-status'); status.textContent = 'Settings saved.';