Skip to content

Commit 8f86c8d

Browse files
committed
fix: Remove inline event handlers to comply with CSP
- Replace all onclick handlers with proper event listeners - Fix gallery buttons (download, copy, delete, carousel navigation) - Fix widget control buttons (minimize, delete) - Add attachGalleryEventListeners() and attachCarouselEventListeners() - Use data attributes for event delegation - Remove all code comments from JavaScript files - Resolve CSP violation errors in console
1 parent 7fb4125 commit 8f86c8d

8 files changed

Lines changed: 106 additions & 392 deletions

File tree

background.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@ chrome.runtime.onInstalled.addListener(() => {
44
title: 'Add to To-Do List',
55
contexts: ['selection']
66
});
7-
87
chrome.contextMenus.create({
98
id: 'addToTodoLink',
109
title: 'Add Link to To-Do List',
1110
contexts: ['link']
1211
});
13-
1412
chrome.contextMenus.create({
1513
id: 'saveToGallery',
1614
title: 'Save to Chaos Gallery',
1715
contexts: ['image']
1816
});
1917
});
20-
2118
chrome.contextMenus.onClicked.addListener((info, tab) => {
2219
if (info.menuItemId === 'addToTodoText') {
2320
const todoItem = {
@@ -44,15 +41,13 @@ chrome.contextMenus.onClicked.addListener((info, tab) => {
4441
saveImageToGallery(info, tab);
4542
}
4643
});
47-
4844
function addTodoItem(item) {
4945
chrome.storage.sync.get(['chaosTodos'], (result) => {
5046
const todos = result.chaosTodos || [];
5147
todos.unshift(item);
5248
chrome.storage.sync.set({ chaosTodos: todos });
5349
});
5450
}
55-
5651
function saveImageToGallery(info, tab) {
5752
const imageData = {
5853
url: info.srcUrl,
@@ -61,8 +56,6 @@ function saveImageToGallery(info, tab) {
6156
pageTitle: tab.title,
6257
timestamp: Date.now()
6358
};
64-
65-
// Send message to the new tab page to add the image
6659
chrome.tabs.query({ url: 'chrome-extension://*/newtab.html' }, (tabs) => {
6760
tabs.forEach(t => {
6861
chrome.tabs.sendMessage(t.id, {
@@ -71,8 +64,6 @@ function saveImageToGallery(info, tab) {
7164
});
7265
});
7366
});
74-
75-
// Also store it directly in case no tab is open
7667
chrome.storage.local.get(['chaosGallery'], (result) => {
7768
const images = result.chaosGallery || [];
7869
images.unshift({

bookmarks.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
11
const bookmarkSearch = document.getElementById('bookmarkSearch');
22
const bookmarksList = document.getElementById('bookmarksList');
3-
43
let allBookmarks = [];
54
let searchQuery = '';
6-
75
function loadBookmarks() {
86
chrome.bookmarks.getTree((bookmarkTreeNodes) => {
97
allBookmarks = [];
108
processBookmarkNode(bookmarkTreeNodes[0]);
119
renderBookmarks();
1210
});
1311
}
14-
1512
function processBookmarkNode(node) {
1613
if (node.url) {
1714
allBookmarks.push(node);
1815
}
19-
2016
if (node.children) {
2117
node.children.forEach(child => processBookmarkNode(child));
2218
}
2319
}
24-
2520
function getFilteredBookmarks() {
2621
if (!searchQuery) return allBookmarks;
27-
2822
const query = searchQuery.toLowerCase();
2923
return allBookmarks.filter(bookmark =>
3024
(bookmark.title && bookmark.title.toLowerCase().includes(query)) ||
3125
(bookmark.url && bookmark.url.toLowerCase().includes(query))
3226
);
3327
}
34-
3528
function renderBookmarks() {
3629
const filtered = getFilteredBookmarks();
37-
3830
if (filtered.length === 0) {
3931
bookmarksList.innerHTML = `
4032
<div style="text-align: center; padding: 40px; color: #71717a;">
@@ -44,11 +36,9 @@ function renderBookmarks() {
4436
`;
4537
return;
4638
}
47-
4839
bookmarksList.innerHTML = filtered.map(bookmark => {
4940
const favicon = `https://www.google.com/s2/favicons?domain=${new URL(bookmark.url).hostname}&sz=32`;
5041
const displayUrl = new URL(bookmark.url).hostname;
51-
5242
return `
5343
<a href="${bookmark.url}" class="bookmark-item" target="_blank">
5444
<img src="${favicon}" class="bookmark-favicon" onerror="this.style.display='none'">
@@ -58,21 +48,17 @@ function renderBookmarks() {
5848
`;
5949
}).join('');
6050
}
61-
6251
function escapeHtml(text) {
6352
const div = document.createElement('div');
6453
div.textContent = text;
6554
return div.innerHTML;
6655
}
67-
6856
bookmarkSearch.addEventListener('input', (e) => {
6957
searchQuery = e.target.value.trim();
7058
renderBookmarks();
7159
});
72-
7360
chrome.bookmarks.onCreated.addListener(loadBookmarks);
7461
chrome.bookmarks.onRemoved.addListener(loadBookmarks);
7562
chrome.bookmarks.onChanged.addListener(loadBookmarks);
7663
chrome.bookmarks.onMoved.addListener(loadBookmarks);
77-
7864
loadBookmarks();

0 commit comments

Comments
 (0)