mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-14 18:46:19 +02:00
add settings for replace tab.
This commit is contained in:
@ -5,17 +5,21 @@ chrome.browserAction.onClicked.addListener(function(){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Listen for tabs getting created.
|
||||||
chrome.tabs.onCreated.addListener(function (tab) {
|
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/') {
|
if (tab.url === 'chrome://newtab/') {
|
||||||
chrome.tabs.update(tab.id, {
|
chrome.storage.sync.get({
|
||||||
url: chrome.extension.getURL('index.html')
|
replaceNewTab: true
|
||||||
}, function callback() {
|
}, function(items) {
|
||||||
console.log('ho gaya');
|
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)
|
|
||||||
});
|
});
|
@ -35,6 +35,11 @@
|
|||||||
Preserve last written code
|
Preserve last written code
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="replaceNewTab">
|
||||||
|
Replace new tab page
|
||||||
|
</label>
|
||||||
|
|
||||||
<div id="js-status" class="status"> </div>
|
<div id="js-status" class="status"> </div>
|
||||||
<button id="js-save-btn" class="btn">Save</button>
|
<button id="js-save-btn" class="btn">Save</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
// Restores preferences from chrome.storage.
|
// Restores preferences from chrome.storage.
|
||||||
function restoreOptions() {
|
function restoreOptions() {
|
||||||
chrome.storage.sync.get({
|
chrome.storage.sync.get({
|
||||||
preserveLastCode: true
|
preserveLastCode: true,
|
||||||
|
replaceNewTab: true
|
||||||
}, function(items) {
|
}, function(items) {
|
||||||
document.forms.optionsForm.preserveLastCode.checked = items.preserveLastCode;
|
document.forms.optionsForm.preserveLastCode.checked = items.preserveLastCode;
|
||||||
|
document.forms.optionsForm.replaceNewTab.checked = items.replaceNewTab;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveOptions(e) {
|
function saveOptions(e) {
|
||||||
var preserveLastCode = document.forms.optionsForm.preserveLastCode.checked;
|
var preserveLastCode = document.forms.optionsForm.preserveLastCode.checked;
|
||||||
|
var replaceNewTab = document.forms.optionsForm.replaceNewTab.checked;
|
||||||
|
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
preserveLastCode: preserveLastCode
|
preserveLastCode: preserveLastCode,
|
||||||
|
replaceNewTab: replaceNewTab
|
||||||
}, function() {
|
}, function() {
|
||||||
var status = document.getElementById('js-status');
|
var status = document.getElementById('js-status');
|
||||||
status.textContent = 'Settings saved.';
|
status.textContent = 'Settings saved.';
|
||||||
|
Reference in New Issue
Block a user