-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
97 lines (84 loc) · 3.5 KB
/
Copy pathbackground.js
File metadata and controls
97 lines (84 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Background script for Modern New Tab extension
// Initialize extension on install
browser.runtime.onInstalled.addListener((details) => {
if (details.reason === 'install') {
console.log('Modern New Tab extension installed');
// Set default settings if they don't exist
browser.storage.local.get('newTabSettings').then((result) => {
if (!result.newTabSettings) {
const defaultSettings = {
searchEngine: 'google',
customSearchEngine: null,
theme: 'dark',
backgroundType: 'color',
backgroundColor: '#1a1a2e',
gradientColor1: '#1a1a2e',
gradientColor2: '#16213e',
backgroundImage: null,
bookmarks: [
{ name: 'YouTube', url: 'https://youtube.com', icon: '📺' },
{ name: 'GitHub', url: 'https://github.com', icon: '🐙' },
{ name: 'Reddit', url: 'https://reddit.com', icon: '🔴' },
{ name: 'Twitter', url: 'https://twitter.com', icon: '🐦' }
]
};
browser.storage.local.set({ newTabSettings: defaultSettings });
}
});
} else if (details.reason === 'update') {
console.log('Modern New Tab extension updated');
}
});
// Handle extension startup
browser.runtime.onStartup.addListener(() => {
console.log('Modern New Tab extension started');
});
// Listen for storage changes (for potential future sync features)
browser.storage.onChanged.addListener((changes, namespace) => {
if (namespace === 'local' && changes.newTabSettings) {
console.log('Settings updated:', changes.newTabSettings.newValue);
}
});
// Handle any runtime messages (for potential future features)
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
switch (request.action) {
case 'getSettings':
browser.storage.local.get('newTabSettings').then((result) => {
sendResponse(result.newTabSettings || {});
});
return true; // Will respond asynchronously
case 'saveSettings':
browser.storage.local.set({ newTabSettings: request.settings }).then(() => {
sendResponse({ success: true });
}).catch((error) => {
sendResponse({ success: false, error: error.message });
});
return true; // Will respond asynchronously
default:
sendResponse({ error: 'Unknown action' });
}
});
// Optional: Add context menu items (can be enabled in future versions)
/*
browser.contextMenus.create({
id: 'add-bookmark',
title: 'Add to New Tab Bookmarks',
contexts: ['page']
});
browser.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === 'add-bookmark') {
// Add current page to bookmarks
browser.storage.local.get('newTabSettings').then((result) => {
const settings = result.newTabSettings || {};
const bookmarks = settings.bookmarks || [];
bookmarks.push({
name: tab.title,
url: tab.url,
icon: tab.title.charAt(0).toUpperCase()
});
settings.bookmarks = bookmarks;
browser.storage.local.set({ newTabSettings: settings });
});
}
});
*/