Skip to content

Commit 5550a00

Browse files
committed
fix: removed use of innerHTML and replaced with textContent to solve warnings. also updated maanifest.json to follow manifest v2 rules
1 parent e2d21dd commit 5550a00

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed

manifest.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"name": "KeepCode",
44
"version": "0.1.0",
55
"description": "Focus on answering problems, let KeepCode handle the rest",
6-
"permissions": ["storage", "tabs", "activeTab"],
7-
"host_permissions": ["https://leetcode.com/*"],
6+
"permissions": ["storage", "tabs", "activeTab", "https://leetcode.com/*"],
87
"background": {
98
"scripts": ["background.js"],
109
"persistent": false

options/options.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,27 @@ document.addEventListener('DOMContentLoaded', () => {
3737
const item = document.createElement('div');
3838
item.className = 'problem-item';
3939
const difficultyClass = problem.difficulty ? problem.difficulty.toLowerCase() : '';
40-
const tagsHtml = Array.isArray(problem.tags) && problem.tags.length > 0
41-
? `<span style='font-size:0.85em; color:#666; margin-left:8px;'>[${problem.tags.join(", ")}]</span>`
42-
: "<span style='font-size:0.85em; color:#bbb; margin-left:8px;'>[No tags]</span>";
43-
item.innerHTML = `
44-
<a href="${problem.url}" target="_blank">${problem.title}</a>
45-
<span class="difficulty ${difficultyClass}">${problem.difficulty}</span>
46-
${tagsHtml}
47-
`;
40+
// Use DOM methods instead of innerHTML for safety
41+
const link = document.createElement('a');
42+
link.href = problem.url;
43+
link.target = '_blank';
44+
link.textContent = problem.title;
45+
46+
const diffSpan = document.createElement('span');
47+
diffSpan.className = `difficulty ${difficultyClass}`;
48+
diffSpan.textContent = problem.difficulty;
49+
50+
const tagsSpan = document.createElement('span');
51+
tagsSpan.style.fontSize = '0.85em';
52+
tagsSpan.style.color = problem.tags && problem.tags.length > 0 ? '#666' : '#bbb';
53+
tagsSpan.style.marginLeft = '8px';
54+
tagsSpan.textContent = problem.tags && problem.tags.length > 0
55+
? `[${problem.tags.join(', ')}]`
56+
: '[No tags]';
57+
58+
item.appendChild(link);
59+
item.appendChild(diffSpan);
60+
item.appendChild(tagsSpan);
4861
problemsList.appendChild(item);
4962
});
5063
}

popup/popup.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@ document.addEventListener("DOMContentLoaded", () => {
1717
return;
1818
}
1919
const container = document.getElementById("popupContent");
20-
container.innerHTML = `
21-
<h3>Problem: ${data.title}</h3>
22-
<p>Difficulty: ${data.difficulty} </p>
23-
<p id="status"><strong>${data.status || "Unsolved"}</strong></p>
24-
`;
20+
21+
container.innerHTML = "";
22+
const titleEl = document.createElement("h3");
23+
titleEl.textContent = `Problem: ${data.title}`;
24+
const diffEl = document.createElement("p");
25+
diffEl.textContent = `Difficulty: ${data.difficulty} `;
26+
const statusEl = document.createElement("p");
27+
statusEl.id = "status";
28+
const strongEl = document.createElement("strong");
29+
strongEl.textContent = data.status || "Unsolved";
30+
statusEl.appendChild(strongEl);
31+
container.appendChild(titleEl);
32+
container.appendChild(diffEl);
33+
container.appendChild(statusEl);
2534

2635
// Listen for problem solved message
2736
browser.runtime.onMessage.addListener((msg) => {
@@ -97,15 +106,27 @@ document.addEventListener("DOMContentLoaded", () => {
97106
const item = document.createElement("div");
98107
item.className = "problem-item";
99108
const difficultyClass = problem.difficulty ? problem.difficulty.toLowerCase() : "";
100-
// Show tags if available
101-
const tagsHtml = Array.isArray(problem.tags) && problem.tags.length > 0
102-
? `<span style='font-size:0.85em; color:#666; margin-left:8px;'>[${problem.tags.join(", ")}]</span>`
103-
: "<span style='font-size:0.85em; color:#bbb; margin-left:8px;'>[No tags]</span>";
104-
item.innerHTML = `
105-
<a href="${problem.url}" target="_blank">${problem.title}</a>
106-
<span class="difficulty ${difficultyClass}">${problem.difficulty}</span>
107-
${tagsHtml}
108-
`;
109+
// Use DOM methods instead of innerHTML for safety
110+
const link = document.createElement('a');
111+
link.href = problem.url;
112+
link.target = '_blank';
113+
link.textContent = problem.title;
114+
115+
const diffSpan = document.createElement('span');
116+
diffSpan.className = `difficulty ${difficultyClass}`;
117+
diffSpan.textContent = problem.difficulty;
118+
119+
const tagsSpan = document.createElement('span');
120+
tagsSpan.style.fontSize = '0.85em';
121+
tagsSpan.style.color = problem.tags && problem.tags.length > 0 ? '#666' : '#bbb';
122+
tagsSpan.style.marginLeft = '8px';
123+
tagsSpan.textContent = problem.tags && problem.tags.length > 0
124+
? `[${problem.tags.join(', ')}]`
125+
: '[No tags]';
126+
127+
item.appendChild(link);
128+
item.appendChild(diffSpan);
129+
item.appendChild(tagsSpan);
109130
list.appendChild(item);
110131
});
111132
}

0 commit comments

Comments
 (0)